mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
Adapt InvalidPasswordException and mapper
This commit is contained in:
@@ -1,8 +1,18 @@
|
|||||||
package sonia.scm.user;
|
package sonia.scm.user;
|
||||||
|
|
||||||
public class InvalidPasswordException extends RuntimeException {
|
import sonia.scm.ContextEntry;
|
||||||
|
import sonia.scm.ExceptionWithContext;
|
||||||
|
|
||||||
public InvalidPasswordException() {
|
public class InvalidPasswordException extends ExceptionWithContext {
|
||||||
super("The given Password does not match with the stored one.");
|
|
||||||
|
private static final String CODE = "8YR7aawFW1";
|
||||||
|
|
||||||
|
public InvalidPasswordException(ContextEntry.ContextBuilder passwordChange) {
|
||||||
|
super(passwordChange.build(), "The given old password does not match with the stored one.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCode() {
|
||||||
|
return CODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package sonia.scm.api.v2.resources;
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
|
import sonia.scm.api.rest.ContextualExceptionMapper;
|
||||||
import sonia.scm.user.InvalidPasswordException;
|
import sonia.scm.user.InvalidPasswordException;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.ext.ExceptionMapper;
|
|
||||||
import javax.ws.rs.ext.Provider;
|
import javax.ws.rs.ext.Provider;
|
||||||
|
|
||||||
@Provider
|
@Provider
|
||||||
public class InvalidPasswordExceptionMapper implements ExceptionMapper<InvalidPasswordException> {
|
public class InvalidPasswordExceptionMapper extends ContextualExceptionMapper<InvalidPasswordException> {
|
||||||
@Override
|
|
||||||
public Response toResponse(InvalidPasswordException exception) {
|
@Inject
|
||||||
return Response.status(Response.Status.BAD_REQUEST)
|
public InvalidPasswordExceptionMapper(ExceptionWithContextToErrorDtoMapper mapper) {
|
||||||
.entity(exception.getMessage())
|
super(InvalidPasswordException.class, Response.Status.BAD_REQUEST, mapper);
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import com.google.inject.Singleton;
|
|||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import sonia.scm.ContextEntry;
|
||||||
import sonia.scm.EagerSingleton;
|
import sonia.scm.EagerSingleton;
|
||||||
import sonia.scm.HandlerEventType;
|
import sonia.scm.HandlerEventType;
|
||||||
import sonia.scm.ManagerDaoAdapter;
|
import sonia.scm.ManagerDaoAdapter;
|
||||||
@@ -402,7 +403,7 @@ public class DefaultUserManager extends AbstractUserManager
|
|||||||
User user = get((String) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal());
|
User user = get((String) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal());
|
||||||
|
|
||||||
if (!user.getPassword().equals(oldPassword)) {
|
if (!user.getPassword().equals(oldPassword)) {
|
||||||
throw new InvalidPasswordException();
|
throw new InvalidPasswordException(ContextEntry.ContextBuilder.entity("passwordChange", "-").in(User.class, user.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
user.setPassword(newPassword);
|
user.setPassword(newPassword);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class DispatcherMock {
|
|||||||
dispatcher.getProviderFactory().registerProvider(AuthorizationExceptionMapper.class);
|
dispatcher.getProviderFactory().registerProvider(AuthorizationExceptionMapper.class);
|
||||||
dispatcher.getProviderFactory().registerProvider(InternalRepositoryExceptionMapper.class);
|
dispatcher.getProviderFactory().registerProvider(InternalRepositoryExceptionMapper.class);
|
||||||
dispatcher.getProviderFactory().registerProvider(ChangePasswordNotAllowedExceptionMapper.class);
|
dispatcher.getProviderFactory().registerProvider(ChangePasswordNotAllowedExceptionMapper.class);
|
||||||
dispatcher.getProviderFactory().registerProvider(InvalidPasswordExceptionMapper.class);
|
dispatcher.getProviderFactory().register(new InvalidPasswordExceptionMapper(mapper));
|
||||||
dispatcher.getProviderFactory().registerProvider(IllegalArgumentExceptionMapper.class);
|
dispatcher.getProviderFactory().registerProvider(IllegalArgumentExceptionMapper.class);
|
||||||
return dispatcher;
|
return dispatcher;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user