Try to save passwords user_management
authorymh <ymh.work@gmail.com>
Wed, 23 Oct 2013 01:43:09 +0200
branchuser_management
changeset 226 d2b688aadd8c
parent 225 0fcce86e650c
child 227 0877747b0213
Try to save passwords
server/src/main/java/org/iri_research/renkan/controller/admin/AbstractRenkanObjectAdminController.java
server/src/main/java/org/iri_research/renkan/forms/UserForm.java
server/src/main/java/org/iri_research/renkan/forms/UserFormValidator.java
server/src/main/java/org/iri_research/renkan/models/User.java
server/src/main/webapp/WEB-INF/i18n/messages.properties
server/src/main/webapp/WEB-INF/i18n/messages_en.properties
server/src/main/webapp/WEB-INF/i18n/messages_fr.properties
server/src/main/webapp/WEB-INF/spring-security.xml
server/src/main/webapp/WEB-INF/templates/fragment/userForm.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/src/main/java/org/iri_research/renkan/controller/admin/AbstractRenkanObjectAdminController.java	Wed Oct 23 01:43:09 2013 +0200
@@ -0,0 +1,5 @@
+package org.iri_research.renkan.controller.admin;
+
+public abstract class AbstractRenkanObjectAdminController {
+
+}
--- a/server/src/main/java/org/iri_research/renkan/forms/UserForm.java	Tue Oct 22 17:54:30 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/forms/UserForm.java	Wed Oct 23 01:43:09 2013 +0200
@@ -100,6 +100,7 @@
         this.model.setExpirationDate(this.expirationDate);
         this.model.setEnabled(this.enabled);
         this.model.setLocked(this.locked);
+        this.model.setRawPassword(this.password);
 
     }
 
--- a/server/src/main/java/org/iri_research/renkan/forms/UserFormValidator.java	Tue Oct 22 17:54:30 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/forms/UserFormValidator.java	Wed Oct 23 01:43:09 2013 +0200
@@ -1,7 +1,5 @@
 package org.iri_research.renkan.forms;
 
-import java.io.IOException;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -9,9 +7,6 @@
 import org.springframework.validation.ValidationUtils;
 import org.springframework.validation.Validator;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
 @Component
 public class UserFormValidator implements Validator {
 
--- a/server/src/main/java/org/iri_research/renkan/models/User.java	Tue Oct 22 17:54:30 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/models/User.java	Wed Oct 23 01:43:09 2013 +0200
@@ -3,10 +3,13 @@
 import java.util.Collection;
 import java.util.Date;
 
+import javax.annotation.Resource;
+
 import org.springframework.data.mongodb.core.mapping.Document;
 import org.springframework.data.mongodb.core.mapping.Field;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.crypto.password.PasswordEncoder;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -15,6 +18,10 @@
 public class User extends AbstractRenkanModel<String> implements UserDetails {
 
     private static final long serialVersionUID = 6972038893086220548L;
+    
+    
+    @Resource(name="renkanPasswordEncoder")
+    private PasswordEncoder passwordEncoder;
 
     private String avatar;
     @Field("credentials_expiration_date")
@@ -131,4 +138,8 @@
         return "";
     }
 
+    public void setRawPassword(String password) {
+        this.password = this.passwordEncoder.encode(password);
+    }
+
 }
--- a/server/src/main/webapp/WEB-INF/i18n/messages.properties	Tue Oct 22 17:54:30 2013 +0200
+++ b/server/src/main/webapp/WEB-INF/i18n/messages.properties	Wed Oct 23 01:43:09 2013 +0200
@@ -56,6 +56,7 @@
 renkanAdmin.object_delete_link = Del.
 
 renkanAdmin.form.title = Title
+renkanAdmin.form.name = Name
 renkanAdmin.form.uri = URI
 renkanAdmin.form.description = Description
 renkanAdmin.form.color = Color
@@ -71,6 +72,8 @@
 renkanAdmin.form.email = Email
 renkanAdmin.form.enabled = Enabled
 renkanAdmin.form.locked = Locked
+renkanAdmin.form.password = Password
+renkanAdmin.form.passwordConfirm = Confirm password
 renkanAdmin.form.user.submit = Ok
 
 renkan.error.title.empty = Title must not be empty or null
--- a/server/src/main/webapp/WEB-INF/i18n/messages_en.properties	Tue Oct 22 17:54:30 2013 +0200
+++ b/server/src/main/webapp/WEB-INF/i18n/messages_en.properties	Wed Oct 23 01:43:09 2013 +0200
@@ -58,6 +58,7 @@
 renkanAdmin.object_delete_link = Del.
 
 renkanAdmin.form.title = Title
+renkanAdmin.form.name = Name
 renkanAdmin.form.uri = URI
 renkanAdmin.form.description = Description
 renkanAdmin.form.color = Color
@@ -81,6 +82,8 @@
 renkanAdmin.form.email = Email
 renkanAdmin.form.enabled = Enabled
 renkanAdmin.form.locked = Locked
+renkanAdmin.form.password = Password
+renkanAdmin.form.passwordConfirm = Confirm password
 renkanAdmin.form.user.submit = Ok
 
 
--- a/server/src/main/webapp/WEB-INF/i18n/messages_fr.properties	Tue Oct 22 17:54:30 2013 +0200
+++ b/server/src/main/webapp/WEB-INF/i18n/messages_fr.properties	Wed Oct 23 01:43:09 2013 +0200
@@ -57,6 +57,7 @@
 renkanAdmin.object_delete_link = Eff.
 
 renkanAdmin.form.title = Titre
+renkanAdmin.form.name = Nom
 renkanAdmin.form.uri = URI
 renkanAdmin.form.description = Description
 renkanAdmin.form.color = Couleur
@@ -79,6 +80,9 @@
 renkanAdmin.form.email = Email
 renkanAdmin.form.enabled = Actif
 renkanAdmin.form.locked = Verrouillé
+renkanAdmin.form.password = Mot de passe
+renkanAdmin.form.passwordConfirm = Conf. mot de passe
+
 renkanAdmin.form.user.submit = Ok
 
 
--- a/server/src/main/webapp/WEB-INF/spring-security.xml	Tue Oct 22 17:54:30 2013 +0200
+++ b/server/src/main/webapp/WEB-INF/spring-security.xml	Wed Oct 23 01:43:09 2013 +0200
@@ -27,7 +27,11 @@
         <property name="location" value="#{propsLocations.classpathProps}"/>
         <property name="ignoreUnresolvablePlaceholders" value="true"/>
         <property name="IgnoreResourceNotFound" value="true"/>
-    </bean>    
+    </bean>
+    
+    <bean class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" id="renkanPasswordEncoder">
+        <constructor-arg name="strength" value="10" type="int"/>
+    </bean>
  
     <security:http auto-config="true" use-expressions="true">
         <security:intercept-url pattern="/admin" access="hasRole('ROLE_ADMIN')" />
--- a/server/src/main/webapp/WEB-INF/templates/fragment/userForm.html	Tue Oct 22 17:54:30 2013 +0200
+++ b/server/src/main/webapp/WEB-INF/templates/fragment/userForm.html	Wed Oct 23 01:43:09 2013 +0200
@@ -20,7 +20,7 @@
             }
 
             var password = $('#password').val();
-            var passwordConf = $('#passwordConf').val();
+            var passwordConf = $('#passwordConfirm').val();
             var objId = $('#id').val();
             
             if(objId && !password) {
@@ -59,7 +59,7 @@
      <fieldset class="form-fields">
        <input type="hidden" th:field="*{id}" th:if="*{id}" />
        <div>
-         <label for="title" th:text="#{renkanAdmin.form.title}">Title: </label> 
+         <label for="title" th:text="#{renkanAdmin.form.name}">Name: </label> 
          <input type="text" th:field="*{title}" />
          <div th:if="${#fields.hasErrors('title')}" th:errors="*{title}" class="form-error"></div>
        </div>