import static org.argeo.security.core.ArgeoUserDetails.createSimpleArgeoUser;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
import javax.naming.Name;
import javax.naming.NamingException;
import org.springframework.security.ldap.populator.DefaultLdapAuthoritiesPopulator;
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch;
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
+import org.springframework.security.providers.ldap.authenticator.LdapShaPasswordEncoder;
import org.springframework.security.userdetails.UserDetails;
import org.springframework.security.userdetails.UserDetailsManager;
import org.springframework.security.userdetails.UserDetailsService;
private LdapUserDetailsService ldapUserDetailsService;
private List<UserNatureMapper> userNatureMappers;
+ private LdapShaPasswordEncoder ldapShaPasswordEncoder = new LdapShaPasswordEncoder();
+ private Random random;
+
+ public ArgeoSecurityDaoLdap(BaseLdapPathContextSource contextSource) {
+ this.contextSource = contextSource;
+ ldapTemplate = new LdapTemplate(this.contextSource);
+ try {
+ random = SecureRandom.getInstance("SHA1PRNG");
+ } catch (NoSuchAlgorithmException e) {
+ random = new Random(System.currentTimeMillis());
+ }
+ }
+
public void afterPropertiesSet() throws Exception {
if (usernameMapper == null)
usernameMapper = new DefaultLdapUsernameToDnMapper(userBase,
}
}
- public ArgeoSecurityDaoLdap(BaseLdapPathContextSource contextSource) {
- this.contextSource = contextSource;
- ldapTemplate = new LdapTemplate(this.contextSource);
- }
-
public synchronized void create(ArgeoUser user) {
userDetailsManager.createUser(new ArgeoUserDetails(user));
}
return createSimpleArgeoUser(getDetails(uname));
}
-// public ArgeoUser getCurrentUser() {
-// ArgeoUser argeoUser = ArgeoUserDetails.securityContextUser();
-// if (argeoUser == null)
-// return null;
-// if (argeoUser.getRoles().contains(defaultRole))
-// argeoUser.getRoles().remove(defaultRole);
-// return argeoUser;
-// }
+ // public ArgeoUser getCurrentUser() {
+ // ArgeoUser argeoUser = ArgeoUserDetails.securityContextUser();
+ // if (argeoUser == null)
+ // return null;
+ // if (argeoUser.getRoles().contains(defaultRole))
+ // argeoUser.getRoles().remove(defaultRole);
+ // return argeoUser;
+ // }
@SuppressWarnings("unchecked")
public synchronized List<ArgeoUser> listUsers() {
ldapTemplate.unbind(dn);
}
+ public Boolean isPasswordValid(String encoded, String raw) {
+ return ldapShaPasswordEncoder.isPasswordValid(encoded, raw, null);
+ }
+
+ public String encodePassword(String raw) {
+ byte[] salt = null;
+ // TODO: check that Linux auth supports SSHA
+ // byte[] salt = new byte[16];
+ // random.nextBytes(salt);
+ return ldapShaPasswordEncoder.encodePassword(raw, salt);
+ }
+
protected String convertRoleToGroup(String role) {
String group = role;
if (group.startsWith(rolePrefix)) {