use of com.liferay.portal.kernel.exception.PortalException in project liferay-blade-samples by liferay.
the class CustomScreenNameValidator method getAUIValidatorJS.
/**
* Returns the JavaScript function to validate the screen name client-side.
*
* @return the JavaScript function
*/
@Override
public String getAUIValidatorJS() {
StringBuilder javascript = new StringBuilder();
try {
Company company = _companyLocalService.getCompanyByWebId(PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID));
long companyId = company.getCompanyId();
String[] reservedWords = _getReservedWords(companyId);
javascript.append("function(val) { return !(");
for (int i = 0; i < reservedWords.length; i++) {
javascript.append("val.indexOf(\"" + reservedWords[i] + "\") !== -1");
if ((reservedWords.length > 1) && (i < (reservedWords.length - 1))) {
javascript.append(" || ");
}
}
javascript.append(")}");
} catch (PortalException pe) {
_log.error(pe);
}
return javascript.toString();
}
use of com.liferay.portal.kernel.exception.PortalException in project sw360portal by sw360.
the class UserUtils method findLiferayUser.
private static Optional<User> findLiferayUser(PortletRequest request, org.eclipse.sw360.datahandler.thrift.users.User user) {
long companyId = getCompanyId(request);
User liferayUser = null;
try {
liferayUser = UserLocalServiceUtil.getUserByEmailAddress(companyId, user.getEmail());
} catch (PortalException | SystemException e) {
log.error("Could not find Liferay user", e);
}
return Optional.ofNullable(liferayUser);
}
use of com.liferay.portal.kernel.exception.PortalException in project sw360portal by sw360.
the class TestAutoLogin method login.
@Override
public String[] login(HttpServletRequest request, HttpServletResponse response) throws AutoLoginException {
// first let's check how the incoming request header looks like
StringBuilder headerRep = new StringBuilder();
headerRep.append("(login) header from request with URL from client: '" + request.getRequestURL() + "'.\n");
Enumeration keys = request.getHeaderNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
headerRep.append(" '" + key + "'/'" + request.getHeader(key) + "'\n");
}
log.debug("Received header:\n" + headerRep.toString());
// then, let's login with a hard coded user in any case ...
long companyId = PortalUtil.getCompanyId(request);
final String emailId = "user@sw360.org";
User user = null;
try {
user = UserLocalServiceUtil.getUserByEmailAddress(companyId, emailId);
} catch (SystemException e) {
log.error("System exception at getUserByEmailAddress(): " + e.getMessage(), e);
} catch (PortalException e) {
log.error("Portal exception at getUserByEmailAddress(): " + e.getMessage(), e);
}
// If user was found by liferay
if (user != null) {
// Create a return credentials object
return new String[] { String.valueOf(user.getUserId()), // Encrypted Liferay password
user.getPassword(), // True: password is encrypted
Boolean.TRUE.toString() };
} else {
log.error("Could not fetch user from backend: '" + emailId + "'.");
return new String[] {};
}
}
use of com.liferay.portal.kernel.exception.PortalException 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.kernel.exception.PortalException in project sw360portal by sw360.
the class SSOAutoLogin method login.
@Override
public String[] login(HttpServletRequest request, HttpServletResponse response) throws AutoLoginException {
String emailId = request.getHeader(AUTH_EMAIL_VALUE);
String extid = request.getHeader(AUTH_EXTID_VALUE);
log.info("Attempting auto login for email: '" + emailId + "' and external id: '" + extid + "'");
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
log.debug(key + ":" + value);
}
if (emailId == null || emailId.isEmpty() || extid == null || extid.isEmpty()) {
log.error("Empty credentials, auto login impossible.");
return new String[] {};
}
long companyId = PortalUtil.getCompanyId(request);
User user = null;
try {
user = UserLocalServiceUtil.getUserByEmailAddress(companyId, emailId);
} catch (SystemException | PortalException e) {
log.error("Exception during get user by email: '" + emailId + "' and company id: '" + companyId + "'", e);
}
// If user was found by liferay
if (user != null) {
// Create a return credentials object
return new String[] { String.valueOf(user.getUserId()), // Encrypted Liferay password
user.getPassword(), // True: password is encrypted
Boolean.TRUE.toString() };
} else {
log.error("Could not get user with email: '" + emailId + "'.");
return new String[] {};
}
}
Aggregations