use of com.liferay.portal.theme.ThemeDisplay in project liferay-ide by liferay.
the class ServicePreAction method doRun.
protected void doRun(HttpServletRequest request, HttpServletResponse response) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
if (!_PORTLET_ADD_DEFAULT_RESOURCE_CHECK_ENABLED) {
return;
}
if (!themeDisplay.isLifecycleRender()) {
return;
}
String portletId = ParamUtil.getString(request, "p_p_id");
if (Validator.isNull(portletId)) {
return;
}
if (!portletId.equals(PortletKeys.KNOWLEDGE_BASE_ARTICLE_DEFAULT_INSTANCE)) {
return;
}
String request_p_p_auth = ParamUtil.getString(request, "p_p_auth");
if (Validator.isNull(request_p_p_auth)) {
return;
}
String actual_p_p_auth = AuthTokenUtil.getToken(request, themeDisplay.getPlid(), portletId);
if (request_p_p_auth.equals(actual_p_p_auth)) {
return;
}
// A guest user that signs in will cause the original portlet
// authentication token to become stale. See SessionAuthToken.
String redirect = HttpUtil.setParameter(themeDisplay.getURLCurrent(), "p_p_auth", actual_p_p_auth);
response.sendRedirect(redirect);
}
use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.
the class UserCacheHolder method getCurrentUserEmail.
protected Optional<String> getCurrentUserEmail(ServletRequest request) {
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
com.liferay.portal.model.User liferayUser = themeDisplay.getUser();
return Optional.ofNullable(liferayUser).map(com.liferay.portal.model.User::getEmailAddress);
}
use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.
the class UserPortletUtils method addLiferayUser.
public static User addLiferayUser(PortletRequest request, String firstName, String lastName, String emailAddress, String organizationName, String roleName, boolean male, String externalId, String password, boolean passwordEncrypted, boolean activateImmediately) throws SystemException, PortalException {
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
long companyId = themeDisplay.getCompanyId();
long organizationId = OrganizationLocalServiceUtil.getOrganizationId(companyId, organizationName);
final Role role = RoleLocalServiceUtil.getRole(companyId, roleName);
long roleId = role.getRoleId();
return addLiferayUser(request, firstName, lastName, emailAddress, organizationId, roleId, male, externalId, password, passwordEncrypted, activateImmediately);
}
use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.
the class UserPortletUtils method addLiferayUser.
private static User addLiferayUser(PortletRequest request, String firstName, String lastName, String emailAddress, long organizationId, long roleId, boolean isMale, String externalId, String password, boolean passwordEncrypted, boolean activateImmediately) {
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
String screenName = firstName + lastName;
long companyId = themeDisplay.getCompanyId();
try {
if (userAlreadyExists(request, emailAddress, externalId, screenName, companyId)) {
return null;
}
} catch (PortalException | SystemException e) {
log.error(e);
// won't try to create user if even checking for existing user failed
return null;
}
try {
ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
long[] roleIds = roleId == 0 ? new long[] {} : new long[] { roleId };
long[] organizationIds = organizationId == 0 ? new long[] {} : new long[] { organizationId };
long[] userGroupIds = null;
long currentUserId = themeDisplay.getUserId();
User user = UserLocalServiceUtil.addUser(currentUserId, /*creator*/
companyId, false, /*autoPassword*/
password, password, false, /*autoScreenName*/
screenName, emailAddress, 0, /*facebookId*/
externalId, /*openId*/
themeDisplay.getLocale(), firstName, "", /*middleName*/
lastName, 0, /*prefixId*/
0, /*suffixId*/
isMale, 4, /*birthdayMonth*/
12, /*birthdayDay*/
1959, /*birthdayYear*/
"", /*jobTitle*/
null, /*groupIds*/
organizationIds, roleIds, userGroupIds, false, /*sendEmail*/
serviceContext);
user.setPasswordReset(false);
if (passwordEncrypted) {
user.setPassword(password);
user.setPasswordEncrypted(true);
}
Role role = RoleLocalServiceUtil.getRole(roleId);
RoleUtil.addUser(role.getRoleId(), user.getUserId());
UserLocalServiceUtil.updateUser(user);
RoleLocalServiceUtil.updateRole(role);
UserLocalServiceUtil.updateStatus(user.getUserId(), activateImmediately ? WorkflowConstants.STATUS_APPROVED : WorkflowConstants.STATUS_INACTIVE);
Indexer indexer = IndexerRegistryUtil.getIndexer(User.class);
indexer.reindex(user);
return user;
} catch (PortalException | SystemException e) {
log.error(e);
return null;
}
}
use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.
the class UserPortlet method getCurrentUser.
private User getCurrentUser(PortletRequest request) throws SW360Exception {
User user;
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
if (themeDisplay.isSignedIn())
user = themeDisplay.getUser();
else {
throw new SW360Exception("Broken portlet!");
}
return user;
}
Aggregations