Search in sources :

Example 11 with UserDetails

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());
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 12 with UserDetails

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);
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 13 with UserDetails

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);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 14 with UserDetails

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);
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) MockUser(com.agiletec.aps.system.services.user.MockUser)

Example 15 with UserDetails

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);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Aggregations

UserDetails (com.agiletec.aps.system.services.user.UserDetails)271 Test (org.junit.Test)150 ResultActions (org.springframework.test.web.servlet.ResultActions)142 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)77 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)71 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)22 Group (com.agiletec.aps.system.services.group.Group)15 ArrayList (java.util.ArrayList)15 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)14 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)13 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)12 HttpSession (javax.servlet.http.HttpSession)12 RestListRequest (org.entando.entando.web.common.model.RestListRequest)12 HashMap (java.util.HashMap)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)9 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)9 IPage (com.agiletec.aps.system.services.page.IPage)8 JspException (javax.servlet.jsp.JspException)8 Page (com.agiletec.aps.system.services.page.Page)7