Search in sources :

Example 36 with Group

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

the class GroupControllerIntegrationTest method testGetGroupsPagination.

@Test
public void testGetGroupsPagination() throws Exception {
    List<Group> testGroups = new ArrayList<>();
    try {
        for (int i = 0; i < 25; i++) {
            String x = ("tmp_" + i);
            Group group = new Group();
            group.setDescription(x);
            group.setName(x);
            testGroups.add(group);
            this.groupManager.addGroup(group);
        }
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        ResultActions result = mockMvc.perform(get("/groups").param("pageSize", "5").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
        result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
        result.andExpect(jsonPath("$.metaData.page", is(1)));
        result.andExpect(jsonPath("$.metaData.lastPage", is(7)));
        result.andExpect(jsonPath("$.payload[0].code", is("administrators")));
        // -------------
        result = mockMvc.perform(get("/groups").param("pageSize", "5").param("page", "1").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
        result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
        result.andExpect(jsonPath("$.metaData.page", is(1)));
        result.andExpect(jsonPath("$.metaData.lastPage", is(7)));
        result.andExpect(jsonPath("$.payload[0].code", is("administrators")));
        // -------------
        result = mockMvc.perform(get("/groups").param("pageSize", "5").param("page", "7").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
        result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
        result.andExpect(jsonPath("$.metaData.page", is(7)));
        result.andExpect(jsonPath("$.metaData.lastPage", is(7)));
        result.andExpect(jsonPath("$.payload[0].code", is("tmp_9")));
        // -------------
        result = mockMvc.perform(get("/groups").param("pageSize", "0").param("page", "7").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isNotFound());
        // -------------
        result = mockMvc.perform(get("/groups").param("pageSize", "7").param("page", "0").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isBadRequest());
        // -------------
        result = mockMvc.perform(get("/groups").param("pageSize", "1").param("page", "7").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(jsonPath("$.metaData.pageSize", is(1)));
        result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
        result.andExpect(jsonPath("$.metaData.page", is(7)));
        result.andExpect(jsonPath("$.metaData.lastPage", is(31)));
        result.andExpect(jsonPath("$.payload[0].code", is("tmp_0")));
    } finally {
        for (Group group : testGroups) {
            this.groupManager.removeGroup(group);
        }
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ArrayList(java.util.ArrayList) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 37 with Group

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

the class UserControllerUnitTest method mockedGroup.

private Group mockedGroup() {
    Group group = new Group();
    group.setDescription("descr1");
    group.setName("group1");
    return group;
}
Also used : Group(com.agiletec.aps.system.services.group.Group)

Example 38 with Group

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

the class OAuth2TestUtils method addAuthorization.

public static void addAuthorization(User user, String groupName, String roleName, String[] permissions) {
    Group group = null;
    if (StringUtils.isNotBlank(groupName)) {
        group = new Group();
        group.setName(groupName);
        group.setDescription(groupName + " descr");
    }
    Role role = null;
    if (StringUtils.isNotBlank(roleName)) {
        role = new Role();
        role.setName(roleName);
        role.setDescription(roleName + " descr");
        if (null != permissions) {
            for (String permissionName : permissions) {
                role.addPermission(permissionName);
            }
        }
    }
    Authorization auth = new Authorization(group, role);
    user.addAuthorization(auth);
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Authorization(com.agiletec.aps.system.services.authorization.Authorization) Group(com.agiletec.aps.system.services.group.Group)

Example 39 with Group

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

the class TestAuthorityManager method testSetRemoveUserAuthorizations_2.

public void testSetRemoveUserAuthorizations_2() throws Throwable {
    String username = "pageManagerCustomers";
    String notExistentGroupName = "testgroupname";
    String existentGroupName = "management";
    String roleName = "pageManager";
    Role roleForTest = this.getRole(roleName);
    assertNotNull(roleForTest);
    // existent group
    Group existentGroup = this.getGroup(existentGroupName);
    assertNotNull(existentGroup);
    // nonexistent group
    Group nonExistentGroup = this.createGroupForTest(notExistentGroupName);
    List<String> usersByGroup = this._authorizationManager.getUsersByAuthority(existentGroup, false);
    assertNotNull(usersByGroup);
    assertEquals(0, usersByGroup.size());
    usersByGroup = this._authorizationManager.getUsersByGroup(nonExistentGroup, false);
    assertNull(usersByGroup);
    try {
        Authorization auth1 = new Authorization(existentGroup, roleForTest);
        Authorization auth2 = new Authorization(nonExistentGroup, roleForTest);
        List<Authorization> authorizations = new ArrayList<Authorization>();
        authorizations.add(auth1);
        authorizations.add(auth2);
        this._authorizationManager.addUserAuthorizations(username, authorizations);
        usersByGroup = this._authorizationManager.getUsersByAuthority(existentGroup, false);
        assertNotNull(usersByGroup);
        assertEquals(1, usersByGroup.size());
        usersByGroup = this._authorizationManager.getUsersByGroup(nonExistentGroup, false);
        assertNull(usersByGroup);
    } catch (Throwable t) {
        this._authorizationManager.deleteUserAuthorization(username, notExistentGroupName, roleName);
        throw t;
    } finally {
        this._authorizationManager.deleteUserAuthorization(username, existentGroupName, roleName);
        usersByGroup = this._authorizationManager.getUsersByAuthority(existentGroup, false);
        assertNotNull(usersByGroup);
        assertEquals(0, usersByGroup.size());
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Group(com.agiletec.aps.system.services.group.Group) ArrayList(java.util.ArrayList)

Example 40 with Group

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

the class TestAuthorityManager method testGetUsersByAuthority_1.

public void testGetUsersByAuthority_1() throws Throwable {
    Role role = this.getRole("pageManager");
    List<String> usersByRole = this._authorizationManager.getUsersByAuthority(role, false);
    assertNotNull(usersByRole);
    assertTrue(usersByRole.size() >= 2);
    usersByRole = this._authorizationManager.getUsersByRole(role, false);
    assertNotNull(usersByRole);
    assertTrue(usersByRole.size() >= 2);
    List<String> usersByInvalidGroup = this._authorizationManager.getUsersByGroup(role, false);
    assertNull(usersByInvalidGroup);
    Group group = this.getGroup("coach");
    List<String> usersByGroup = this._authorizationManager.getUsersByAuthority(group, false);
    assertNotNull(usersByGroup);
    assertTrue(usersByGroup.size() >= 3);
    List<String> usersByNullGroup = this._authorizationManager.getUsersByAuthority(null, false);
    assertNull(usersByNullGroup);
    Group noExistingGroup = new Group();
    noExistingGroup.setName("test");
    noExistingGroup.setDescription("test");
    List<String> usersByInvaliGroup = this._authorizationManager.getUsersByGroup(noExistingGroup, false);
    assertNull(usersByInvaliGroup);
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Group(com.agiletec.aps.system.services.group.Group)

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