diff --git a/wise-webapp/pom.xml b/wise-webapp/pom.xml
index 33b1ca4e..079f7383 100644
--- a/wise-webapp/pom.xml
+++ b/wise-webapp/pom.xml
@@ -77,6 +77,12 @@
${org.springframework.version}
compile
+
+ org.springframework.security
+ spring-security-ldap
+ ${org.springframework.version}
+ compile
+
org.springframework
spring-beans
diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java b/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java
index 297735c2..bd636ea2 100644
--- a/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java
+++ b/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java
@@ -85,7 +85,7 @@ public class AdminController extends BaseController {
}
// Finally create the user ...
- userService.createUser(delegated, false);
+ userService.createUser(delegated, false,true);
response.setHeader("Location", "/service/admin/users/" + user.getId());
}
diff --git a/wise-webapp/src/main/java/com/wisemapping/security/UserDetails.java b/wise-webapp/src/main/java/com/wisemapping/security/UserDetails.java
index 30530ad7..2a7c5d15 100644
--- a/wise-webapp/src/main/java/com/wisemapping/security/UserDetails.java
+++ b/wise-webapp/src/main/java/com/wisemapping/security/UserDetails.java
@@ -27,10 +27,10 @@ import java.util.ArrayList;
import java.util.Collection;
public class UserDetails implements org.springframework.security.core.userdetails.UserDetails {
- private com.wisemapping.model.User user;
+ private com.wisemapping.model.User user;
private boolean isAdmin;
- public UserDetails(@NotNull final com.wisemapping.model.User user, boolean isAdmin) {
+ public UserDetails(@NotNull final com.wisemapping.model.User user, boolean isAdmin) {
this.user = user;
this.isAdmin = isAdmin;
}
diff --git a/wise-webapp/src/main/java/com/wisemapping/security/UserDetailsService.java b/wise-webapp/src/main/java/com/wisemapping/security/UserDetailsService.java
index 0c1f1ab4..390795b4 100644
--- a/wise-webapp/src/main/java/com/wisemapping/security/UserDetailsService.java
+++ b/wise-webapp/src/main/java/com/wisemapping/security/UserDetailsService.java
@@ -18,13 +18,12 @@
package com.wisemapping.security;
-import com.wisemapping.dao.UserManager;
+
import com.wisemapping.model.User;
import com.wisemapping.service.UserService;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
+
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@@ -37,7 +36,7 @@ public class UserDetailsService
@Override
public UserDetails loadUserByUsername(@NotNull String email) throws UsernameNotFoundException, DataAccessException {
final User user = userService.getUserBy(email);
-
+
if (user != null) {
return new UserDetails(user, isAdmin(email));
} else {
diff --git a/wise-webapp/src/main/java/com/wisemapping/security/ldap/LdapUserDetailsContextMapper.java b/wise-webapp/src/main/java/com/wisemapping/security/ldap/LdapUserDetailsContextMapper.java
new file mode 100644
index 00000000..8eb6dae6
--- /dev/null
+++ b/wise-webapp/src/main/java/com/wisemapping/security/ldap/LdapUserDetailsContextMapper.java
@@ -0,0 +1,79 @@
+package com.wisemapping.security.ldap;
+
+
+import com.wisemapping.exceptions.WiseMappingException;
+import com.wisemapping.model.User;
+import com.wisemapping.security.UserDetails;
+import com.wisemapping.service.UserService;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.springframework.ldap.core.DirContextAdapter;
+import org.springframework.ldap.core.DirContextOperations;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.ldap.userdetails.UserDetailsContextMapper;
+
+import java.util.Calendar;
+import java.util.Collection;
+
+public class LdapUserDetailsContextMapper implements UserDetailsContextMapper {
+
+ private UserService userService;
+ private String adminUser;
+
+
+ public UserService getUserService() {
+ return userService;
+ }
+
+ public void setUserService(UserService userService) {
+ this.userService = userService;
+ }
+
+
+ private boolean isAdmin(@Nullable String email) {
+ return email != null && adminUser != null && email.trim().endsWith(adminUser);
+ }
+
+ public String getAdminUser() {
+ return adminUser;
+ }
+
+ public void setAdminUser(String adminUser) {
+ this.adminUser = adminUser;
+ }
+
+ @Override
+ public UserDetails mapUserFromContext(@NotNull DirContextOperations userData,
+ String email, Collection extends GrantedAuthority> arg2) {
+ User user = userService.getUserBy(email);
+ if (user == null) {
+ // If the user was not found in the database, create a new one ...
+ user = new User();
+ user.setEmail(email);
+
+ final String firstName = userData.getStringAttribute("givenName");
+ user.setFirstname(firstName);
+
+ final String lastName = userData.getStringAttribute("sn");
+ user.setLastname(lastName);
+
+ user.setPassword(email);
+ final Calendar now = Calendar.getInstance();
+ user.setActivationDate(now);
+
+ try {
+ userService.createUser(user, false,false);
+ } catch (WiseMappingException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return new UserDetails(user, isAdmin(email));
+ }
+
+ @Override
+ public void mapUserToContext(org.springframework.security.core.userdetails.UserDetails userDetails, DirContextAdapter dirContextAdapter) {
+ // To be implemented ...
+ }
+
+
+}
diff --git a/wise-webapp/src/main/java/com/wisemapping/service/UserService.java b/wise-webapp/src/main/java/com/wisemapping/service/UserService.java
index 52d32752..fd9e0cd7 100755
--- a/wise-webapp/src/main/java/com/wisemapping/service/UserService.java
+++ b/wise-webapp/src/main/java/com/wisemapping/service/UserService.java
@@ -26,7 +26,7 @@ public interface UserService {
public void activateAccount(long code) throws InvalidActivationCodeException;
- public User createUser(@NotNull User user, boolean emailConfirmEnabled) throws WiseMappingException;
+ public User createUser(@NotNull User user, boolean emailConfirmEnabled,boolean welcomeEmail) throws WiseMappingException;
public void changePassword(@NotNull User user);
@@ -41,4 +41,6 @@ public interface UserService {
public void deleteUser(@NotNull User user);
public void auditLogin(@NotNull User user);
+
+ public User getCasUserBy(String uid);
}
diff --git a/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java
index 26344abd..e0849650 100755
--- a/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java
+++ b/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java
@@ -107,7 +107,7 @@ public class UserServiceImpl
userManager.auditLogin(accessAuditory);
}
- public User createUser(@NotNull User user, boolean emailConfirmEnabled) throws WiseMappingException {
+ public User createUser(@NotNull User user, boolean emailConfirmEnabled, boolean welcomeEmail) throws WiseMappingException {
final UUID uuid = UUID.randomUUID();
user.setCreationDate(Calendar.getInstance());
user.setActivationCode(uuid.getLeastSignificantBits());
@@ -120,6 +120,7 @@ public class UserServiceImpl
}
Collaborator col = userManager.getCollaboratorBy(user.getEmail());
+
if (col != null) {
userManager.createUser(user, col);
} else {
@@ -134,7 +135,7 @@ public class UserServiceImpl
// Send registration email.
if (emailConfirmEnabled) {
notificationService.sendRegistrationEmail(user);
- } else {
+ } else if (welcomeEmail) {
// Send a welcome email ..
notificationService.newAccountCreated(user);
}
@@ -205,4 +206,10 @@ public class UserServiceImpl
public void setVelocityEngine(VelocityEngine velocityEngine) {
this.velocityEngine = velocityEngine;
}
+
+ @Override
+ public User getCasUserBy(String uid) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
diff --git a/wise-webapp/src/main/java/com/wisemapping/webmvc/UsersController.java b/wise-webapp/src/main/java/com/wisemapping/webmvc/UsersController.java
index 9d33b0b7..9835f4b3 100644
--- a/wise-webapp/src/main/java/com/wisemapping/webmvc/UsersController.java
+++ b/wise-webapp/src/main/java/com/wisemapping/webmvc/UsersController.java
@@ -110,7 +110,7 @@ public class UsersController {
user.setPassword(userBean.getPassword());
boolean confirmRegistrationByEmail = false;
- userService.createUser(user, confirmRegistrationByEmail);
+ userService.createUser(user, confirmRegistrationByEmail,true);
// Forward to the success view ...
result = new ModelAndView("userRegistrationSuccess");
diff --git a/wise-webapp/src/main/webapp/WEB-INF/app.properties b/wise-webapp/src/main/webapp/WEB-INF/app.properties
index 963c6b30..76a47f6a 100755
--- a/wise-webapp/src/main/webapp/WEB-INF/app.properties
+++ b/wise-webapp/src/main/webapp/WEB-INF/app.properties
@@ -98,3 +98,25 @@ google.analytics.account=UA-XXXX
# Google Ads enable
##################################################################################
google.ads.enabled=false
+
+#######################################################################################
+LDAP Configuration Section
+#######################################################################################
+security.ldap.enabled=false
+security.ldap.server=ldap://localhost:389
+security.ldap.server.user=cn=pveiga,dc=wisemapping,dc=com
+security.ldap.server.password=password
+
+security.ldap.basedn=dc=wisemapping,dc=com
+security.ldap.subDn=people
+security.ldap.auth.attribute=mail
+#######################################################################################
+
+
+
+
+
+
+
+
+
diff --git a/wise-webapp/src/main/webapp/WEB-INF/web.xml b/wise-webapp/src/main/webapp/WEB-INF/web.xml
index 63bfab89..aba7687c 100644
--- a/wise-webapp/src/main/webapp/WEB-INF/web.xml
+++ b/wise-webapp/src/main/webapp/WEB-INF/web.xml
@@ -28,6 +28,7 @@
- The application context is then available via
- WebApplicationContextUtils.getWebApplicationContext(servletContext).
-->
+
com.wisemapping.service.HibernateAppListener
diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security-db.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security-db.xml
new file mode 100644
index 00000000..7319eca1
--- /dev/null
+++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security-db.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security-ldap.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security-ldap.xml
new file mode 100644
index 00000000..21cff647
--- /dev/null
+++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security-ldap.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml
index a33c9491..12ad85b1 100644
--- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml
+++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml
@@ -56,18 +56,10 @@
-
-
-
-
-
-
-
-
-
+
+
-
@@ -76,4 +68,5 @@
+
\ No newline at end of file