added AD realm accepting user name only (by extending domain name automatically)
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
package de.muehlencord.shared.account.util;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm;
|
||||
import org.apache.shiro.realm.ldap.LdapContextFactory;
|
||||
import org.apache.shiro.realm.ldap.LdapUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
public class UserNameActiveDirectoryRealm extends ActiveDirectoryRealm {
|
||||
|
||||
@Override
|
||||
protected AuthenticationInfo queryForAuthenticationInfo(AuthenticationToken token, LdapContextFactory ldapContextFactory) throws NamingException {
|
||||
|
||||
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
|
||||
// Binds using the username and password provided by the user.
|
||||
LdapContext ctx = null;
|
||||
try {
|
||||
String userName = upToken.getUsername();
|
||||
if (principalSuffix != null) {
|
||||
if (!userName.contains(principalSuffix))
|
||||
userName += principalSuffix;
|
||||
}
|
||||
|
||||
ctx = ldapContextFactory.getLdapContext(userName, String.valueOf(upToken.getPassword()));
|
||||
} finally {
|
||||
LdapUtils.closeContext(ctx);
|
||||
}
|
||||
|
||||
return buildAuthenticationInfo(upToken.getUsername(), upToken.getPassword());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user