Search in sources :

Example 31 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class ApsAdminBaseTestCase method getUser.

/**
 * Return a user (with his autority) by username.
 *
 * @param username The username
 * @param password The password
 * @return The required user.
 * @throws Exception In case of error.
 */
protected UserDetails getUser(String username, String password) throws Exception {
    IAuthenticationProviderManager provider = (IAuthenticationProviderManager) this.getService(SystemConstants.AUTHENTICATION_PROVIDER_MANAGER);
    IUserManager userManager = (IUserManager) this.getService(SystemConstants.USER_MANAGER);
    UserDetails user = null;
    if (username.equals(SystemConstants.GUEST_USER_NAME)) {
        user = userManager.getGuestUser();
    } else {
        user = provider.getUser(username, password);
    }
    return user;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IUserManager(com.agiletec.aps.system.services.user.IUserManager) IAuthenticationProviderManager(com.agiletec.aps.system.services.user.IAuthenticationProviderManager)

Example 32 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class TestShortcutConfigAction method testJoinMyShortcut_2.

public void testJoinMyShortcut_2() throws Throwable {
    UserDetails user = this.getUser("admin");
    try {
        String result = this.executeJoinMyShortcut("core.tools.setting", 9, "admin", ApsAdminSystemConstants.ADD);
        assertEquals(Action.SUCCESS, result);
        String[] newConfig = this._shortcutManager.getUserConfig(user);
        for (int i = 0; i < newConfig.length; i++) {
            if (i == 9) {
                assertEquals("core.tools.setting", newConfig[i]);
            } else {
                assertEquals(ADMIN_CONFIG[i], newConfig[i]);
            }
        }
    } catch (Exception e) {
        throw e;
    } finally {
        this._shortcutManager.saveUserConfig(user, ADMIN_CONFIG);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 33 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class TestShortcutConfigAction method testSwapMyShortcut.

public void testSwapMyShortcut() throws Throwable {
    UserDetails user = this.getUser("admin");
    try {
        String[] oldConfig = this._shortcutManager.getUserConfig(user);
        String result = this.executeSwapMyShortcut(2, 9, "admin", ApsAdminSystemConstants.EDIT);
        assertEquals(Action.SUCCESS, result);
        String[] newConfig = this._shortcutManager.getUserConfig(user);
        assertEquals(newConfig[9], oldConfig[2]);
        assertEquals(newConfig[2], oldConfig[9]);
        result = this.executeSwapMyShortcut(8, 9, "admin", ApsAdminSystemConstants.EDIT);
        assertEquals(Action.SUCCESS, result);
        String[] newConfig2 = this._shortcutManager.getUserConfig(user);
        assertEquals(newConfig2[9], newConfig[8]);
        assertEquals(newConfig2[8], newConfig[9]);
    } catch (Exception e) {
        throw e;
    } finally {
        this._shortcutManager.saveUserConfig(user, ADMIN_CONFIG);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 34 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class TestShortcutConfigAction method testRemoveMyShortcut.

public void testRemoveMyShortcut() throws Throwable {
    UserDetails user = this.getUser("admin");
    try {
        String result = this.executeEmptyPosition(3, "admin");
        assertEquals(Action.SUCCESS, result);
        String[] newConfig = this._shortcutManager.getUserConfig(user);
        for (int i = 0; i < newConfig.length; i++) {
            if (i == 3) {
                assertNull(newConfig[i]);
            } else {
                assertEquals(ADMIN_CONFIG[i], newConfig[i]);
            }
        }
    } catch (Exception e) {
        throw e;
    } finally {
        this._shortcutManager.saveUserConfig(user, ADMIN_CONFIG);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 35 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class BaseContentDispenser method getRenderizationInfo.

protected ContentRenderizationInfo getRenderizationInfo(PublicContentAuthorizationInfo authInfo, String contentId, long modelId, String langCode, RequestContext reqCtx, boolean cacheable) {
    ContentRenderizationInfo renderInfo = null;
    try {
        UserDetails currentUser = (null != reqCtx) ? (UserDetails) reqCtx.getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER) : null;
        List<Group> userGroups = (null != currentUser) ? this.getAuthorizationManager().getUserGroups(currentUser) : new ArrayList<Group>();
        if (authInfo.isUserAllowed(userGroups)) {
            renderInfo = this.getBaseRenderizationInfo(authInfo, contentId, modelId, langCode, currentUser, reqCtx, cacheable);
            if (null == renderInfo) {
                return null;
            }
        } else {
            String renderedContent = "Current user '" + currentUser.getUsername() + "' can't view this content";
            Content contentToRender = this.getContentManager().loadContent(contentId, true, cacheable);
            renderInfo = new ContentRenderizationInfo(contentToRender, renderedContent, modelId, langCode, null);
            renderInfo.setRenderedContent(renderedContent);
            return renderInfo;
        }
    } catch (Throwable t) {
        _logger.error("Error while rendering content {}", contentId, t);
        return null;
    }
    return renderInfo;
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

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