- * Adds given username as learner or monitor (as specified by asStaff parameter) to all lessons in
- * given LAMS group.
+ * Adds given username as learner or monitor (as specified by asStaff parameter) to all lessons in given LAMS group.
*
*
*
- * The LAMS group is identified by the external courseId parameter. If the courseId doesn't exist in the
- * lams_ext_course_class_map table, then a new LAMS group is created. If it does exist, the group name is
- * updated.
+ * The LAMS group is identified by the external courseId parameter. If the courseId doesn't exist in the
+ * lams_ext_course_class_map table, then a new LAMS group is created. If it does exist, the group name is updated.
*
*/
+ @Override
public boolean addUserToGroupLessons(String username, String serverId, String datetime, String hash,
String courseId, String courseName, String countryIsoCode, String langIsoCode, Boolean asStaff)
- throws java.rmi.RemoteException {
+ throws java.rmi.RemoteException {
try {
// authenticate external server
- ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId);
+ ExtServerOrgMap serverMap = RegisterServiceSoapBindingImpl.integrationService.getExtServerOrgMap(serverId);
Authenticator.authenticate(serverMap, datetime, hash);
// get group to use for this request
- ExtUserUseridMap userMap = integrationService.getExtUserUseridMap(serverMap, username);
- ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap(serverMap, userMap, courseId,
- courseName, countryIsoCode, langIsoCode, service.getRootOrganisation().getOrganisationId()
- .toString(), asStaff, false);
+ ExtUserUseridMap userMap = RegisterServiceSoapBindingImpl.integrationService.getExtUserUseridMap(serverMap,
+ username);
+ ExtCourseClassMap orgMap = RegisterServiceSoapBindingImpl.integrationService.getExtCourseClassMap(serverMap,
+ userMap, courseId, courseName, countryIsoCode, langIsoCode,
+ RegisterServiceSoapBindingImpl.service.getRootOrganisation().getOrganisationId().toString(),
+ asStaff, false);
Organisation org = orgMap.getOrganisation();
// add user to lessons
- User user = service.getUserByLogin(username);
+ User user = RegisterServiceSoapBindingImpl.service.getUserByLogin(username);
addUserToLessons(user, org, asStaff);
return true;
} catch (Exception e) {
@@ -299,29 +317,33 @@
/**
* Same as addUserToLessons, except adds user to lessons in given subgroup.
*/
+ @Override
public boolean addUserToSubgroupLessons(String username, String serverId, String datetime, String hash,
String courseId, String courseName, String countryIsoCode, String langIsoCode, String subgroupId,
String subgroupName, Boolean asStaff) throws java.rmi.RemoteException {
try {
// authenticate external server
- ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId);
+ ExtServerOrgMap serverMap = RegisterServiceSoapBindingImpl.integrationService.getExtServerOrgMap(serverId);
Authenticator.authenticate(serverMap, datetime, hash);
// get group to use for this request
- ExtUserUseridMap userMap = integrationService.getExtUserUseridMap(serverMap, username);
- ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap(serverMap, userMap, courseId,
- courseName, countryIsoCode, langIsoCode, service.getRootOrganisation().getOrganisationId()
- .toString(), asStaff, false);
+ ExtUserUseridMap userMap = RegisterServiceSoapBindingImpl.integrationService.getExtUserUseridMap(serverMap,
+ username);
+ ExtCourseClassMap orgMap = RegisterServiceSoapBindingImpl.integrationService.getExtCourseClassMap(serverMap,
+ userMap, courseId, courseName, countryIsoCode, langIsoCode,
+ RegisterServiceSoapBindingImpl.service.getRootOrganisation().getOrganisationId().toString(),
+ asStaff, false);
Organisation group = orgMap.getOrganisation();
// get subgroup to add user to
- ExtCourseClassMap subOrgMap = integrationService.getExtCourseClassMap(serverMap, userMap, subgroupId,
- subgroupName, countryIsoCode, langIsoCode, group.getOrganisationId().toString(), asStaff, false);
+ ExtCourseClassMap subOrgMap = RegisterServiceSoapBindingImpl.integrationService.getExtCourseClassMap(
+ serverMap, userMap, subgroupId, subgroupName, countryIsoCode, langIsoCode,
+ group.getOrganisationId().toString(), asStaff, false);
Organisation subgroup = subOrgMap.getOrganisation();
// add user to subgroup lessons
if (subgroup != null) {
- User user = service.getUserByLogin(username);
+ User user = RegisterServiceSoapBindingImpl.service.getUserByLogin(username);
addUserToLessons(user, subgroup, asStaff);
return true;
}
@@ -337,9 +359,10 @@
Iterator iter2 = org.getLessons().iterator();
while (iter2.hasNext()) {
Lesson lesson = (Lesson) iter2.next();
- lessonService.addLearner(lesson.getLessonId(), user.getUserId());
- if (asStaff)
- lessonService.addStaffMember(lesson.getLessonId(), user.getUserId());
+ RegisterServiceSoapBindingImpl.lessonService.addLearner(lesson.getLessonId(), user.getUserId());
+ if (asStaff) {
+ RegisterServiceSoapBindingImpl.lessonService.addStaffMember(lesson.getLessonId(), user.getUserId());
+ }
if (log.isDebugEnabled()) {
log.debug("Added " + user.getLogin() + " to " + lesson.getLessonName()
+ (asStaff ? " as staff, and" : " as learner"));
Index: lams_central/web/login.jsp
===================================================================
RCS file: /usr/local/cvsroot/lams_central/web/login.jsp,v
diff -u -r1.51.2.7 -r1.51.2.8
--- lams_central/web/login.jsp 20 Oct 2015 10:41:38 -0000 1.51.2.7
+++ lams_central/web/login.jsp 21 Oct 2015 11:44:56 -0000 1.51.2.8
@@ -11,7 +11,6 @@
--%>
-
@@ -26,23 +25,15 @@
--%>
- <%-- If credentials came from attributes, no need for encrypting --%>
- <%= Configuration.getAsBoolean(ConfigurationKeys.LDAP_ENCRYPT_PASSWORD_FROM_BROWSER) %>
-
Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/usermanagement/User.hbm.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/usermanagement/User.hbm.xml,v
diff -u -r1.35.2.3 -r1.35.2.4
--- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/usermanagement/User.hbm.xml 15 Oct 2014 07:48:47 -0000 1.35.2.3
+++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/usermanagement/User.hbm.xml 21 Oct 2015 11:44:55 -0000 1.35.2.4
@@ -62,16 +62,30 @@
type="java.lang.String"
column="password"
not-null="true"
- length="50"
+ length="64"
>
@hibernate.property
column="password"
- length="50"
+ length="64"
not-null="true"
+
+ @hibernate.property
+ column="salt"
+ length="64"
+ not-null="false"
+
+
+ getExtUserUseridMapByServerMap(ExtServerOrgMap serverMap);
/**
@@ -94,9 +96,10 @@
ExtServerOrgMap getExtServerOrgMap(Integer sid);
ExtServerOrgMap getExtServerOrgMap(String serverId);
-
+
/**
- * Returns ExtCourseClassMap. If ExtCourseClassMap doesn't existent - returns null and does not create a new ExtCourseClassMap.
+ * Returns ExtCourseClassMap. If ExtCourseClassMap doesn't existent - returns null and does not create a new
+ * ExtCourseClassMap.
*
* @param extServerOrgMapId
* @param extCourseId
@@ -113,16 +116,17 @@
* @param country
* @param email
* @param prefix
- * @param isUpdateUserDetails whether user details should be updated with provided parameters
+ * @param isUpdateUserDetails
+ * whether user details should be updated with provided parameters
* @return
* @throws UserInfoValidationException
*/
ExtUserUseridMap getImplicitExtUserUseridMap(ExtServerOrgMap serverMap, String extUsername, String firstName,
String lastName, String language, String country, String email, boolean prefix, boolean isUpdateUserDetails)
- throws UserInfoValidationException;
+ throws UserInfoValidationException;
ExtUserUseridMap getImplicitExtUserUseridMap(ExtServerOrgMap serverMap, String extUsername, String password,
- String firstName, String lastName, String email) throws UserInfoValidationException;
+ String salt, String firstName, String lastName, String email) throws UserInfoValidationException;
List getAllExtServerOrgMaps();
Index: lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java,v
diff -u -r1.33.2.2 -r1.33.2.3
--- lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java 13 Feb 2015 23:34:26 -0000 1.33.2.2
+++ lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java 21 Oct 2015 11:44:55 -0000 1.33.2.3
@@ -41,7 +41,6 @@
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
-import org.apache.struts.action.ActionMessage;
import org.lamsfoundation.lams.integration.ExtCourseClassMap;
import org.lamsfoundation.lams.integration.ExtServerLessonMap;
import org.lamsfoundation.lams.integration.ExtServerOrgMap;
@@ -62,8 +61,6 @@
import org.lamsfoundation.lams.usermanagement.UserOrganisationRole;
import org.lamsfoundation.lams.usermanagement.service.IUserManagementService;
import org.lamsfoundation.lams.util.CSVUtil;
-import org.lamsfoundation.lams.util.Configuration;
-import org.lamsfoundation.lams.util.ConfigurationKeys;
import org.lamsfoundation.lams.util.HashUtil;
import org.lamsfoundation.lams.util.LanguageUtil;
import org.lamsfoundation.lams.util.ValidationUtil;
@@ -92,28 +89,29 @@
@Override
public ExtServerOrgMap getExtServerOrgMap(String serverId) {
List list = service.findByProperty(ExtServerOrgMap.class, "serverid", serverId);
- if (list == null || list.size() == 0) {
+ if ((list == null) || (list.size() == 0)) {
return null;
} else {
return (ExtServerOrgMap) list.get(0);
}
}
-
+
@Override
public ExtCourseClassMap getExtCourseClassMap(Integer extServerOrgMapId, String extCourseId) {
Map properties = new HashMap();
properties.put("courseid", extCourseId);
properties.put("extServerOrgMap.sid", extServerOrgMapId);
List list = service.findByProperties(ExtCourseClassMap.class, properties);
- if (list == null || list.size() == 0) {
+ if ((list == null) || (list.size() == 0)) {
return null;
} else {
- return (ExtCourseClassMap) list.get(0);
+ return list.get(0);
}
}
// wrapper method for compatibility with original integration modules
+ @Override
public ExtCourseClassMap getExtCourseClassMap(ExtServerOrgMap serverMap, ExtUserUseridMap userMap,
String extCourseId, String countryIsoCode, String langIsoCode, String prettyCourseName, String method,
Boolean prefix) throws UserInfoValidationException {
@@ -136,60 +134,61 @@
}
// wrapper method for compatibility with original integration modules
+ @Override
public ExtCourseClassMap getExtCourseClassMap(ExtServerOrgMap serverMap, ExtUserUseridMap userMap,
- String extCourseId, String countryIsoCode, String langIsoCode, String prettyCourseName, String method) throws UserInfoValidationException {
+ String extCourseId, String countryIsoCode, String langIsoCode, String prettyCourseName, String method)
+ throws UserInfoValidationException {
return getExtCourseClassMap(serverMap, userMap, extCourseId, countryIsoCode, langIsoCode, prettyCourseName,
method, true);
}
// newer method which accepts course name, a parent org id, a flag for whether user should get
// 'teacher' roles, and a flag for whether to use a prefix in the org's name
+ @Override
public ExtCourseClassMap getExtCourseClassMap(ExtServerOrgMap serverMap, ExtUserUseridMap userMap,
String extCourseId, String extCourseName, String countryIsoCode, String langIsoCode, String parentOrgId,
Boolean isTeacher, Boolean prefix) throws UserInfoValidationException {
Organisation org;
User user = userMap.getUser();
-
+
ExtCourseClassMap extCourseClassMap = getExtCourseClassMap(serverMap.getSid(), extCourseId);
if (extCourseClassMap == null) {
//create new ExtCourseClassMap
-
- org = createOrganisation(serverMap, user, extCourseId, extCourseName, countryIsoCode,
- langIsoCode, parentOrgId, prefix);
+
+ org = createOrganisation(serverMap, user, extCourseId, extCourseName, countryIsoCode, langIsoCode,
+ parentOrgId, prefix);
extCourseClassMap = new ExtCourseClassMap();
extCourseClassMap.setCourseid(extCourseId);
extCourseClassMap.setExtServerOrgMap(serverMap);
extCourseClassMap.setOrganisation(org);
service.save(extCourseClassMap);
-
+
} else {
org = extCourseClassMap.getOrganisation();
// update external course name if if has changed
String requestedCourseName = prefix ? buildName(serverMap.getPrefix(), extCourseName) : extCourseName;
- if (extCourseName != null && !org.getName().equals(requestedCourseName)) {
+ if ((extCourseName != null) && !org.getName().equals(requestedCourseName)) {
// validate org name
if (!ValidationUtil.isOrgNameValid(requestedCourseName)) {
- throw new UserInfoValidationException(
- "Can't create organisation due to validation error: "
- + "organisation name cannot contain any of these characters < > ^ * @ % $. External server:"
- + serverMap.getServerid() + ", orgId:" + extCourseId + ", orgName:"
- + requestedCourseName);
+ throw new UserInfoValidationException("Can't create organisation due to validation error: "
+ + "organisation name cannot contain any of these characters < > ^ * @ % $. External server:"
+ + serverMap.getServerid() + ", orgId:" + extCourseId + ", orgName:" + requestedCourseName);
}
org.setName(requestedCourseName);
service.updateOrganisationandWorkspaceNames(org);
}
}
-
+
updateUserRoles(user, org, isTeacher);
-
+
return extCourseClassMap;
}
private void updateUserRoles(User user, Organisation org, Boolean isTeacher) {
-
+
//create UserOrganisation if it doesn't exist
UserOrganisation uo = service.getUserOrganisation(user.getUserId(), org.getOrganisationId());
if (uo == null) {
@@ -198,7 +197,7 @@
user.addUserOrganisation(uo);
service.save(user);
}
-
+
Integer[] roles;
if (isTeacher) {
roles = new Integer[] { Role.ROLE_AUTHOR, Role.ROLE_MONITOR, Role.ROLE_LEARNER };
@@ -214,7 +213,8 @@
}
}
}
-
+
+ @Override
public List getExtUserUseridMapByServerMap(ExtServerOrgMap serverMap) {
Map properties = new HashMap();
properties.put("extServerOrgMap.sid", serverMap.getSid());
@@ -226,11 +226,12 @@
public ExtUserUseridMap getExtUserUseridMap(ExtServerOrgMap serverMap, String extUsername, boolean prefix)
throws UserInfoFetchException, UserInfoValidationException {
ExtUserUseridMap extUserUseridMap = getExistingExtUserUseridMap(serverMap, extUsername);
-
+
if (extUserUseridMap == null) {
String[] userData = getUserDataFromExtServer(serverMap, extUsername);
- String password = HashUtil.sha1(RandomPasswordGenerator.nextPassword(10));
- return createExtUserUseridMap(serverMap, extUsername, password, userData, prefix);
+ String salt = HashUtil.salt();
+ String password = HashUtil.sha256(RandomPasswordGenerator.nextPassword(10), salt);
+ return createExtUserUseridMap(serverMap, extUsername, password, salt, userData, prefix);
} else {
return extUserUseridMap;
}
@@ -248,43 +249,44 @@
properties.put("extServerOrgMap.sid", serverMap.getSid());
properties.put("extUsername", extUsername);
List list = service.findByProperties(ExtUserUseridMap.class, properties);
-
- if (list == null || list.size() == 0) {
+
+ if ((list == null) || (list.size() == 0)) {
return null;
} else {
- return (ExtUserUseridMap) list.get(0);
+ return list.get(0);
}
}
@Override
public ExtUserUseridMap getImplicitExtUserUseridMap(ExtServerOrgMap serverMap, String extUsername, String password,
- String firstName, String lastName, String email) throws UserInfoValidationException {
+ String salt, String firstName, String lastName, String email) throws UserInfoValidationException {
ExtUserUseridMap extUserUseridMap = getExistingExtUserUseridMap(serverMap, extUsername);
-
+
if (extUserUseridMap == null) {
String[] defaultLangCountry = LanguageUtil.getDefaultLangCountry();
- String[] userData = { "", firstName, lastName, "", "", "", "", "", "", "", "", email,
- defaultLangCountry[1], defaultLangCountry[0] };
- return createExtUserUseridMap(serverMap, extUsername, password, userData, false);
+ String[] userData = { "", firstName, lastName, "", "", "", "", "", "", "", "", email, defaultLangCountry[1],
+ defaultLangCountry[0] };
+ return createExtUserUseridMap(serverMap, extUsername, password, salt, userData, false);
} else {
return extUserUseridMap;
}
}
@Override
- public ExtUserUseridMap getImplicitExtUserUseridMap(ExtServerOrgMap serverMap, String extUsername,
- String firstName, String lastName, String language, String country, String email, boolean prefix,
- boolean isUpdateUserDetails) throws UserInfoValidationException {
-
+ public ExtUserUseridMap getImplicitExtUserUseridMap(ExtServerOrgMap serverMap, String extUsername, String firstName,
+ String lastName, String language, String country, String email, boolean prefix, boolean isUpdateUserDetails)
+ throws UserInfoValidationException {
+
ExtUserUseridMap extUserUseridMap = getExistingExtUserUseridMap(serverMap, extUsername);
-
+
//create new one if it doesn't exist yet
if (extUserUseridMap == null) {
String[] userData = { "", firstName, lastName, "", "", "", "", "", "", "", "", email, country, language };
- String password = HashUtil.sha1(RandomPasswordGenerator.nextPassword(10));
- return createExtUserUseridMap(serverMap, extUsername, password, userData, prefix);
-
- //update user details if it's required
+ String salt = HashUtil.salt();
+ String password = HashUtil.sha256(RandomPasswordGenerator.nextPassword(10), salt);
+ return createExtUserUseridMap(serverMap, extUsername, password, salt, userData, prefix);
+
+ //update user details if it's required
} else if (isUpdateUserDetails) {
User user = extUserUseridMap.getUser();
@@ -307,27 +309,28 @@
+ "Email format is invalid. External server:" + serverMap.getServerid() + ", Username:"
+ user.getLogin() + ", firstName:" + firstName + ", lastName:" + lastName);
}
-
+
user.setFirstName(firstName);
user.setLastName(lastName);
user.setEmail(email);
user.setModifiedDate(new Date());
user.setLocale(LanguageUtil.getSupportedLocale(language, country));
service.save(user);
-
+
return extUserUseridMap;
-
- //simply return existing one
+
+ //simply return existing one
} else {
return extUserUseridMap;
}
}
private Organisation createOrganisation(ExtServerOrgMap serverMap, User user, String extCourseId,
- String extCourseName, String countryIsoCode, String langIsoCode, String parentOrgId, Boolean prefix) throws UserInfoValidationException {
-
+ String extCourseName, String countryIsoCode, String langIsoCode, String parentOrgId, Boolean prefix)
+ throws UserInfoValidationException {
+
Organisation org = new Organisation();
-
+
// org name validation
String orgName = prefix ? buildName(serverMap.getPrefix(), extCourseName) : extCourseName;
if (StringUtils.isNotBlank(orgName) && !ValidationUtil.isOrgNameValid(orgName)) {
@@ -336,46 +339,46 @@
+ serverMap.getServerid() + ", orgId:" + extCourseId + ", orgName:" + orgName);
}
org.setName(orgName);
-
+
org.setDescription(extCourseId);
- org.setOrganisationState((OrganisationState) service
- .findById(OrganisationState.class, OrganisationState.ACTIVE));
+ org.setOrganisationState(
+ (OrganisationState) service.findById(OrganisationState.class, OrganisationState.ACTIVE));
org.setLocale(LanguageUtil.getSupportedLocale(langIsoCode, countryIsoCode));
// determine whether org will be a group or subgroup
Organisation parent = (Organisation) service.findById(Organisation.class, Integer.valueOf(parentOrgId));
if (parent != null) {
org.setParentOrganisation(parent);
if (!parent.getOrganisationId().equals(service.getRootOrganisation().getOrganisationId())) {
- org.setOrganisationType((OrganisationType) service.findById(OrganisationType.class,
- OrganisationType.CLASS_TYPE));
+ org.setOrganisationType(
+ (OrganisationType) service.findById(OrganisationType.class, OrganisationType.CLASS_TYPE));
} else {
- org.setOrganisationType((OrganisationType) service.findById(OrganisationType.class,
- OrganisationType.COURSE_TYPE));
+ org.setOrganisationType(
+ (OrganisationType) service.findById(OrganisationType.class, OrganisationType.COURSE_TYPE));
}
} else {
// default
org.setParentOrganisation(service.getRootOrganisation());
- org.setOrganisationType((OrganisationType) service.findById(OrganisationType.class,
- OrganisationType.COURSE_TYPE));
+ org.setOrganisationType(
+ (OrganisationType) service.findById(OrganisationType.class, OrganisationType.COURSE_TYPE));
}
return service.saveOrganisation(org, user.getUserId());
}
// flexible method to specify username and password
private ExtUserUseridMap createExtUserUseridMap(ExtServerOrgMap serverMap, String extUsername, String password,
- String[] userData, boolean prefix) throws UserInfoValidationException {
-
+ String salt, String[] userData, boolean prefix) throws UserInfoValidationException {
+
String login = prefix ? buildName(serverMap.getPrefix(), extUsername) : extUsername;
String firstName = userData[1];
String lastName = userData[2];
String email = userData[11];
-
+
// login validation
if (StringUtils.isBlank(login)) {
- throw new UserInfoValidationException("Can't create user due to validation error: "
- + "Username cannot be blank. External server:" + serverMap.getServerid() + ", firstName:"
- + firstName + ", lastName:" + lastName);
+ throw new UserInfoValidationException(
+ "Can't create user due to validation error: " + "Username cannot be blank. External server:"
+ + serverMap.getServerid() + ", firstName:" + firstName + ", lastName:" + lastName);
} else if (!ValidationUtil.isUserNameValid(login)) {
throw new UserInfoValidationException("Can't create user due to validation error: "
+ "Username can only contain alphanumeric characters and no spaces. External server:"
@@ -402,10 +405,11 @@
+ "Email format is invalid. External server:" + serverMap.getServerid() + ", Username:" + login
+ ", firstName:" + firstName + ", lastName:" + lastName);
}
-
+
User user = new User();
user.setLogin(login);
user.setPassword(password);
+ user.setSalt(salt);
user.setTitle(userData[0]);
user.setFirstName(userData[1]);
user.setLastName(userData[2]);
@@ -418,8 +422,8 @@
user.setMobilePhone(userData[9]);
user.setFax(userData[10]);
user.setEmail(userData[11]);
- user.setAuthenticationMethod((AuthenticationMethod) service.findById(AuthenticationMethod.class,
- AuthenticationMethod.DB));
+ user.setAuthenticationMethod(
+ (AuthenticationMethod) service.findById(AuthenticationMethod.class, AuthenticationMethod.DB));
user.setCreateDate(new Date());
user.setDisabledFlag(false);
user.setLocale(LanguageUtil.getSupportedLocale(userData[13], userData[12]));
@@ -450,17 +454,19 @@
// set the values for the parameters
userDataCallbackUrl = userDataCallbackUrl.replaceAll("%username%", encodedExtUsername)
.replaceAll("%timestamp%", timestamp).replaceAll("%hash%", hash);
- log.debug(userDataCallbackUrl);
+ IntegrationService.log.debug(userDataCallbackUrl);
URL url = new URL(userDataCallbackUrl);
URLConnection conn = url.openConnection();
- if (!(conn instanceof HttpURLConnection))
+ if (!(conn instanceof HttpURLConnection)) {
throw new UserInfoFetchException("Fail to fetch user data from external server:"
+ serverMap.getServerid() + "- Invalid connection type");
+ }
HttpURLConnection httpConn = (HttpURLConnection) conn;
- if (httpConn.getResponseCode() != HttpURLConnection.HTTP_OK)
+ if (httpConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new UserInfoFetchException("Fail to fetch user data from external server:"
+ serverMap.getServerid() + " - Unexpected return HTTP Status:" + httpConn.getResponseCode());
+ }
InputStream is = url.openConnection().getInputStream();
BufferedReader isReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
@@ -473,17 +479,18 @@
return CSVUtil.parse(str);
} catch (MalformedURLException e) {
- log.error(e);
+ IntegrationService.log.error(e);
throw new UserInfoFetchException(e);
} catch (IOException e) {
- log.error(e);
+ IntegrationService.log.error(e);
throw new UserInfoFetchException(e);
} catch (ParseException e) {
- log.error(e);
+ IntegrationService.log.error(e);
throw new UserInfoFetchException(e);
}
}
+ @Override
public String hash(ExtServerOrgMap serverMap, String extUsername, String timestamp) {
String serverId = serverMap.getServerid();
String serverKey = serverMap.getServerkey();
@@ -496,43 +503,50 @@
return prefix + '_' + name;
}
+ @Override
public List getAllExtServerOrgMaps() {
return service.findAll(ExtServerOrgMap.class);
}
+ @Override
@SuppressWarnings("unchecked")
public List getMappedServers(String toolSig) {
Map properties = new HashMap();
properties.put("tool.toolSignature", toolSig);
- return (List) service.findByProperties(ExtServerToolAdapterMap.class, properties);
+ return service.findByProperties(ExtServerToolAdapterMap.class, properties);
}
+ @Override
@SuppressWarnings("unchecked")
public ExtServerToolAdapterMap getMappedServer(String serverId, String toolSig) {
Map properties = new HashMap();
properties.put("tool.toolSignature", toolSig);
properties.put("extServer.serverid", serverId);
List ret = service.findByProperties(ExtServerToolAdapterMap.class, properties);
- if (ret != null && ret.size() > 0) {
+ if ((ret != null) && (ret.size() > 0)) {
return (ExtServerToolAdapterMap) ret.get(0);
} else {
return null;
}
}
+ @Override
public void saveExtServerToolAdapterMap(ExtServerToolAdapterMap map) {
service.save(map);
}
+ @Override
public void deleteExtServerToolAdapterMap(ExtServerToolAdapterMap map) {
service.delete(map);
}
+ @Override
public void saveExtServerOrgMap(ExtServerOrgMap map) {
service.save(map);
}
+ @Override
public ExtServerOrgMap getExtServerOrgMap(Integer sid) {
return (ExtServerOrgMap) service.findById(ExtServerOrgMap.class, sid);
}
@@ -544,6 +558,7 @@
service.save(map);
}
+ @Override
public String getLessonFinishCallbackUrl(User user, Lesson lesson) throws UnsupportedEncodingException {
// the callback url must contain %username%, %lessonid%, %timestamp% and %hash% eg:
// "http://test100.ics.mq.edu.au/webapps/lams-plglamscontent-bb_bb60/UserData?uid=%username%&lessonid=%lessonid%&ts=%timestamp%&hash=%hash%";
@@ -554,7 +569,8 @@
Long lessonId = lesson.getLessonId();
ExtServerLessonMap extServerLesson = getExtServerLessonMap(lessonId);
// checks whether the lesson was created from extServer and whether it has lessonFinishCallbackUrl setting
- if (extServerLesson != null && StringUtils.isNotBlank(extServerLesson.getExtServer().getLessonFinishUrl())) {
+ if ((extServerLesson != null)
+ && StringUtils.isNotBlank(extServerLesson.getExtServer().getLessonFinishUrl())) {
ExtServerOrgMap serverMap = extServerLesson.getExtServer();
ExtUserUseridMap extUserUseridMap = getExtUserUseridMapByUserId(serverMap, user.getUserId());
@@ -571,7 +587,7 @@
lessonFinishCallbackUrl = lessonFinishCallbackUrl.replaceAll("%username%", encodedExtUsername)
.replaceAll("%lessonid%", lessonId.toString()).replaceAll("%timestamp%", timestamp)
.replaceAll("%hash%", hash);
- log.debug(lessonFinishCallbackUrl);
+ IntegrationService.log.debug(lessonFinishCallbackUrl);
}
}
}
@@ -581,7 +597,7 @@
private ExtServerLessonMap getExtServerLessonMap(Long lessonId) {
List list = service.findByProperty(ExtServerLessonMap.class, "lessonId", lessonId);
- if (list == null || list.size() == 0) {
+ if ((list == null) || (list.size() == 0)) {
return null;
} else {
return (ExtServerLessonMap) list.get(0);
@@ -593,7 +609,7 @@
properties.put("extServerOrgMap.sid", serverMap.getSid());
properties.put("user.userId", userId);
List list = service.findByProperties(ExtUserUseridMap.class, properties);
- if (list == null || list.size() == 0) {
+ if ((list == null) || (list.size() == 0)) {
return null;
} else {
return (ExtUserUseridMap) list.get(0);
Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/User.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/usermanagement/User.java,v
diff -u -r1.50 -r1.50.2.1
--- lams_common/src/java/org/lamsfoundation/lams/usermanagement/User.java 3 Sep 2013 10:55:36 -0000 1.50
+++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/User.java 21 Oct 2015 11:44:55 -0000 1.50.2.1
@@ -50,10 +50,15 @@
private String login;
/**
- * persistent field ] TODO needs to be removed for security reason
+ * persistent field
*/
private String password;
+ /**
+ * persistent field
+ */
+ private String salt;
+
/** nullable persistent field */
private String title;
@@ -198,10 +203,18 @@
return password;
}
+ public String getSalt() {
+ return salt;
+ }
+
public void setPassword(String password) {
this.password = password;
}
+ public void setSalt(String salt) {
+ this.salt = salt;
+ }
+
public String getTitle() {
return title;
}
@@ -485,7 +498,7 @@
// TimeZone.getTimeZone("Australia/Sydney"),
timeZone, authenticationMethod.getAuthenticationMethodId(), fckLanguageMapping, lamsCommunityToken,
lamsCommunityUsername, (tutorialsDisabled == null ? false : true), // assume tutorials enabled if not
- // set
+ // set
tutorialPages, (firstLogin == null ? true : false) // assume no firstLogin value means they haven't
// logged in
);
Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/LdapService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/LdapService.java,v
diff -u -r1.22 -r1.22.2.1
--- lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/LdapService.java 3 Sep 2013 10:55:36 -0000 1.22
+++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/LdapService.java 21 Oct 2015 11:44:54 -0000 1.22.2.1
@@ -82,6 +82,7 @@
this.service = service;
}
+ @Override
public void updateLDAPUser(User user, Attributes attrs) {
HashMap map = getLDAPUserAttributes(attrs);
user.setLogin(map.get("login"));
@@ -107,7 +108,7 @@
// tries to match ldap attribute to a locale, otherwise returns server
// default
private SupportedLocale getLocale(String attribute) {
- if (attribute != null && attribute.trim().length() > 0) {
+ if ((attribute != null) && (attribute.trim().length() > 0)) {
int index = attribute.indexOf("_");
if (index > 0) {
String language = attribute.substring(0, index);
@@ -120,11 +121,12 @@
return LanguageUtil.getDefaultLocale();
}
+ @Override
public boolean createLDAPUser(Attributes attrs) {
User user = new User();
try {
HashMap map = getLDAPUserAttributes(attrs);
- if (map.get("login") != null && map.get("login").trim().length() > 0) {
+ if ((map.get("login") != null) && (map.get("login").trim().length() > 0)) {
if (log.isDebugEnabled()) {
log.debug("===> using LDAP attributes: " + map.get("login") + "," + map.get("fname") + ","
+ map.get("lname") + "," + map.get("email") + "," + map.get("address1") + ","
@@ -134,7 +136,9 @@
+ map.get("mobile") + "," + map.get("locale"));
}
user.setLogin(map.get("login"));
- user.setPassword(HashUtil.sha1(RandomPasswordGenerator.nextPassword(10)));
+ String salt = HashUtil.salt();
+ user.setSalt(salt);
+ user.setPassword(HashUtil.sha256(RandomPasswordGenerator.nextPassword(10), salt));
user.setFirstName(map.get("fname"));
user.setLastName(map.get("lname"));
user.setEmail(map.get("email"));
@@ -149,8 +153,8 @@
user.setEveningPhone(map.get("eveningphone"));
user.setFax(map.get("fax"));
user.setMobilePhone(map.get("mobile"));
- user.setAuthenticationMethod((AuthenticationMethod) service.findById(AuthenticationMethod.class,
- AuthenticationMethod.LDAP));
+ user.setAuthenticationMethod(
+ (AuthenticationMethod) service.findById(AuthenticationMethod.class, AuthenticationMethod.LDAP));
user.setFlashTheme(service.getDefaultFlashTheme());
user.setHtmlTheme(service.getDefaultHtmlTheme());
user.setDisabledFlag(getDisabledBoolean(attrs));
@@ -175,88 +179,89 @@
HashMap map = new HashMap();
try {
map.put("login", getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_LOGIN_ATTR))));
- map.put("fname", getSingleAttributeString(attrs.get(Configuration
- .get(ConfigurationKeys.LDAP_FIRST_NAME_ATTR))));
- map.put("lname", getSingleAttributeString(attrs.get(Configuration
- .get(ConfigurationKeys.LDAP_LAST_NAME_ATTR))));
+ map.put("fname",
+ getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_FIRST_NAME_ATTR))));
+ map.put("lname",
+ getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_LAST_NAME_ATTR))));
map.put("email", getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_EMAIL_ATTR))));
- map.put("address1", getSingleAttributeString(attrs
- .get(Configuration.get(ConfigurationKeys.LDAP_ADDR1_ATTR))));
- map.put("address2", getSingleAttributeString(attrs
- .get(Configuration.get(ConfigurationKeys.LDAP_ADDR2_ATTR))));
- map.put("address3", getSingleAttributeString(attrs
- .get(Configuration.get(ConfigurationKeys.LDAP_ADDR3_ATTR))));
+ map.put("address1",
+ getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_ADDR1_ATTR))));
+ map.put("address2",
+ getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_ADDR2_ATTR))));
+ map.put("address3",
+ getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_ADDR3_ATTR))));
map.put("city", getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_CITY_ATTR))));
map.put("state", getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_STATE_ATTR))));
- map.put("postcode", getSingleAttributeString(attrs.get(Configuration
- .get(ConfigurationKeys.LDAP_POSTCODE_ATTR))));
- map.put("country", getSingleAttributeString(attrs.get(Configuration
- .get(ConfigurationKeys.LDAP_COUNTRY_ATTR))));
- map.put("dayphone", getSingleAttributeString(attrs.get(Configuration
- .get(ConfigurationKeys.LDAP_DAY_PHONE_ATTR))));
- map.put("eveningphone", getSingleAttributeString(attrs.get(Configuration
- .get(ConfigurationKeys.LDAP_EVENING_PHONE_ATTR))));
+ map.put("postcode",
+ getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_POSTCODE_ATTR))));
+ map.put("country",
+ getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_COUNTRY_ATTR))));
+ map.put("dayphone",
+ getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_DAY_PHONE_ATTR))));
+ map.put("eveningphone",
+ getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_EVENING_PHONE_ATTR))));
map.put("fax", getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_FAX_ATTR))));
map.put("mobile",
getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_MOBILE_ATTR))));
map.put("locale",
getSingleAttributeString(attrs.get(Configuration.get(ConfigurationKeys.LDAP_LOCALE_ATTR))));
- map.put("disabled", getSingleAttributeString(attrs.get(getLdapAttr(Configuration
- .get(ConfigurationKeys.LDAP_DISABLED_ATTR)))));
+ map.put("disabled", getSingleAttributeString(
+ attrs.get(getLdapAttr(Configuration.get(ConfigurationKeys.LDAP_DISABLED_ATTR)))));
} catch (Exception e) {
log.error("===> Exception occurred while getting LDAP user attributes: ", e);
}
// field validation; trim values before they get to database
- if (map.get("login") != null && map.get("login").trim().length() > 255) {
+ if ((map.get("login") != null) && (map.get("login").trim().length() > 255)) {
map.put("login", map.get("login").substring(0, 255));
}
- if (map.get("fname") != null && map.get("fname").trim().length() > 128) {
+ if ((map.get("fname") != null) && (map.get("fname").trim().length() > 128)) {
map.put("fname", map.get("fname").substring(0, 128));
}
- if (map.get("lname") != null && map.get("lname").trim().length() > 128) {
+ if ((map.get("lname") != null) && (map.get("lname").trim().length() > 128)) {
map.put("lname", map.get("lname").substring(0, 128));
}
- if (map.get("email") != null && map.get("email").trim().length() > 128) {
+ if ((map.get("email") != null) && (map.get("email").trim().length() > 128)) {
map.put("email", map.get("email").substring(0, 128));
}
- if (map.get("address1") != null && map.get("address1").trim().length() > 64) {
+ if ((map.get("address1") != null) && (map.get("address1").trim().length() > 64)) {
map.put("address1", map.get("address1").substring(0, 64));
}
- if (map.get("address2") != null && map.get("address2").trim().length() > 64) {
+ if ((map.get("address2") != null) && (map.get("address2").trim().length() > 64)) {
map.put("address2", map.get("address2").substring(0, 64));
}
- if (map.get("address3") != null && map.get("address3").trim().length() > 64) {
+ if ((map.get("address3") != null) && (map.get("address3").trim().length() > 64)) {
map.put("address3", map.get("address3").substring(0, 64));
}
- if (map.get("city") != null && map.get("city").trim().length() > 64) {
+ if ((map.get("city") != null) && (map.get("city").trim().length() > 64)) {
map.put("city", map.get("city").substring(0, 64));
}
- if (map.get("state") != null && map.get("state").trim().length() > 64) {
+ if ((map.get("state") != null) && (map.get("state").trim().length() > 64)) {
map.put("state", map.get("state").substring(0, 64));
}
- if (map.get("postcode") != null && map.get("postcode").trim().length() > 10) {
+ if ((map.get("postcode") != null) && (map.get("postcode").trim().length() > 10)) {
map.put("postcode", map.get("postcode").substring(0, 10));
}
- if (map.get("country") != null && map.get("country").trim().length() > 64) {
+ if ((map.get("country") != null) && (map.get("country").trim().length() > 64)) {
map.put("country", map.get("country").substring(0, 64));
}
- if (map.get("dayphone") != null && map.get("dayphone").trim().length() > 64) {
+ if ((map.get("dayphone") != null) && (map.get("dayphone").trim().length() > 64)) {
map.put("dayphone", map.get("dayphone").substring(0, 64));
}
- if (map.get("eveningphone") != null && map.get("eveningphone").trim().length() > 64) {
+ if ((map.get("eveningphone") != null) && (map.get("eveningphone").trim().length() > 64)) {
map.put("eveningphone", map.get("eveningphone").substring(0, 64));
}
- if (map.get("fax") != null && map.get("fax").trim().length() > 64) {
+ if ((map.get("fax") != null) && (map.get("fax").trim().length() > 64)) {
map.put("fax", map.get("fax").substring(0, 64));
}
- if (map.get("mobile") != null && map.get("mobile").trim().length() > 64) {
+ if ((map.get("mobile") != null) && (map.get("mobile").trim().length() > 64)) {
map.put("mobile", map.get("mobile").substring(0, 64));
}
return map;
}
+ @Override
public String getLdapAttr(String ldapAttr) {
if (ldapAttr != null) {
return (ldapAttr.startsWith("!") ? ldapAttr.substring(1) : ldapAttr);
@@ -277,6 +282,7 @@
return null;
}
+ @Override
public boolean getDisabledBoolean(Attributes attrs) {
String ldapDisabledAttrStr = Configuration.get(ConfigurationKeys.LDAP_DISABLED_ATTR);
if (ldapDisabledAttrStr.startsWith("!")) {
@@ -295,6 +301,7 @@
}
+ @Override
public boolean addLDAPUser(Attributes attrs, Integer userId) {
User user = (User) service.findById(User.class, userId);
// get ldap attributes for lams org and roles
@@ -305,51 +312,51 @@
String orgField = Configuration.get(ConfigurationKeys.LDAP_ORG_FIELD);
boolean isAddingUserSuccessful = true;
- if (ldapOrgs != null && ldapRoles != null && orgField != null) {
+ if ((ldapOrgs != null) && (ldapRoles != null) && (orgField != null)) {
// get list of possible matching organisations
- for (String ldapOrg : ldapOrgs) {
- log.debug("Looking for organisation to add ldap user to...");
- List orgList = (List) service.findByProperty(Organisation.class, orgField, ldapOrg);
- if (orgList != null && !orgList.isEmpty()) {
- Organisation org = null;
+ for (String ldapOrg : ldapOrgs) {
+ log.debug("Looking for organisation to add ldap user to...");
+ List orgList = service.findByProperty(Organisation.class, orgField, ldapOrg);
+ if ((orgList != null) && !orgList.isEmpty()) {
+ Organisation org = null;
+ if (orgList.size() == 1) {
+ org = (Organisation) orgList.get(0);
+ } else if (orgList.size() > 1) {
+ // if there are multiple orgs, select the one that is
+ // active, if there is one
+ HashMap properties = new HashMap();
+ properties.put(orgField, ldapOrg);
+ properties.put("organisationState.organisationStateId", OrganisationState.ACTIVE);
+ orgList = service.findByProperties(Organisation.class, properties);
if (orgList.size() == 1) {
org = (Organisation) orgList.get(0);
- } else if (orgList.size() > 1) {
- // if there are multiple orgs, select the one that is
- // active, if there is one
- HashMap properties = new HashMap();
- properties.put(orgField, ldapOrg);
- properties.put("organisationState.organisationStateId", OrganisationState.ACTIVE);
- orgList = (List) service.findByProperties(Organisation.class, properties);
- if (orgList.size() == 1) {
- org = (Organisation) orgList.get(0);
- } else {
- log.warn("More than one LAMS organisation found with the " + orgField + ": " + ldapOrg);
- isAddingUserSuccessful = false;
- break;
- }
- }
-
- // now convert the roles to lams roles and add the user to the org
- List roleIds = getRoleIds(ldapRoles);
- if (roleIds != null && !roleIds.isEmpty()) {
- service.setRolesForUserOrganisation(user, org.getOrganisationId(), roleIds);
} else {
- log.warn("Couldn't map any roles from attribute: "
- + Configuration.get(ConfigurationKeys.LDAP_ROLES_ATTR));
+ log.warn("More than one LAMS organisation found with the " + orgField + ": " + ldapOrg);
isAddingUserSuccessful = false;
- }
-
- // if the user is a member of any other groups, remove them
- if (Configuration.getAsBoolean(ConfigurationKeys.LDAP_ONLY_ONE_ORG)) {
- service.removeUserFromOtherGroups(userId, org.getOrganisationId());
break;
- }
+ }
+ }
+
+ // now convert the roles to lams roles and add the user to the org
+ List roleIds = getRoleIds(ldapRoles);
+ if ((roleIds != null) && !roleIds.isEmpty()) {
+ service.setRolesForUserOrganisation(user, org.getOrganisationId(), roleIds);
} else {
- log.warn("No LAMS organisations found with the " + orgField + ": " + ldapOrg);
+ log.warn("Couldn't map any roles from attribute: "
+ + Configuration.get(ConfigurationKeys.LDAP_ROLES_ATTR));
isAddingUserSuccessful = false;
}
+
+ // if the user is a member of any other groups, remove them
+ if (Configuration.getAsBoolean(ConfigurationKeys.LDAP_ONLY_ONE_ORG)) {
+ service.removeUserFromOtherGroups(userId, org.getOrganisationId());
+ break;
+ }
+ } else {
+ log.warn("No LAMS organisations found with the " + orgField + ": " + ldapOrg);
+ isAddingUserSuccessful = false;
}
+ }
}
return isAddingUserSuccessful;
}
@@ -386,7 +393,7 @@
}
private boolean isRoleInList(String list, String role) {
- if (list != null && role != null) {
+ if ((list != null) && (role != null)) {
String[] array = list.split(";");
for (String s : array) {
if (role.contains(s)) {
@@ -418,6 +425,7 @@
}
// get the single (string) value of an ldap attribute
+ @Override
public String getSingleAttributeString(Attribute attr) {
try {
if (attr != null) {
@@ -432,12 +440,13 @@
return null;
}
+ @Override
public BulkUpdateResultDTO bulkUpdate() {
// setup ldap context
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
- env.setProperty(Context.SECURITY_AUTHENTICATION, Configuration
- .get(ConfigurationKeys.LDAP_SECURITY_AUTHENTICATION));
+ env.setProperty(Context.SECURITY_AUTHENTICATION,
+ Configuration.get(ConfigurationKeys.LDAP_SECURITY_AUTHENTICATION));
// make java ldap provider return 10 results at a time instead of
// default 1
env.setProperty(Context.BATCHSIZE, "10");
@@ -446,7 +455,7 @@
if (StringUtils.equals("ssl", securityProtocol)) {
env.setProperty(Context.SECURITY_PROTOCOL, securityProtocol);
}
-
+
// setup initial bind user credentials if configured
if (StringUtils.isNotBlank(Configuration.get(ConfigurationKeys.LDAP_BIND_USER_DN))) {
env.setProperty(Context.SECURITY_PRINCIPAL, Configuration.get(ConfigurationKeys.LDAP_BIND_USER_DN));
@@ -504,48 +513,49 @@
NamingEnumeration results = ctx.search(baseDN, filter, ctrl);
while (results.hasMore()) {
try {
- SearchResult result = results.next();
- Attributes attrs = result.getAttributes();
+ SearchResult result = results.next();
+ Attributes attrs = result.getAttributes();
- // add or update this user to LAMS
- boolean disabled = getDisabledBoolean(attrs);
- String login = getSingleAttributeString(attrs.get(Configuration
- .get(ConfigurationKeys.LDAP_LOGIN_ATTR)));
- if (login != null && login.trim().length() > 0) {
- int code = bulkUpdateLDAPUser(login, attrs, disabled);
- switch (code) {
- case BULK_UPDATE_CREATED:
- createdUsers++;
- break;
- case BULK_UPDATE_UPDATED:
- updatedUsers++;
- break;
- case BULK_UPDATE_DISABLED:
- disabledUsers++;
- break;
- }
- } else {
- log.error("Couldn't find login attribute for user using attribute name: "
- + Configuration.get(ConfigurationKeys.LDAP_LOGIN_ATTR)
- + ". Dumping attributes...");
- NamingEnumeration enumAttrs = attrs.getAll();
- while (enumAttrs.hasMoreElements()) {
- log.error(enumAttrs.next());
- }
- }
- } catch (Exception e) {
- // continue processing
- messages.add("Error processing context result number " + contextResults + ": " + e.getMessage());
- }
+ // add or update this user to LAMS
+ boolean disabled = getDisabledBoolean(attrs);
+ String login = getSingleAttributeString(
+ attrs.get(Configuration.get(ConfigurationKeys.LDAP_LOGIN_ATTR)));
+ if ((login != null) && (login.trim().length() > 0)) {
+ int code = bulkUpdateLDAPUser(login, attrs, disabled);
+ switch (code) {
+ case BULK_UPDATE_CREATED:
+ createdUsers++;
+ break;
+ case BULK_UPDATE_UPDATED:
+ updatedUsers++;
+ break;
+ case BULK_UPDATE_DISABLED:
+ disabledUsers++;
+ break;
+ }
+ } else {
+ log.error("Couldn't find login attribute for user using attribute name: "
+ + Configuration.get(ConfigurationKeys.LDAP_LOGIN_ATTR)
+ + ". Dumping attributes...");
+ NamingEnumeration enumAttrs = attrs.getAll();
+ while (enumAttrs.hasMoreElements()) {
+ log.error(enumAttrs.next());
+ }
+ }
+ } catch (Exception e) {
+ // continue processing
+ messages.add(
+ "Error processing context result number " + contextResults + ": " + e.getMessage());
+ }
contextResults++;
}
cookie = getPagedResponseCookie(ctx.getResponseControls());
// set response cookie to continue paged result
- ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, cookie,
- Control.NONCRITICAL) });
+ ctx.setRequestControls(
+ new Control[] { new PagedResultsControl(pageSize, cookie, Control.NONCRITICAL) });
} while (cookie != null);
log.info("Ldap context " + baseDN + " returned " + contextResults + " users.");
ctx.close();
@@ -580,13 +590,13 @@
log.info("Creating new user for LDAP username: " + login);
if (createLDAPUser(attrs)) {
user = getService().getUserByLogin(login);
- returnCode = BULK_UPDATE_CREATED;
+ returnCode = LdapService.BULK_UPDATE_CREATED;
} else {
log.error("Couldn't create new user for LDAP username: " + login);
}
} else {
updateLDAPUser(user, attrs);
- returnCode = BULK_UPDATE_UPDATED;
+ returnCode = LdapService.BULK_UPDATE_UPDATED;
}
if (!addLDAPUser(attrs, user.getUserId())) {
log.error("Couldn't add LDAP user: " + login + " to organisation.");
@@ -595,7 +605,7 @@
// remove user from groups and set disabled flag
if (user != null) {
getService().disableUser(user.getUserId());
- returnCode = BULK_UPDATE_DISABLED;
+ returnCode = LdapService.BULK_UPDATE_DISABLED;
}
}
return returnCode;
Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java,v
diff -u -r1.115.2.5 -r1.115.2.6
--- lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java 5 Oct 2015 18:03:00 -0000 1.115.2.5
+++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java 21 Oct 2015 11:44:54 -0000 1.115.2.6
@@ -109,8 +109,8 @@
private IAuditService getAuditService() {
if (UserManagementService.auditService == null) {
- WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(SessionManager
- .getServletContext());
+ WebApplicationContext ctx = WebApplicationContextUtils
+ .getWebApplicationContext(SessionManager.getServletContext());
UserManagementService.auditService = (IAuditService) ctx.getBean("auditService");
}
return UserManagementService.auditService;
@@ -356,7 +356,8 @@
// now, process any children of this org
Organisation childOrganisation = userOrganisation.getOrganisation();
if (org.getChildOrganisations().size() > 0) {
- getChildOrganisations(user, childOrganisation, restrictToRoleNames, restrictToClassIds, dtolist);
+ getChildOrganisations(user, childOrganisation, restrictToRoleNames, restrictToClassIds,
+ dtolist);
}
}
}
@@ -395,8 +396,8 @@
Map map = new HashMap();
map.put("user.userId", user.getUserId());
map.put("organisation.organisationId", organisationId);
- UserOrganisation userOrganisation = (UserOrganisation) baseDAO
- .findByProperties(UserOrganisation.class, map).get(0);
+ UserOrganisation userOrganisation = (UserOrganisation) baseDAO.findByProperties(UserOrganisation.class, map)
+ .get(0);
OrganisationDTO dto = userOrganisation.getOrganisation().getOrganisationDTO();
addRolesToDTO(null, userOrganisation, dto);
return dto;
@@ -445,8 +446,8 @@
// it's ugly to put query string here, but it is a convention of this class so let's stick to it for now
String query = "SELECT uo.user FROM UserOrganisation uo INNER JOIN uo.userOrganisationRoles r WHERE uo.organisation.organisationId="
+ organisationID + " AND r.role.name= '" + roleName + "'";
- List queryResult = (List) baseDAO.find(query);
-
+ List queryResult = baseDAO.find(query);
+
for (User user : queryResult) {
if (isFlashCall && !getUser) {
users.add(user.getUserFlashDTO());
@@ -456,14 +457,15 @@
users.add(user.getUserDTO());
}
}
-
+
return users;
}
@Override
public Organisation getRootOrganisation() {
- return (Organisation) baseDAO.findByProperty(Organisation.class, "organisationType.organisationTypeId",
- OrganisationType.ROOT_TYPE).get(0);
+ return (Organisation) baseDAO
+ .findByProperty(Organisation.class, "organisationType.organisationTypeId", OrganisationType.ROOT_TYPE)
+ .get(0);
}
@Override
@@ -537,7 +539,9 @@
public void updatePassword(String login, String password) {
try {
User user = getUserByLogin(login);
- user.setPassword(HashUtil.sha1(password));
+ String salt = HashUtil.salt();
+ user.setSalt(salt);
+ user.setPassword(HashUtil.sha256(password, salt));
baseDAO.update(user);
} catch (Exception e) {
log.debug(e);
@@ -628,8 +632,8 @@
User user = (User) findById(User.class, m.getUserID());
UserOrganisation uo = new UserOrganisation(user, organisation);
log.debug("adding course manager: " + user.getUserId() + " as staff");
- UserOrganisationRole uor = new UserOrganisationRole(uo, (Role) findById(Role.class,
- Role.ROLE_MONITOR));
+ UserOrganisationRole uor = new UserOrganisationRole(uo,
+ (Role) findById(Role.class, Role.ROLE_MONITOR));
HashSet uors = new HashSet();
uors.add(uor);
uo.setUserOrganisationRoles(uors);
Index: lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java,v
diff -u -r1.53.2.2 -r1.53.2.3
--- lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java 4 May 2015 09:19:10 -0000 1.53.2.2
+++ lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java 21 Oct 2015 11:44:54 -0000 1.53.2.3
@@ -47,7 +47,7 @@
public static String LAMS_EAR_DIR = "EARDir";
public static String SMTP_SERVER = "SMTPServer";
-
+
public static String USE_INTERNAL_SMTP_SERVER = "InternalSMTPServer";
public static String LAMS_ADMIN_EMAIL = "LamsSupportEmail";
@@ -128,7 +128,7 @@
public static String LAMS_COMMUNITY_ENABLE = "LAMS_Community_enable";
public static String ALLOW_EDIT_ON_FLY = "AllowLiveEdit";
-
+
public static String SHOW_ALL_MY_LESSON_LINK = "ShowAllMyLessonLink";
public static String LDAP_PROVISIONING_ENABLED = "LDAPProvisioningEnabled";
@@ -140,9 +140,9 @@
public static String LDAP_SEARCH_FILTER = "LDAPSearchFilter";
public static String LDAP_BASE_DN = "LDAPBaseDN";
-
+
public static String LDAP_BIND_USER_DN = "LDAPBindUserDN";
-
+
public static String LDAP_BIND_USER_PASSWORD = "LDAPBindUserPassword";
public static String LDAP_SECURITY_PROTOCOL = "LDAPSecurityProtocol";
@@ -205,8 +205,6 @@
public static String LDAP_ONLY_ONE_ORG = "LDAPOnlyOneOrg";
- public static String LDAP_ENCRYPT_PASSWORD_FROM_BROWSER = "LDAPEncryptPasswordFromBrowser";
-
public static String LDAP_SEARCH_RESULTS_PAGE_SIZE = "LDAPSearchResultsPageSize";
/**
@@ -231,17 +229,17 @@
public static String ADMIN_SCREEN_SIZE = "AdminScreenSize";
public static String GMAP_KEY = "GmapKey";
-
+
public static String RED5_SERVER_URL = "Red5ServerUrl";
-
+
public static String RED5_RECORDINGS_URL = "Red5RecordingsUrl";
-
+
public static String SMTP_AUTH_USER = "SMTPUser";
-
+
public static String SMTP_AUTH_PASSWORD = "SMTPPassword";
-
+
public static String PROFILE_EDIT_ENABLE = "ProfileEditEnable";
-
+
public static String PROFILE_PARTIAL_EDIT_ENABLE = "ProfilePartialEditEnable";
public static String KALTURA_SERVER = "KalturaServer";
@@ -253,25 +251,25 @@
public static String KALTURA_USER_SECRET = "KalturaUserSecret";
public static String KALTURA_KCW_UI_CONF_ID = "KalturaKCWUiConfId";
-
+
public static String KALTURA_KDP_UI_CONF_ID = "KalturaKDPUiConfId";
-
+
public static String USER_VALIDATION_REQUIRED_USERNAME = "UserValidationUsername";
-
+
public static String USER_VALIDATION_REQUIRED_FIRST_LAST_NAME = "UserValidationFirstLastName";
-
+
public static String USER_VALIDATION_REQUIRED_EMAIL = "UserValidationEmail";
// LDEV-2747
public static String ENABLE_SERVER_REGISTRATION = "EnableServerRegistration";
-
+
// LDEV-2889
public static String LEARNER_COLLAPSIBLE_PROGRESS_PANEL = "LearnerCollapsProgressPanel";
-
+
// CNG-26 Add to lams_configuration and set to false
// if you don't want imported LD to have __ appended
public static String SUFFIX_IMPORTED_LD = "SuffixImportedLD";
-
+
// LDEV-3254
public static String CONFIGURATION_CACHE_REFRESH_INTERVAL = "ConfigCacheRefresInterval";
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/util/HashUtil.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/util/HashUtil.java,v
diff -u -r1.3 -r1.3.24.1
--- lams_common/src/java/org/lamsfoundation/lams/util/HashUtil.java 20 Sep 2006 02:41:57 -0000 1.3
+++ lams_common/src/java/org/lamsfoundation/lams/util/HashUtil.java 21 Oct 2015 11:44:54 -0000 1.3.24.1
@@ -24,38 +24,68 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
import org.apache.commons.codec.binary.Hex;
/**
- * @version
- *
- *