Adapt ChangePasswordNotAllowedException and mapper

This commit is contained in:
René Pfeuffer
2018-10-29 09:26:23 +01:00
parent 007baecc86
commit 4425243f03
3 changed files with 20 additions and 12 deletions

View File

@@ -1,17 +1,17 @@
package sonia.scm.api.v2.resources;
import sonia.scm.api.rest.ContextualExceptionMapper;
import sonia.scm.user.ChangePasswordNotAllowedException;
import sonia.scm.user.InvalidPasswordException;
import javax.inject.Inject;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@Provider
public class ChangePasswordNotAllowedExceptionMapper implements ExceptionMapper<ChangePasswordNotAllowedException> {
@Override
public Response toResponse(ChangePasswordNotAllowedException exception) {
return Response.status(Response.Status.BAD_REQUEST)
.entity(exception.getMessage())
.build();
public class ChangePasswordNotAllowedExceptionMapper extends ContextualExceptionMapper<ChangePasswordNotAllowedException> {
@Inject
public ChangePasswordNotAllowedExceptionMapper(ExceptionWithContextToErrorDtoMapper mapper) {
super(ChangePasswordNotAllowedException.class, Response.Status.BAD_REQUEST, mapper);
}
}

View File

@@ -422,7 +422,7 @@ public class DefaultUserManager extends AbstractUserManager
throw new NotFoundException(User.class, userId);
}
if (!isTypeDefault(user)) {
throw new ChangePasswordNotAllowedException(user.getType());
throw new ChangePasswordNotAllowedException(ContextEntry.ContextBuilder.entity("passwordChange", "-").in(User.class, user.getName()));
}
user.setPassword(newPassword);
this.modify(user);