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);
}
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;
}
}
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);
}
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;
}
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());
}
Aggregations