Created
April 10, 2014 06:00
-
-
Save bmvakili/10346438 to your computer and use it in GitHub Desktop.
Liferay Miscellanious util scripts. Create user, check password required. Written in Beanshell for Liferay Script page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.liferay.portal.model.*; | |
import com.liferay.portal.service.*; | |
import com.liferay.counter.service.*; | |
import com.liferay.portal.util.*; | |
import java.util.*; | |
import org.apache.commons.lang.exception.*; | |
/*********** DEBUG VARIABLES *****************/ | |
dbg = ""; | |
C = "\n"; | |
count = -1; | |
group = null; | |
serviceContext = ServiceContextThreadLocal.getServiceContext(); | |
companyId = serviceContext.getCompanyId(); | |
date = new Date(); | |
name = "OOBLiferay"; | |
emailAddress = date.getTime() + name + "@mailinator.com"; | |
screenName = name + userId; | |
password = "Password1"; | |
user = null; | |
passwordPolicy = null; | |
try { | |
user = UserLocalServiceUtil.addUser( | |
0l, //long creatorUserId, | |
companyId, //long companyId, | |
true, //boolean autoPassword, | |
password, //String password1, | |
password, //String password2, | |
false, //boolean autoScreenName, | |
screenName, //String screenName, | |
emailAddress, //String emailAddress, | |
0l, //long facebookId, | |
"", // String openId, | |
Locale.US, //Locale locale, | |
name, //String firstName, | |
"", //String middleName, | |
name, //String lastName, | |
0, //int prefixId, | |
0, //int suffixId, | |
true, //boolean male, | |
Calendar.JANUARY, //int birthdayMonth, | |
1, //int birthdayDay, | |
1970, //int birthdayYear, | |
"", //String jobTitle, | |
null, //long[] groupIds, | |
null, //long[] organizationIds, | |
null, //long[] roleIds, | |
null, //long[] userGroupIds, | |
false, //boolean sendEmail | |
serviceContext | |
); | |
defaultUser = UserLocalServiceUtil.getDefaultUser(companyId); | |
passwordPolicy = user.getPasswordPolicy(); | |
} catch(Exception e) { | |
dbg += ExceptionUtils.getStackTrace(e); | |
e.printStackTrace(); | |
} | |
if (user != null) { | |
dbg += C + "user: "; | |
dbg += C + serviceContext.getPortalURL() + "/web/" + user.getScreenName(); | |
dbg += C + user.getScreenName(); | |
dbg += C + user.getUserId(); | |
dbg += C + user.getPasswordReset(); | |
} | |
if (passwordPolicy != null) { | |
dbg += C + "password policy: "; | |
dbg += C + passwordPolicy; | |
dbg += C + passwordPolicy.isChangeable(); | |
dbg += C + passwordPolicy.isChangeRequired(); | |
if ((passwordPolicy != null) && passwordPolicy.isChangeable() && | |
passwordPolicy.isChangeRequired()) { | |
dbg += C + "hit..."; | |
} | |
} | |
out.println(dbg); | |
// Clean up | |
try { | |
UserLocalServiceUtil.deleteUser(user); | |
} catch(Exception e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment