active directory - Apache Shiro - authentication with attribute other than cn? -


i'm trying use apache shiro in our project authentication , authorization active directory realm. works when authenticate users cn attribute however, use unique attribute login. possible configure shiro so?

here shiro.ini file:

    [main]     shiro.loginurl = /login.jsp     activedirectoryrealm = org.apache.shiro.realm.activedirectory.activedirectoryrealm     activedirectoryrealm.systemusername = admin     activedirectoryrealm.systempassword = secret     activedirectoryrealm.searchbase = dc=company,dc=private     activedirectoryrealm.url = ldap://url:389 

and login code:

    public void login(string uname, string pwd, boolean rememberme) {             factory<securitymanager> ldapfactory = new inisecuritymanagerfactory("classpath:shiro.ini");             securitymanager smanager = ldapfactory.getinstance();             securityutils.setsecuritymanager(smanager);             subject currentuser = securityutils.getsubject();             if (!currentuser.isauthenticated()) {                 uname = "cn=" + uname + ",ou=users";                 usernamepasswordtoken token = new usernamepasswordtoken(uname, pwd);                 token.setrememberme(rememberme);                 try {                     currentuser.login(token);                 } catch (unknownaccountexception ex) {                     logger.info("unknown user");                 } catch (incorrectcredentialsexception ex) {                     logger.info("incorrect credentials");                 } catch (lockedaccountexception ex) {                     logger.info("account locked");                 } catch (authenticationexception ex) {                     ex.printstacktrace();                 }             }         } 

if change line

    uname = "cn=" + uname + ",ou=users"; 

to following

    uname = "mycustomattribute=" + uname + ",ou=users"; 

and try login it, got

    javax.naming.authenticationexception: [ldap: error code 49 - 80090308: ldaperr: dsid-0c0903a9, comment: acceptsecuritycontext error, data 52e, v1db1 ] 

thanks answers.

ok, i've managed creating custom myjndildaprealm extending jndildaprealm , overriding method

protected authenticationinfo dogetauthenticationinfo(authenticationtoken token){} 

but still welcome answers if have better solutions.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -