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