Search in sources :

Example 6 with UserDetails

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

the class SearcherTagHelper method executeSearch.

/**
 * Carica una lista di identificativi di contenuto in base ad una ricerca
 * effettuata in funzione ad una parila chiave specificata.
 * @param word La parola con cui effettuare la ricerca.
 * @param reqCtx Il contesto della richiesta.
 * @return La lista di identificativi di contenuto.
 * @throws ApsSystemException
 */
public List<String> executeSearch(String word, RequestContext reqCtx) throws ApsSystemException {
    List<String> result = new ArrayList<String>();
    if (null != word && word.trim().length() > 0) {
        UserDetails currentUser = (UserDetails) reqCtx.getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        ICmsSearchEngineManager searchEngine = (ICmsSearchEngineManager) ApsWebApplicationUtils.getBean(JacmsSystemConstants.SEARCH_ENGINE_MANAGER, reqCtx.getRequest());
        IAuthorizationManager authManager = (IAuthorizationManager) ApsWebApplicationUtils.getBean(SystemConstants.AUTHORIZATION_SERVICE, reqCtx.getRequest());
        List<Group> groups = authManager.getUserGroups(currentUser);
        Set<String> userGroups = new HashSet<String>();
        Iterator<Group> iter = groups.iterator();
        while (iter.hasNext()) {
            Group group = iter.next();
            userGroups.add(group.getName());
        }
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        result = searchEngine.searchEntityId(currentLang.getCode(), word, userGroups);
    }
    return result;
}
Also used : ICmsSearchEngineManager(com.agiletec.plugins.jacms.aps.system.services.searchengine.ICmsSearchEngineManager) IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) HashSet(java.util.HashSet)

Example 7 with UserDetails

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

the class TokenEndpointServlet method validateClientWithAuthorizationCode.

private OAuthResponse validateClientWithAuthorizationCode(HttpServletRequest request) throws Throwable {
    try {
        final OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request);
        IOAuthConsumerManager consumerManager = (IOAuthConsumerManager) ApsWebApplicationUtils.getBean(SystemConstants.OAUTH_CONSUMER_MANAGER, request);
        IApiOAuthorizationCodeManager codeManager = (IApiOAuthorizationCodeManager) ApsWebApplicationUtils.getBean(SystemConstants.OAUTH2_AUTHORIZATION_CODE_MANAGER, request);
        if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.AUTHORIZATION_CODE.toString()) || oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.REFRESH_TOKEN.toString())) {
            final String clientId = oauthRequest.getClientId();
            final String oauthType = GrantType.AUTHORIZATION_CODE.toString();
            final String authCode = oauthRequest.getParam(OAuth.OAUTH_CODE);
            final String clientSecret = oauthRequest.getClientSecret();
            boolean checkVerifyAccess = codeManager.verifyAccess(clientId, clientSecret, consumerManager);
            if (!checkVerifyAccess) {
                _logger.error(ERROR_AUTHENTICATION_FAILED);
                return null;
            } else if (!codeManager.verifyCode(authCode, request.getRemoteAddr())) {
                _logger.error("OAuth2 authcode does not match or the source of client is different");
                return null;
            }
            return this.registerToken(request, clientId, oauthType, null);
        } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.PASSWORD.toString())) {
            final String username = oauthRequest.getUsername();
            final String password = oauthRequest.getPassword();
            final String oauthType = GrantType.PASSWORD.toString();
            IUserManager userManager = (IUserManager) ApsWebApplicationUtils.getBean(SystemConstants.USER_MANAGER, request);
            UserDetails user = userManager.getUser(username, password);
            if (user == null) {
                _logger.error(ERROR_AUTHENTICATION_FAILED);
                return null;
            }
            return this.registerToken(request, username, oauthType, null);
        } else {
            return null;
        }
    } catch (OAuthSystemException e) {
        _logger.error("OAuthSystemException - {} ", e);
        return null;
    } catch (OAuthProblemException e) {
        _logger.error("OAuthProblemException - {} ", e.getError().concat(" ").concat(e.getDescription()));
        _logger.debug("OAuthProblemException - {} ", e);
        return null;
    }
}
Also used : OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) UserDetails(com.agiletec.aps.system.services.user.UserDetails) IOAuthConsumerManager(org.entando.entando.aps.system.services.oauth2.IOAuthConsumerManager) IUserManager(com.agiletec.aps.system.services.user.IUserManager) IApiOAuthorizationCodeManager(org.entando.entando.aps.system.services.oauth2.IApiOAuthorizationCodeManager) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) OAuthTokenRequest(org.apache.oltu.oauth2.as.request.OAuthTokenRequest)

Example 8 with UserDetails

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

the class BaseTestCase 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 9 with UserDetails

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

the class TestAuthorizationManager method testCheckAdminUser.

public void testCheckAdminUser() throws Throwable {
    // nel database di test, username e password sono uguali
    UserDetails adminUser = this._authenticationProvider.getUser("admin", "admin");
    assertNotNull(adminUser);
    assertEquals("admin", adminUser.getUsername());
    assertEquals(1, adminUser.getAuthorizations().size());
    List<Group> groups = this._groupManager.getGroups();
    for (int i = 0; i < groups.size(); i++) {
        Group group = groups.get(i);
        boolean check = this._authorizationManager.isAuth(adminUser, group);
        assertTrue(check);
        check = this._authorizationManager.isAuthOnGroup(adminUser, group.getName());
        assertTrue(check);
    }
    List<Permission> permissions = new ArrayList<Permission>(this._roleManager.getPermissions());
    for (int i = 0; i < permissions.size(); i++) {
        Permission perm = permissions.get(i);
        boolean check = this._authorizationManager.isAuth(adminUser, perm);
        assertTrue(check);
        check = this._authorizationManager.isAuthOnPermission(adminUser, perm.getName());
        assertTrue(check);
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Permission(com.agiletec.aps.system.services.role.Permission) ArrayList(java.util.ArrayList)

Example 10 with UserDetails

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

the class TestAuthorizationManager method testGroupsByPermission_2.

public void testGroupsByPermission_2() throws Throwable {
    int allGroupSize = this._groupManager.getGroups().size();
    String username = "admin";
    UserDetails user = this._authenticationProvider.getUser(username);
    List<Group> autorities = this._authorizationManager.getGroupsByPermission(user, Permission.MANAGE_PAGES);
    assertNotNull(autorities);
    assertEquals(allGroupSize, autorities.size());
    autorities = this._authorizationManager.getGroupsByPermission(user, Permission.SUPERUSER);
    assertNotNull(autorities);
    assertEquals(allGroupSize, autorities.size());
    autorities = this._authorizationManager.getGroupsByPermission(user, "wrong_permission");
    assertNotNull(autorities);
    assertEquals(allGroupSize, autorities.size());
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails)

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