Search in sources :

Example 21 with UserDetails

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

the class TestContentAuthorization method testCheckCustomerUser.

public void testCheckCustomerUser() throws Throwable {
    UserDetails extractedUser = this.getUser("pageManagerCustomers");
    assertNotNull(extractedUser);
    assertEquals("pageManagerCustomers", extractedUser.getUsername());
    assertEquals(1, extractedUser.getAuthorizations().size());
    IContentManager contentManager = (IContentManager) this.getService(JacmsSystemConstants.CONTENT_MANAGER);
    Content content = contentManager.loadContent("ART111", true);
    boolean checkContent = this._authorizationManager.isAuth(extractedUser, content);
    assertTrue(checkContent);
    content = contentManager.loadContent("EVN25", true);
    checkContent = this._authorizationManager.isAuth(extractedUser, content);
    assertTrue(checkContent);
    content = contentManager.loadContent("EVN41", true);
    checkContent = this._authorizationManager.isAuth(extractedUser, content);
    assertFalse(checkContent);
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IContentManager(com.agiletec.plugins.jacms.aps.system.services.content.IContentManager) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

Example 22 with UserDetails

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

the class TestContentAuthorization method testCheckNewUser.

/*
     * This test is fully inherited from the original TestAuthorizationManager in jAPS2 (2.0.6)
     */
public void testCheckNewUser() throws Throwable {
    String username = "UserForTest";
    String password = "PasswordForTest";
    this.addUserForTest(username, password);
    UserDetails extractedUser = null;
    try {
        extractedUser = this.getUser(username, password);
        assertEquals(username, extractedUser.getUsername());
        assertNotNull(extractedUser);
        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);
        assertTrue(checkGroup);
        boolean checkPermission = this._authorizationManager.isAuthOnPermission(extractedUser, Permission.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, "editContents");
        assertTrue(checkPermission);
        IContentManager contentManager = (IContentManager) this.getService(JacmsSystemConstants.CONTENT_MANAGER);
        Content content = contentManager.loadContent("ART111", true);
        boolean checkContent = this._authorizationManager.isAuth(extractedUser, content);
        assertFalse(checkContent);
        content = contentManager.loadContent("EVN25", true);
        checkContent = this._authorizationManager.isAuth(extractedUser, content);
        assertTrue(checkContent);
        content = contentManager.loadContent("EVN41", true);
        checkContent = this._authorizationManager.isAuth(extractedUser, content);
        assertFalse(checkContent);
    } catch (Throwable t) {
        throw t;
    } finally {
        if (null != extractedUser) {
            this._userManager.removeUser(extractedUser);
        }
        extractedUser = this._userManager.getUser(username);
        assertNull(extractedUser);
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) IContentManager(com.agiletec.plugins.jacms.aps.system.services.content.IContentManager) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

Example 23 with UserDetails

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

the class TestContentAuthorization method testCheckAdminUser.

public void testCheckAdminUser() throws Throwable {
    UserDetails adminUser = this.getUser("admin");
    assertNotNull(adminUser);
    assertEquals("admin", adminUser.getUsername());
    assertEquals(1, adminUser.getAuthorizations().size());
    IContentManager contentManager = (IContentManager) this.getService(JacmsSystemConstants.CONTENT_MANAGER);
    Content content = contentManager.loadContent("ART111", true);
    boolean check = this._authorizationManager.isAuth(adminUser, content);
    assertTrue(check);
    content = contentManager.loadContent("EVN25", true);
    check = this._authorizationManager.isAuth(adminUser, content);
    assertTrue(check);
    content = contentManager.loadContent("EVN41", true);
    check = this._authorizationManager.isAuth(adminUser, content);
    assertTrue(check);
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IContentManager(com.agiletec.plugins.jacms.aps.system.services.content.IContentManager) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

Example 24 with UserDetails

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

the class SelfRestCaller method extractParameters.

protected Properties extractParameters(SelfRestCallPostProcess selfRestCall) throws ApsSystemException {
    Properties properties = new Properties();
    try {
        ILangManager langManager = this.getLangManager();
        String langCode = selfRestCall.getLangCode();
        if (null == langCode || null == langManager.getLang(langCode)) {
            langCode = langManager.getDefaultLang().getCode();
        }
        if (null != selfRestCall.getQueryParameters()) {
            properties.putAll(selfRestCall.getQueryParameters());
        }
        properties.put(SystemConstants.API_LANG_CODE_PARAMETER, langCode);
        UserDetails user = this.getAuthenticationProvider().getUser(SystemConstants.ADMIN_USER_NAME);
        if (null != user) {
            properties.put(SystemConstants.API_USER_PARAMETER, user);
        } else {
            _logger.error("Admin user missing");
        }
    } catch (Throwable t) {
        _logger.error("Error extracting parameters", t);
        // ApsSystemUtils.logThrowable(t, this, "extractParameters", "Error extracting parameters");
        throw new ApsSystemException("Error extracting parameters", t);
    }
    return properties;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Properties(java.util.Properties)

Example 25 with UserDetails

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

the class ActivityStreamLastUpdateTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
    try {
        IActionLogManager loggerManager = (IActionLogManager) ApsWebApplicationUtils.getBean(SystemConstants.ACTION_LOGGER_MANAGER, this.pageContext);
        UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        Date lastUpdate = loggerManager.lastUpdateDate(currentUser);
        if (null != this.getVar()) {
            ValueStack stack = this.getStack();
            stack.getContext().put(this.getVar(), lastUpdate);
            stack.setValue("#attr['" + this.getVar() + "']", lastUpdate, false);
        }
    } catch (Throwable t) {
        _logger.error("Error on doStartTag", t);
        throw new JspException("Error on doStartTag", t);
    }
    return super.doEndTag();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ValueStack(com.opensymphony.xwork2.util.ValueStack) IActionLogManager(org.entando.entando.aps.system.services.actionlog.IActionLogManager) Date(java.util.Date)

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