Search in sources :

Example 41 with Group

use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.

the class TestAuthorityManager method createGroupForTest.

private Group createGroupForTest(String code) {
    Group groupForTest = new Group();
    groupForTest.setName(code);
    groupForTest.setDescription("Description");
    return groupForTest;
}
Also used : Group(com.agiletec.aps.system.services.group.Group)

Example 42 with Group

use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.

the class TestAuthorityManager method testSetRemoveUserAuthorization_2.

public void testSetRemoveUserAuthorization_2() throws Throwable {
    String username = "pageManagerCustomers";
    String groupName = "testgroupname";
    String roleName = "pageManager";
    Group invalidGroupForTest = this.createGroupForTest(groupName);
    try {
        this._authorizationManager.addUserAuthorization(username, groupName, roleName);
        List<String> usersByGroup = this._authorizationManager.getUsersByGroup(invalidGroupForTest, false);
        assertNull(usersByGroup);
    } catch (Throwable t) {
        this._authorizationManager.deleteUserAuthorization(username, groupName, roleName);
        throw t;
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group)

Example 43 with Group

use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.

the class TestAuthorityManager method testGetUsersByAuthority_2.

public void testGetUsersByAuthority_2() throws Throwable {
    // name equal to an existing role
    Group groupForTest = this.createGroupForTest("pageManager");
    try {
        ((IGroupManager) this._groupManager).addGroup(groupForTest);
        Group group = this.getGroup(groupForTest.getName());
        assertNotNull(group);
        List<String> usersByGroup = this._authorizationManager.getUsersByAuthority(group, false);
        assertNotNull(usersByGroup);
        assertTrue(usersByGroup.isEmpty());
        usersByGroup = this._authorizationManager.getUsersByGroup(group, false);
        assertNotNull(usersByGroup);
        assertTrue(usersByGroup.isEmpty());
        List<String> usersByRole = this._authorizationManager.getUsersByRole(group, false);
        assertNull(usersByRole);
    } catch (Throwable t) {
        throw t;
    } finally {
        ((IGroupManager) this._groupManager).removeGroup(groupForTest);
        Group group = this.getGroup(groupForTest.getName());
        assertNull(group);
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager)

Example 44 with Group

use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.

the class TestAuthorityManager method testSetRemoveUserAuthorization_1.

public void testSetRemoveUserAuthorization_1() throws Throwable {
    String username = "pageManagerCustomers";
    String groupName = "coach";
    String roleName = "pageManager";
    Group groupForTest = this.getGroup(groupName);
    assertNotNull(groupForTest);
    List<String> usersByGroup = this._authorizationManager.getUsersByAuthority(groupForTest, false);
    assertNotNull(usersByGroup);
    int initSize = usersByGroup.size();
    assertTrue(initSize >= 3);
    try {
        this._authorizationManager.addUserAuthorization(username, groupName, roleName);
        usersByGroup = this._authorizationManager.getUsersByAuthority(groupForTest, false);
        assertNotNull(usersByGroup);
        assertEquals(initSize + 1, usersByGroup.size());
    } catch (Throwable t) {
        throw t;
    } finally {
        this._authorizationManager.deleteUserAuthorization(username, groupName, roleName);
        usersByGroup = this._authorizationManager.getUsersByAuthority(groupForTest, false);
        assertNotNull(usersByGroup);
        assertEquals(initSize, usersByGroup.size());
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group)

Example 45 with Group

use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.

the class TestAuthorizationManager method testCheckCustomerUser.

public void testCheckCustomerUser() throws Throwable {
    UserDetails extractedUser = this._authenticationProvider.getUser("pageManagerCustomers", "pageManagerCustomers");
    assertNotNull(extractedUser);
    assertEquals("pageManagerCustomers", extractedUser.getUsername());
    assertEquals(1, extractedUser.getAuthorizations().size());
    Group group = this._groupManager.getGroup("coach");
    boolean checkGroup = this._authorizationManager.isAuth(extractedUser, group);
    assertFalse(checkGroup);
    group = this._groupManager.getGroup(Group.FREE_GROUP_NAME);
    checkGroup = this._authorizationManager.isAuth(extractedUser, group);
    assertFalse(checkGroup);
    group = this._groupManager.getGroup("customers");
    checkGroup = this._authorizationManager.isAuth(extractedUser, group);
    assertTrue(checkGroup);
    boolean checkPermission = this._authorizationManager.isAuthOnPermission(extractedUser, Permission.CONTENT_SUPERVISOR);
    assertFalse(checkPermission);
    checkPermission = this._authorizationManager.isAuthOnPermission(extractedUser, Permission.SUPERUSER);
    assertFalse(checkPermission);
    checkPermission = this._authorizationManager.isAuthOnPermission(extractedUser, Permission.BACKOFFICE);
    assertTrue(checkPermission);
    checkPermission = this._authorizationManager.isAuthOnPermission(extractedUser, Permission.CONTENT_EDITOR);
    assertFalse(checkPermission);
    checkPermission = this._authorizationManager.isAuthOnPermission(extractedUser, Permission.MANAGE_PAGES);
    assertTrue(checkPermission);
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Aggregations

Group (com.agiletec.aps.system.services.group.Group)68 UserDetails (com.agiletec.aps.system.services.user.UserDetails)15 Role (com.agiletec.aps.system.services.role.Role)13 ArrayList (java.util.ArrayList)13 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 BeanComparator (org.apache.commons.beanutils.BeanComparator)5 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)4 HashSet (java.util.HashSet)4 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)4 RestServerError (org.entando.entando.aps.system.exception.RestServerError)4 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)3 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)3 AttributeRole (com.agiletec.aps.system.common.entity.model.attribute.AttributeRole)2 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)2 Authorization (com.agiletec.aps.system.services.authorization.Authorization)2 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)2 ExtendedResourceAction (com.agiletec.plugins.jacms.apsadmin.content.attribute.action.resource.ExtendedResourceAction)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2