use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class TestAuthorizationManager method testGroupsByPermission_1.
public void testGroupsByPermission_1() throws Throwable {
String username = "pageManagerCoach";
UserDetails user = this._authenticationProvider.getUser(username);
List<Group> autorities = this._authorizationManager.getGroupsByPermission(user, Permission.MANAGE_PAGES);
assertNotNull(autorities);
assertEquals(2, autorities.size());
autorities = this._authorizationManager.getGroupsByPermission(user, Permission.SUPERUSER);
assertNotNull(autorities);
assertTrue(autorities.isEmpty());
autorities = this._authorizationManager.getGroupsByPermission(user, "wrong_permission");
assertNotNull(autorities);
assertTrue(autorities.isEmpty());
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class TestAuthorizationManager method testAuthoritiesByRole_1.
public void testAuthoritiesByRole_1() throws Throwable {
String username = "pageManagerCoach";
UserDetails user = this._authenticationProvider.getUser(username);
List<IApsAuthority> autorities = this._authorizationManager.getAuthoritiesByRole(user, "pageManager");
assertNotNull(autorities);
assertEquals(2, autorities.size());
autorities = this._authorizationManager.getAuthoritiesByRole(user, "wrong_role");
assertNull(autorities);
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class TestAuthorizationManager method testUpdateAuthorization_1.
public void testUpdateAuthorization_1() throws Throwable {
String username = "UserForTest";
String password = "PasswordForTest";
String wrongGroupName = "wrong_group_name";
assertNull(this._groupManager.getGroup(wrongGroupName));
String wrongRoleName = "wrong_role_name";
assertNull(this._roleManager.getRole(wrongRoleName));
this.addUserForTest(username, password);
UserDetails extractedUser = null;
try {
extractedUser = this._authenticationProvider.getUser(username, password);
List<Authorization> authorizations = this._authorizationManager.getUserAuthorizations(username);
assertEquals(1, authorizations.size());
this._authorizationManager.addUserAuthorization(username, Group.FREE_GROUP_NAME, "admin");
authorizations = this._authorizationManager.getUserAuthorizations(username);
assertEquals(2, authorizations.size());
// invalid authorization
this._authorizationManager.addUserAuthorization(username, Group.FREE_GROUP_NAME, wrongRoleName);
authorizations = this._authorizationManager.getUserAuthorizations(username);
assertEquals(2, authorizations.size());
// invalid authorization
this._authorizationManager.addUserAuthorization(username, wrongGroupName, null);
authorizations = this._authorizationManager.getUserAuthorizations(username);
assertEquals(2, authorizations.size());
this._authorizationManager.addUserAuthorization(username, null, "admin");
authorizations = this._authorizationManager.getUserAuthorizations(username);
assertEquals(3, authorizations.size());
this._authorizationManager.addUserAuthorization(username, "coach", null);
authorizations = this._authorizationManager.getUserAuthorizations(username);
assertEquals(4, authorizations.size());
// existing authorization
this._authorizationManager.addUserAuthorization(username, "coach", null);
authorizations = this._authorizationManager.getUserAuthorizations(username);
assertEquals(4, authorizations.size());
} catch (Throwable t) {
throw t;
} finally {
if (null != extractedUser) {
this._userManager.removeUser(extractedUser);
}
extractedUser = this._userManager.getUser(username);
assertNull(extractedUser);
}
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class TestAuthorizationManager method addUserForTest.
private void addUserForTest(String username, String password) throws Throwable {
MockUser user = new MockUser();
user.setUsername(username);
user.setPassword(password);
user.setDisabled(false);
Authorization auth = new Authorization(this._groupManager.getGroup(Group.FREE_GROUP_NAME), this._roleManager.getRole("editor"));
user.addAuthorization(auth);
this._userManager.removeUser(user);
UserDetails extractedUser = this._userManager.getUser(username);
assertNull(extractedUser);
this._userManager.addUser(user);
this._authorizationManager.addUserAuthorization(username, auth);
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class UserService method updateUser.
@Override
public UserDto updateUser(UserRequest userRequest) {
try {
UserDetails user = this.loadUser(userRequest.getUsername());
UserDetails newUser = this.updateUser(user, userRequest);
this.getUserManager().updateUser(newUser);
return dtoBuilder.convert(newUser);
} catch (ApsSystemException e) {
logger.error("Error in updating user {}", userRequest.getUsername(), e);
throw new RestServerError("Error in updating user", e);
}
}
Aggregations