mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-15 11:07:57 +01:00
Fix password encription
This commit is contained in:
parent
145986fb61
commit
11c6ce1004
@ -19,6 +19,7 @@
|
|||||||
package com.wisemapping.security;
|
package com.wisemapping.security;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.security.crypto.password.MessageDigestPasswordEncoder;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@ -26,29 +27,21 @@ public class LegacyPasswordEncoder implements PasswordEncoder {
|
|||||||
final private static Logger logger = Logger.getLogger("com.wisemapping.security.LegacyPasswordEncoder");
|
final private static Logger logger = Logger.getLogger("com.wisemapping.security.LegacyPasswordEncoder");
|
||||||
|
|
||||||
private static final String ENC_PREFIX = "ENC:";
|
private static final String ENC_PREFIX = "ENC:";
|
||||||
private static final PasswordEncoder sha1Encoder = new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1");
|
private static final PasswordEncoder sha1Encoder = new MessageDigestPasswordEncoder("SHA-1");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String encode(CharSequence rawPassword) {
|
public String encode(CharSequence rawPassword) {
|
||||||
|
|
||||||
logger.info("LegacyPasswordEncoder encode executed.");
|
logger.info("LegacyPasswordEncoder encode executed.");
|
||||||
|
return ENC_PREFIX + sha1Encoder.encode(rawPassword);
|
||||||
|
|
||||||
String result = rawPassword.toString();
|
|
||||||
if (!rawPassword.toString().startsWith(ENC_PREFIX)) {
|
|
||||||
result = ENC_PREFIX + sha1Encoder.encode(rawPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(CharSequence rawPassword, String encodedPassword) {
|
public boolean matches(CharSequence rawPassword, String encodedPassword) {
|
||||||
|
|
||||||
String newEncodedPassword = encodedPassword;
|
final String encode = encode(rawPassword);
|
||||||
if (encodedPassword.startsWith(ENC_PREFIX)) {
|
logger.info("LegacyPasswordEncoder encode executed ->" + encode + ":" + encodedPassword);
|
||||||
|
return encode.equals(encodedPassword);
|
||||||
newEncodedPassword = encode(rawPassword);
|
|
||||||
}
|
|
||||||
return newEncodedPassword.equals(encodedPassword);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user