Changeset 279
- Timestamp:
- 12/02/11 14:11:54 (13 years ago)
- Location:
- ether_megapoli/trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
ether_megapoli/trunk/common/implementation/com/ether/EtherHelper.java
r218 r279 8 8 import java.io.FileWriter; 9 9 import java.io.IOException; 10 import java.security.DigestException; 11 import java.security.MessageDigest; 12 import java.security.NoSuchAlgorithmException; 10 13 import java.util.ArrayList; 11 14 import java.util.List; … … 138 141 } 139 142 143 144 /** 145 * Returns the specified String as an encrypted hash 146 * 147 * @param stringToEncrypt 148 * @return 149 */ 150 @NotNull 151 public static byte[] encryptStringToHash( @NotNull final String stringToEncrypt ) 152 throws DigestException, NoSuchAlgorithmException 153 { 154 final byte[] input = stringToEncrypt.getBytes(); 155 final MessageDigest digest = MessageDigest.getInstance( "SHA-1" ); 156 digest.update( input, 0, input.length ); 157 final int hashLength = 20; // SHA-1 donne un hash de longueur 20 158 final byte[] hash = new byte[hashLength]; 159 digest.digest( hash, 0, hashLength ); 160 return hash; 161 } 162 163 /** 164 * Returns the specified bytes array hash as a String 165 * 166 * @param encryptedHash the hash as a bytes array 167 * @return the hash as a String 168 */ 169 @NotNull 170 public static String displayEncryptedHash( @NotNull final byte[] encryptedHash ) 171 { 172 final StringBuilder stringBuilder = new StringBuilder(); 173 for( final byte aHash : encryptedHash ) 174 { 175 final int v = aHash & 0xFF; 176 if( v < 16 ) 177 stringBuilder.append( '0' ); 178 179 stringBuilder.append( Integer.toString( v, 16 ) ); 180 } 181 return stringBuilder.toString(); 182 } 183 184 /** 185 * This method creates a encrypted password with SHA-1 hash 186 * 187 * @param password 188 * @return 189 */ 190 @NotNull 191 public static String encryptPassword( @NotNull final String password ) 192 throws DigestException, NoSuchAlgorithmException 193 { 194 final byte[] sHAPassword = EtherHelper.encryptStringToHash( password ); 195 return EtherHelper.displayEncryptedHash( sHAPassword ); 196 } 197 140 198 } -
ether_megapoli/trunk/service/test/com/ether/OtherTest.java
r194 r279 4 4 import org.junit.Assert; 5 5 import org.junit.Test; 6 6 import sun.misc.BASE64Decoder; 7 import sun.misc.BASE64Encoder; 8 9 import java.io.IOException; 10 import java.security.DigestException; 11 import java.security.NoSuchAlgorithmException; 7 12 import java.text.DateFormat; 8 13 import java.text.SimpleDateFormat; … … 172 177 } 173 178 179 @Test 180 public void testEcnryptSHA1() 181 { 182 try 183 { 184 final String password = "boum"; 185 final byte[] sHAPassword = EtherHelper.encryptStringToHash( password ); 186 final String rePassword = EtherHelper.displayEncryptedHash( sHAPassword ); 187 188 final BASE64Decoder decoder = new BASE64Decoder(); 189 final byte[] base64Password = decoder.decodeBuffer( password ); 190 191 final BASE64Encoder endecoder = new BASE64Encoder(); 192 final String base64DecodedPassword = endecoder.encode( base64Password ); 193 194 final String tot = "tit"; 195 } 196 catch( DigestException e ) 197 { 198 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 199 } 200 catch( NoSuchAlgorithmException e ) 201 { 202 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 203 } 204 catch( IOException e ) 205 { 206 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 207 } 208 } 174 209 } -
ether_megapoli/trunk/web/resources/jsp/dataProtocol_en.jsp
r278 r279 9 9 10 10 <BR/> 11 < button onclick="javascript:onClickDownloadDataProtocol()" class="dataProtocolDownloadButton">Download</button>11 <a href="SendFileToClient.do?path=dataProtocol_en.pdf"><button class="dataProtocolDownloadButton">Download</button></a> 12 12 13 13 <BR/><BR/> 14 14 <hr width="50%"> 15 15 16 <div class="title1">Ask for a ccount</div>16 <div class="title1">Ask for an account</div> 17 17 <BR/> 18 18 … … 31 31 </tr> 32 32 <tr> 33 <td><label for="password">Password</label></td> 34 <td><input id="password" name="password" type="text" size="30"></td> 35 </tr> 36 <tr> 33 37 <td> 34 38 <input id="checkboxUser" type="checkbox" class="dataProtocolCheckbox"> -
ether_megapoli/trunk/web/resources/jsp/dataProtocol_fr.jsp
r278 r279 9 9 10 10 <BR/> 11 <button class="dataProtocolDownloadButton"><a href="/SendFileToClient.do?path=dataProtocol.pdf">Téléchargement</a></button> 12 <a href="SendFileToClient.do?path=dataProtocol_fr.pdf">Téléchargement</a> 11 <a href="SendFileToClient.do?path=dataProtocol_fr.pdf"><button class="dataProtocolDownloadButton">Téléchargement</button></a> 13 12 14 13 <BR/><BR/> … … 32 31 </tr> 33 32 <tr> 33 <td><label for="password">Mot de passe</label></td> 34 <td><input id="password" name="password" type="text" size="30"></td> 35 </tr> 36 <tr> 34 37 <td> 35 38 <input id="checkboxUser" type="checkbox" class="dataProtocolCheckbox"> -
ether_megapoli/trunk/web/resources/jsp/megapoliHead.jsp
r278 r279 174 174 /** *********** ACCOUNT *********** **/ 175 175 /** ******************************* **/ 176 function onClickDownloadDataProtocol()177 {178 alert( "downLoad" );179 }180 181 176 function onClickAcceptDataProtocol() 182 177 { 183 if( '' == $( "#lastName" ).val() || '' == $( "#email" ).val() )178 if( '' == $( "#lastName" ).val() || '' == $( "#email" ).val() || '' == $( "#password" ).val() ) 184 179 { 185 180 showErrorAccount( null, templateTexts["app.dataProtocolFields"] ); … … 195 190 function createAccount() 196 191 { 197 var parametersUrl = "name=" + $( "#lastName" ).val() + "&firstName=" + $( "#firstName" ).val() + "&email=" + $( "#email" ).val() ;192 var parametersUrl = "name=" + $( "#lastName" ).val() + "&firstName=" + $( "#firstName" ).val() + "&email=" + $( "#email" ).val() + "&pwd=" + $( "#password" ).val(); 198 193 var request = $.ajax( { 199 194 url: "project?methodName=createAccount&" + parametersUrl, -
ether_megapoli/trunk/web/src/ApplicationResources.properties
r278 r279 443 443 app.infos=Informations 444 444 app.dataProtocolAccept=Vous devez accepter le protocole d'utilisation des donn\u00E9es pour demander un compte 445 app.dataProtocolFields=Les champs 'Nom' et 'Email' sont incomplets445 app.dataProtocolFields=Les champs 'Nom', 'Email' et 'Mot de passe' sont incomplets 446 446 app.dataProtocol.account=Votre compte est en attente de validation par l'administrateur. Vous recevrez un email lors de son activation. 447 447 app.dataProtocol.alreadyExist=Cette email est d\u00E9j\u00E0 utilis\u00E9 par un compte, veuillez en fournir un autre. -
ether_megapoli/trunk/web/src/ApplicationResources_en.properties
r278 r279 442 442 app.infos=Informations 443 443 app.dataProtocolAccept=You have to accept the data protocol to ask for an account 444 app.dataProtocolFields=Fields 'LastName' and 'Email' must be filled444 app.dataProtocolFields=Fields 'LastName', 'Email' and 'Password' must be filled 445 445 app.dataProtocol.account=Your account is waiting for administrator validation. You will receive an email when it will be activated. 446 446 app.dataProtocol.alreadyExist=This email is already used, you have to give another one … … 535 535 bo.user.email=Email 536 536 bo.user.password=Password 537 bo.user.password.same=Keep same password 538 bo.user.password.same.help=(only to modify a password) 537 539 bo.user.role=Role 538 540 bo.user.creationDate=Creation date -
ether_megapoli/trunk/web/src/com/ether/ControllerBackoffice.java
r278 r279 16 16 17 17 import javax.mail.MessagingException; 18 import java.security.DigestException; 19 import java.security.NoSuchAlgorithmException; 18 20 import java.util.ArrayList; 19 21 import java.util.Date; … … 69 71 throws WebException, ServiceException 70 72 { 71 final User existingUser = _etherService.getUserByEmail( email ); 72 if( null == existingUser ) 73 { 74 final Date creationDate = new Date(); 75 final User user = new User( lastName, firstName, email, pwd, role, state, hasAccessToBO, creationDate ); 76 77 _etherService.createUser( user ); 78 } 79 else 80 throw new WebException( WebException.WebCode.USER_ALREADY_EXISTS, "This email already corresponds to an User", WebException.getExceptionThrowable() ); 73 try 74 { 75 final User existingUser = _etherService.getUserByEmail( email ); 76 if( null == existingUser ) 77 { 78 final Date creationDate = new Date(); 79 final String encryptedPassword = EtherHelper.encryptPassword( pwd ); 80 final User user = new User( lastName, firstName, email, encryptedPassword, role, state, hasAccessToBO, creationDate ); 81 82 _etherService.createUser( user ); 83 } 84 else 85 throw new WebException( WebException.WebCode.USER_ALREADY_EXISTS, "This email already corresponds to an User", WebException.getExceptionThrowable() ); 86 87 } 88 catch( DigestException e ) 89 { 90 throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "This password cannot be encrypted" ); 91 } 92 catch( NoSuchAlgorithmException e ) 93 { 94 throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "This password cannot be encrypted" ); 95 } 81 96 82 97 return getAllAndWaitingUsers(); … … 97 112 @Nullable @ParamName(ParameterConstants.PARAMETER_FIRST_NAME) final String firstName, 98 113 @NotNull @ParamName(ParameterConstants.PARAMETER_EMAIL) final String email, 99 @N otNull@ParamName(ParameterConstants.PARAMETER_PWD) final String pwd,114 @Nullable @ParamName(ParameterConstants.PARAMETER_PWD) final String pwd, 100 115 @Nullable @ParamName(ParameterConstants.PARAMETER_ROLE) final String role, 101 116 @NotNull @ParamName(ParameterConstants.PARAMETER_STATE) final String state, 102 @NotNull @ParamName(ParameterConstants.PARAMETER_HAS_ACCESS) final Boolean hasAccessToBO ) 103 throws WebException, ServiceException 104 { 105 final User existingUser = _etherService.getUserByEmail( email ); 106 if( null == existingUser || userId.equals( existingUser.getId() ) ) 107 { 108 final User user = _etherService.getUserById( userId ); 109 user.setLastName( lastName ); 110 user.setFirstName( firstName ); 111 user.setEmail( email ); 112 user.setPassword( pwd ); 113 user.setRole( UserRole.valueOf( role ) ); 114 user.setState( UserState.valueOf( state ) ); 115 user.setAccessToBO( hasAccessToBO ); 116 117 _etherService.updateUser( user ); 118 } 119 else 120 throw new WebException( WebException.WebCode.USER_ALREADY_EXISTS, "This email already corresponds to an User", WebException.getExceptionThrowable() ); 117 @NotNull @ParamName(ParameterConstants.PARAMETER_HAS_ACCESS) final Boolean hasAccessToBO, 118 @NotNull @ParamName(ParameterConstants.PARAMETER_KEEP_SAME_PASSWORD) final Boolean keepSamePassword ) 119 throws WebException, ServiceException 120 { 121 try 122 { 123 final User existingUser = _etherService.getUserByEmail( email ); 124 if( null == existingUser || userId.equals( existingUser.getId() ) ) 125 { 126 final User user = _etherService.getUserById( userId ); 127 user.setLastName( lastName ); 128 user.setFirstName( firstName ); 129 user.setEmail( email ); 130 if( !keepSamePassword && null != pwd ) 131 { 132 final String encryptedPassword = EtherHelper.encryptPassword( pwd ); 133 user.setPassword( encryptedPassword ); 134 } 135 user.setRole( UserRole.valueOf( role ) ); 136 user.setState( UserState.valueOf( state ) ); 137 user.setAccessToBO( hasAccessToBO ); 138 139 _etherService.updateUser( user ); 140 } 141 else 142 throw new WebException( WebException.WebCode.USER_ALREADY_EXISTS, "This email already corresponds to an User", WebException.getExceptionThrowable() ); 143 } 144 catch( DigestException e ) 145 { 146 throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "This password cannot be encrypted" ); 147 } 148 catch( NoSuchAlgorithmException e ) 149 { 150 throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "This password cannot be encrypted" ); 151 } 121 152 122 153 return getAllAndWaitingUsers(); … … 167 198 String content = "Dear user, \n\nThe Megapoli administrator has "; 168 199 if( isAccepted ) 169 { 170 content += "accepted your inscription. You can now access to data with : \n"; 171 content += " - login : " + user.getEmail() + '\n'; 172 content += " - password : " + user.getPassword() + '\n'; 173 } 200 content += "accepted your inscription. You can now access to data with you login (" + user.getEmail() + ") and the password you gave during inscription.\n"; 174 201 else 175 202 content += "refused your inscription. You can reply to this email if you want more information.\n"; -
ether_megapoli/trunk/web/src/com/ether/ControllerEponge.java
r278 r279 19 19 import javax.mail.MessagingException; 20 20 import javax.servlet.http.HttpServletRequest; 21 import java.security.DigestException; 22 import java.security.NoSuchAlgorithmException; 21 23 import java.util.Date; 22 24 import java.util.HashMap; … … 50 52 /** *********************** CALLS ***************************** **/ 51 53 /** *********************************************************** **/ 52 // TODO : crypter les login/pwd53 54 @ControllerMethod(requestMandatory = true, jsonResult = true) 54 55 public JSONObject login( @ParamName(ParameterConstants.PARAMETER_LOGIN) final String login, … … 87 88 } 88 89 89 90 90 @ControllerMethod(requestMandatory = true, jsonResult = true) 91 91 public JSONObject logout( @NotNull final HttpServletRequest request ) … … 101 101 public JSONObject createAccount( @NotNull @ParamName(ParameterConstants.PARAMETER_NAME) final String lastName, 102 102 @Nullable @ParamName(ParameterConstants.PARAMETER_FIRST_NAME) final String firstName, 103 @NotNull @ParamName(ParameterConstants.PARAMETER_EMAIL) final String email ) 103 @NotNull @ParamName(ParameterConstants.PARAMETER_EMAIL) final String email, 104 @NotNull @ParamName(ParameterConstants.PARAMETER_PWD) final String password ) 104 105 throws ServiceException, WebException 105 106 { 106 final User existingUser = _etherService.getUserByEmail( email ); 107 if( null == existingUser ) 107 try 108 108 { 109 final Date creationDate = new Date();110 // TODO : encrypt password111 final String password = "boum";112 final User user = new User( lastName, firstName, email, password, UserRole.COORDINATOR, UserState.WAITING, false, creationDate);109 final User existingUser = _etherService.getUserByEmail( email ); 110 if( null == existingUser ) 111 { 112 final Date creationDate = new Date(); 113 113 114 _etherService.createUser( user ); 114 final String encryptedPassword = EtherHelper.encryptPassword( password ); 115 final User user = new User( lastName, firstName, email, encryptedPassword, UserRole.COORDINATOR, UserState.WAITING, false, creationDate ); 115 116 116 // Send email to administrator to inform there is a new account 117 sendEmailToAdministrator( user ); 117 _etherService.createUser( user ); 118 119 // Send email to administrator to inform there is a new account 120 sendEmailToAdministrator( user ); 121 } 122 else 123 throw new WebException( WebException.WebCode.USER_ALREADY_EXISTS, "This email already corresponds to an User", WebException.getExceptionThrowable() ); 118 124 } 119 else 120 throw new WebException( WebException.WebCode.USER_ALREADY_EXISTS, "This email already corresponds to an User", WebException.getExceptionThrowable() ); 125 catch( DigestException e ) 126 { 127 throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "This password cannot be encrypted" ); 128 } 129 catch( NoSuchAlgorithmException e ) 130 { 131 throw new WebException( WebException.WebCode.ERROR_ENCRYPT_PASSWORD, "This password cannot be encrypted" ); 132 } 121 133 122 134 return new JSONObject(); … … 136 148 final MailFactory mailFactory = (MailFactory) getServletContext().getAttribute( "APP_MAILFACTORY" ); 137 149 final String from = (String) getServletContext().getAttribute( "APP_WEBMASTER" ); 150 final String toPI = (String) getServletContext().getAttribute( "APP_PI" ); 138 151 final String subject = "[MEGAPOLI] Nouvelle demande de compte utilisateur"; 139 152 final String content = "Hello Matthias,\n\nUne nouvelle demande de compte vient d'arriver.\n\n" + … … 144 157 "Bonne soirée,\nLe serveur masqué"; 145 158 146 final Mail mail = new Mail( from, from, null, content, subject ); 147 mailFactory.sendMail( mail ); 159 final Mail mailAdministrator = new Mail( from, from, null, content, subject ); 160 mailFactory.sendMail( mailAdministrator ); 161 final Mail mailPI = new Mail( from, toPI, null, content, subject ); 162 mailFactory.sendMail( mailPI ); 148 163 } 149 164 catch( MessagingException e ) -
ether_megapoli/trunk/web/src/com/ether/WebException.java
r278 r279 56 56 PARAMETER_IS_NULL, 57 57 USER_ALREADY_EXISTS, 58 ERROR_EMAIL_CANNOT_BE_SEND 58 ERROR_EMAIL_CANNOT_BE_SEND, 59 ERROR_ENCRYPT_PASSWORD 59 60 } 60 61
Note: See TracChangeset
for help on using the changeset viewer.