mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
apply permission from adapter
This commit is contained in:
@@ -51,9 +51,10 @@ class IdResourceManagerAdapter<MODEL_OBJECT extends ModelObject,
|
|||||||
* @param usernameToChangePassword the user name of the user we want to change password
|
* @param usernameToChangePassword the user name of the user we want to change password
|
||||||
* @return function to verify permission
|
* @return function to verify permission
|
||||||
*/
|
*/
|
||||||
public Function<User, PermissionCheck> getChangePasswordPermission(String usernameToChangePassword) {
|
public Function<MODEL_OBJECT, PermissionCheck> getChangePasswordPermission(String usernameToChangePassword) {
|
||||||
AssertUtil.assertIsNotEmpty(usernameToChangePassword);
|
AssertUtil.assertIsNotEmpty(usernameToChangePassword);
|
||||||
return user -> {
|
return model -> {
|
||||||
|
User user = (User) model;
|
||||||
if (usernameToChangePassword.equals(AuthenticationUtil.getAuthenticatedUsername())) {
|
if (usernameToChangePassword.equals(AuthenticationUtil.getAuthenticatedUsername())) {
|
||||||
return UserPermissions.changeOwnPassword();
|
return UserPermissions.changeOwnPassword();
|
||||||
}
|
}
|
||||||
@@ -61,13 +62,13 @@ class IdResourceManagerAdapter<MODEL_OBJECT extends ModelObject,
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response changePassword(String id, Function<MODEL_OBJECT, MODEL_OBJECT> applyChanges, Consumer<MODEL_OBJECT> checker, Function<MODEL_OBJECT, PermissionCheck> permissionCheck) throws NotFoundException, ConcurrentModificationException {
|
public Response changePassword(String id, Function<MODEL_OBJECT, MODEL_OBJECT> applyChanges, Consumer<MODEL_OBJECT> checker ) throws NotFoundException, ConcurrentModificationException {
|
||||||
return singleAdapter.changePassword(
|
return singleAdapter.changePassword(
|
||||||
loadBy(id),
|
loadBy(id),
|
||||||
applyChanges,
|
applyChanges,
|
||||||
idStaysTheSame(id),
|
idStaysTheSame(id),
|
||||||
checker,
|
checker,
|
||||||
permissionCheck);
|
getChangePasswordPermission(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response update(String id, Function<MODEL_OBJECT, MODEL_OBJECT> applyChanges) throws NotFoundException, ConcurrentModificationException {
|
public Response update(String id, Function<MODEL_OBJECT, MODEL_OBJECT> applyChanges) throws NotFoundException, ConcurrentModificationException {
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class MeResource {
|
|||||||
@Consumes(VndMediaType.PASSWORD_CHANGE)
|
@Consumes(VndMediaType.PASSWORD_CHANGE)
|
||||||
public Response changePassword(PasswordChangeDto passwordChangeDto) throws NotFoundException, ConcurrentModificationException {
|
public Response changePassword(PasswordChangeDto passwordChangeDto) throws NotFoundException, ConcurrentModificationException {
|
||||||
String name = (String) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
|
String name = (String) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
|
||||||
return adapter.changePassword(name, user -> user.clone().changePassword(passwordService.encryptPassword(passwordChangeDto.getNewPassword())), userManager.getChangePasswordChecker().andThen(getOldOriginalPasswordChecker(passwordChangeDto.getOldPassword())), user -> UserPermissions.changeOwnPassword());
|
return adapter.changePassword(name, user -> user.clone().changePassword(passwordService.encryptPassword(passwordChangeDto.getNewPassword())), userManager.getChangePasswordChecker().andThen(getOldOriginalPasswordChecker(passwordChangeDto.getOldPassword())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public class UserResource {
|
|||||||
})
|
})
|
||||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||||
public Response changePassword(@PathParam("id") String name, @Valid PasswordChangeDto passwordChangeDto) throws NotFoundException, ConcurrentModificationException {
|
public Response changePassword(@PathParam("id") String name, @Valid PasswordChangeDto passwordChangeDto) throws NotFoundException, ConcurrentModificationException {
|
||||||
return adapter.changePassword(name, user -> user.changePassword(passwordService.encryptPassword(passwordChangeDto.getNewPassword())), userManager.getChangePasswordChecker(), adapter.getChangePasswordPermission(name));
|
return adapter.changePassword(name, user -> user.changePassword(passwordService.encryptPassword(passwordChangeDto.getNewPassword())), userManager.getChangePasswordChecker());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user