Search in sources :

Example 61 with Group

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

the class GroupAction method delete.

public String delete() {
    try {
        String check = this.checkGroupForDelete();
        if (null != check)
            return check;
        IGroupManager groupManager = this.getGroupManager();
        Group group = groupManager.getGroup(this.getName());
        this.getGroupManager().removeGroup(group);
    } catch (Throwable t) {
        _logger.error("error in delete", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : Group(com.agiletec.aps.system.services.group.Group) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager)

Example 62 with Group

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

the class UserControllerIntegrationTest method shouldAddUserAuthorities.

@Test
public void shouldAddUserAuthorities() throws Exception {
    Group group = createGroup(1);
    Role role = createRole(1);
    try {
        this.groupManager.addGroup(group);
        this.roleManager.addRole(role);
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        String mockJson = "[{\"group\":\"group1\", \"role\":\"role1\"}]";
        ResultActions result = mockMvc.perform(put("/users/{target}/authorities", "mockuser").sessionAttr("user", user).content(mockJson).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        result.andExpect(jsonPath("$.payload[0].group", is("group1")));
    } finally {
        this.authorizationManager.deleteUserAuthorizations("mockuser");
        this.groupManager.removeGroup(group);
        this.roleManager.removeRole(role);
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 63 with Group

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

the class UserControllerIntegrationTest method createGroup.

private Group createGroup(int i) {
    Group group = new Group();
    group.setDescription("descr" + i);
    group.setName("group" + i);
    return group;
}
Also used : Group(com.agiletec.aps.system.services.group.Group)

Example 64 with Group

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

the class ContentPreviewDispenser method getBaseRenderizationInfo.

@Override
public ContentRenderizationInfo getBaseRenderizationInfo(PublicContentAuthorizationInfo authInfo, String contentId, long modelId, String langCode, UserDetails currentUser, RequestContext reqCtx) {
    ContentRenderizationInfo renderInfo = null;
    try {
        List<Group> userGroups = (null != currentUser) ? this.getAuthorizationManager().getUserGroups(currentUser) : new ArrayList<Group>();
        if (authInfo.isUserAllowed(userGroups)) {
            Content contentOnSession = this.extractContentOnSession(reqCtx);
            String renderedContent = this.buildRenderedContent(contentOnSession, modelId, langCode, reqCtx);
            if (null != renderedContent && renderedContent.trim().length() > 0) {
                List<AttributeRole> roles = this.getContentManager().getAttributeRoles();
                renderInfo = new ContentRenderizationInfo(contentOnSession, renderedContent, modelId, langCode, roles);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error while rendering content {}", contentId, t);
        return null;
    }
    return renderInfo;
}
Also used : ContentRenderizationInfo(com.agiletec.plugins.jacms.aps.system.services.dispenser.ContentRenderizationInfo) Group(com.agiletec.aps.system.services.group.Group) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeRole(com.agiletec.aps.system.common.entity.model.attribute.AttributeRole)

Example 65 with Group

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

the class PublicContentAuthorizationInfo method isUserAllowed.

/**
 * Verifica i permessi dell'utente in accesso al contenuto.
 * Restituisce true se l'utente specificato è abilitato
 * ad accedere al contenuto, false in caso contrario.
 * @param userGroups I gruppi dell'utente di cui verificarne l'abilitazione.
 * @return true se l'utente specificato è abilitato ad accedere
 * al contenuto, false in caso contrario.
 */
public boolean isUserAllowed(List<Group> userGroups) {
    if (null == userGroups) {
        userGroups = new ArrayList<Group>();
    }
    Set<String> codes = new HashSet<String>();
    for (int i = 0; i < userGroups.size(); i++) {
        Group group = userGroups.get(i);
        codes.add(group.getAuthority());
    }
    return this.isUserAllowed(codes);
}
Also used : Group(com.agiletec.aps.system.services.group.Group) HashSet(java.util.HashSet)

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