fixed Username AD realm

added missing serail version uid to config service
update shiro to 1.3.2
This commit is contained in:
jomu
2016-09-27 22:21:59 +00:00
parent 2471221bda
commit 1a9c4ced6e
6 changed files with 150 additions and 15 deletions

View File

@ -1,6 +1,7 @@
package de.muehlencord.shared.account.business;
import de.muehlencord.shared.account.entity.ConfigEntity;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
@ -13,7 +14,9 @@ import javax.persistence.PersistenceContext;
*/
@Singleton
@Startup
public class ConfigService {
public class ConfigService implements Serializable {
private static final long serialVersionUID = -3195224653632853003L;
@PersistenceContext
EntityManager em;
@ -32,10 +35,10 @@ public class ConfigService {
this.maxFailedLogins = Integer.parseInt(configEntity.getConfigValue());
}
}
public String getConfigValue (String configKey) {
ConfigEntity configEntity = em.find(ConfigEntity.class, configKey);
return (configEntity == null ? null : configEntity.getConfigValue());
public String getConfigValue(String configKey) {
ConfigEntity configEntity = em.find(ConfigEntity.class, configKey);
return (configEntity == null ? null : configEntity.getConfigValue());
}
/* *** getter *** */

View File

@ -14,21 +14,23 @@ 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;
String userName = upToken.getUsername();
try {
try {
if (principalSuffix != null) {
if (!userName.contains(principalSuffix))
if (!userName.contains(principalSuffix)) {
userName += principalSuffix;
}
}
ctx = ldapContextFactory.getLdapContext(userName, String.valueOf(upToken.getPassword()));
// use system context (system user / password) to connect to server
// ctx = ldapContextFactory.getSystemLdapContext();
ctx = ldapContextFactory.getLdapContext(userName, upToken.getCredentials());
} finally {
LdapUtils.closeContext(ctx);
}