Search in sources :

Example 51 with UserDetails

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

the class BaseAction method hasCurrentUserPermission.

/**
 * Check if the current user has the given permission granted. It always returns true if the
 * user has the the "superuser" permission set in some role.
 * @param permissionName The name of the permission to check against the current user.
 * @return true if the user has the permission granted, false otherwise.
 */
protected boolean hasCurrentUserPermission(String permissionName) {
    UserDetails currentUser = this.getCurrentUser();
    IAuthorizationManager authManager = this.getAuthorizationManager();
    return authManager.isAuthOnPermission(currentUser, permissionName) || authManager.isAuthOnPermission(currentUser, Permission.SUPERUSER);
}
Also used : IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) UserDetails(com.agiletec.aps.system.services.user.UserDetails)

Example 52 with UserDetails

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

the class TestCacheInfoManager method testGetContents_1.

// ---------------------------------------------- ContentList
public void testGetContents_1() throws Throwable {
    try {
        UserDetails guestUser = super.getUser(SystemConstants.GUEST_USER_NAME);
        MockContentListBean bean = new MockContentListBean();
        bean.setContentType("ART");
        assertTrue(bean.isCacheable());
        String cacheKey = BaseContentListHelper.buildCacheKey(bean, guestUser);
        assertNull(this._cacheInfoManager.getFromCache(ICacheInfoManager.DEFAULT_CACHE_NAME, cacheKey));
        List<String> contents = this._contentListHelper.getContentsId(bean, guestUser);
        assertTrue(contents.size() > 0);
        List<String> cachedContents = (List<String>) this._cacheInfoManager.getFromCache(ICacheInfoManager.DEFAULT_CACHE_NAME, cacheKey);
        assertNotNull(cachedContents);
        assertEquals(contents.size(), cachedContents.size());
        for (int i = 0; i < cachedContents.size(); i++) {
            assertEquals(contents.get(i), cachedContents.get(i));
        }
    } catch (Throwable t) {
        throw t;
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) MockContentListBean(org.entando.entando.plugins.jacms.aps.system.services.MockContentListBean) List(java.util.List)

Example 53 with UserDetails

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

the class TestContentBulkCommand method testCategoryCommands.

public void testCategoryCommands() {
    Collection<String> items = new ArrayList<String>();
    Collection<Category> categories = new ArrayList<Category>();
    UserDetails currentUser = null;
    BaseContentPropertyBulkCommand<Category> categoryCommand = this.initCategoriesCommand(JoinCategoryBulkCommand.BEAN_NAME, items, categories, currentUser);
    assertNotNull(categoryCommand);
    categoryCommand = this.initCategoriesCommand(RemoveCategoryBulkCommand.BEAN_NAME, items, categories, currentUser);
    assertNotNull(categoryCommand);
}
Also used : Category(com.agiletec.aps.system.services.category.Category) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ArrayList(java.util.ArrayList)

Example 54 with UserDetails

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

the class AbstractControllerTest method mockOAuthInterceptor.

protected String mockOAuthInterceptor(UserDetails user) throws Exception, ApsSystemException {
    String accessToken = OAuth2TestUtils.getValidAccessToken();
    when(apiOAuth2TokenManager.getApiOAuth2Token(Mockito.anyString())).thenReturn(OAuth2TestUtils.getOAuth2Token(user.getUsername(), accessToken));
    when(authenticationProviderManager.getUser(user.getUsername())).thenReturn(user);
    when(authorizationManager.isAuthOnPermission(any(UserDetails.class), anyString())).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            UserDetails user = (UserDetails) invocation.getArguments()[0];
            String permissionName = (String) invocation.getArguments()[1];
            return new AuthorizationManager().isAuthOnPermission(user, permissionName);
        }
    });
    return accessToken;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) AuthorizationManager(com.agiletec.aps.system.services.authorization.AuthorizationManager)

Example 55 with UserDetails

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

the class CategoryControllerIntegrationTest method testGetInvalidCategoryTree.

@Test
public void testGetInvalidCategoryTree() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    this.executeGet("invalid_code", accessToken, status().isNotFound());
    ResultActions result = mockMvc.perform(get("/categories").param("parentCode", "invalid_code").header("Authorization", "Bearer " + accessToken));
    System.out.println(result.andReturn().getResponse().getContentAsString());
    result.andExpect(status().isNotFound());
}
Also used : 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)

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