diff --git a/wise-webapp/src/main/java/com/wisemapping/security/DefaultPasswordEncoderFactories.java b/wise-webapp/src/main/java/com/wisemapping/security/DefaultPasswordEncoderFactories.java new file mode 100644 index 00000000..3d07c04d --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/security/DefaultPasswordEncoderFactories.java @@ -0,0 +1,26 @@ +package com.wisemapping.security; + +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.DelegatingPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; + +import java.util.HashMap; +import java.util.Map; + +public class DefaultPasswordEncoderFactories { + + private static final String ENCODING_ID = "bcrypt"; + + @SuppressWarnings("deprecation") + static PasswordEncoder createDelegatingPasswordEncoder() { + + final Map encoders = new HashMap<>(); + encoders.put(ENCODING_ID, new BCryptPasswordEncoder(16)); + + DelegatingPasswordEncoder result = new DelegatingPasswordEncoder(ENCODING_ID, encoders); + result.setDefaultPasswordEncoderForMatches(new LegacyPasswordEncoder()); + + return result; + } + +} \ No newline at end of file diff --git a/wise-webapp/src/main/java/com/wisemapping/security/CustomPasswordEncoder.java b/wise-webapp/src/main/java/com/wisemapping/security/LegacyPasswordEncoder.java similarity index 55% rename from wise-webapp/src/main/java/com/wisemapping/security/CustomPasswordEncoder.java rename to wise-webapp/src/main/java/com/wisemapping/security/LegacyPasswordEncoder.java index 5bf97ccd..aec1b65c 100755 --- a/wise-webapp/src/main/java/com/wisemapping/security/CustomPasswordEncoder.java +++ b/wise-webapp/src/main/java/com/wisemapping/security/LegacyPasswordEncoder.java @@ -18,27 +18,37 @@ package com.wisemapping.security; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.apache.log4j.Logger; import org.springframework.security.crypto.password.PasswordEncoder; -public class CustomPasswordEncoder implements PasswordEncoder { +@SuppressWarnings("deprecation") +public class LegacyPasswordEncoder implements PasswordEncoder { + final private static Logger logger = Logger.getLogger("com.wisemapping.security.LegacyPasswordEncoder"); + private static final String ENC_PREFIX = "ENC:"; - private BCryptPasswordEncoder delegateEncoder = new BCryptPasswordEncoder(16); + private static final PasswordEncoder sha1Encoder = new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1"); @Override public String encode(CharSequence rawPassword) { - String password = rawPassword.toString(); - if(!rawPassword.toString().startsWith(ENC_PREFIX)) { - password = ENC_PREFIX + delegateEncoder.encode(rawPassword); + + logger.info("LegacyPasswordEncoder encode executed."); + + String result = rawPassword.toString(); + if (!rawPassword.toString().startsWith(ENC_PREFIX)) { + result = ENC_PREFIX + sha1Encoder.encode(rawPassword); } - return password; + return result; } @Override public boolean matches(CharSequence rawPassword, String encodedPassword) { - String encodedRawPassword = delegateEncoder.encode(rawPassword); - return delegateEncoder.matches(encodedRawPassword, encodedPassword); + String newEncodedPassword = encodedPassword; + if (encodedPassword.startsWith(ENC_PREFIX)) { + + newEncodedPassword = encode(rawPassword); + } + return newEncodedPassword.equals(encodedPassword); } } diff --git a/wise-webapp/src/main/webapp/WEB-INF/classes/log4j.properties b/wise-webapp/src/main/webapp/WEB-INF/classes/log4j.properties index f1555fcd..78e56247 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/classes/log4j.properties +++ b/wise-webapp/src/main/webapp/WEB-INF/classes/log4j.properties @@ -1,7 +1,6 @@ log4j.rootLogger=WARN, stdout, R -log4j.logger.com.wisemapping=WARN,stdout,R -log4j.logger.org.springframework=WARN,stdout,R -log4j.logger.org.codehaus.jackson=WARN,stdout,R +log4j.logger.com.wisemapping=INFO,stdout,R +log4j.logger.org.springframework=INFO,stdout,R log4j.logger.org.hibernate=WARN,stdout,R log4j.logger.org.hibernate.engine.StatefulPersistenceContext=ERROR,stdout,R diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-model.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-model.xml index 97f8c680..d2925eac 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-model.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-model.xml @@ -7,7 +7,7 @@ - + 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 index 5d3824f3..4d63d585 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security-db.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security-db.xml @@ -8,6 +8,8 @@ http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"> + + @@ -15,7 +17,6 @@ - + - \ No newline at end of file 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 b78d6a27..05361f7c 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml @@ -87,8 +87,6 @@ - -