Apache Shiro combined with LDAP

I combined Apache Shiro with a mannequin and it works great! But this framework has no online training! It is very difficult to get into it as a beginner.

Can someone help me integrate ldap integration. I just found information that it is not so difficult: - /

I started by setting up the area:

[main] myRealm = org.apache.shiro.realm.ldap.AbstractLdapRealm 

But what to do next? How to configure it?

Thanks for any help

+6
security ldap
source share
4 answers

AbstractLdapRealm is abstract - you cannot create it directly or declare it as your kingdom. You will have to subclass this and implement the necessary abstract methods.

You will not need to do this the next time Shiro is released - the problem is currently open ( https://issues.apache.org/jira/browse/SHIRO-127 ) in order to have a specific implementation that can be used out of the box, so 95 % of end users should not subclass AbstractLdapRealm.

NTN

Le

+4
source share

This may not help much. Check out the entire tutorial that covers simple and LDAP authentication. http://www.ibm.com/developerworks/web/library/wa-apacheshiro/

+4
source share

Here is an example of work.

active.ini

 ldapRealm = org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm ldapRealm.url = ldap://ldapserver:389 

the code:

 Factory<SecurityManager> ldapFactory = new IniSecurityManagerFactory("classpath:active.ini"); SecurityManager sManager = ldapFactory.getInstance(); SecurityUtils.setSecurityManager(sManager); Subject currentUser = SecurityUtils.getSubject(); if (!currentUser.isAuthenticated()) { UsernamePasswordToken token = new UsernamePasswordToken("user", "password"); try { currentUser.login(token); } catch (UnknownAccountException ex) { logger.info("Unknown user"); } catch (IncorrectCredentialsException ex) { logger.info("Incorrect credentials"); } catch (LockedAccountException ex) { logger.info("Account is Locked"); } catch (AuthenticationException ex) { logger.info("Authentication Exception"); } } logger.info("User [" + currentUser.getPrincipal() +"] logged succesfully"); currentUser.logout(); 
+3
source share

using Spring as the main structure, you can also use the XML context of the application to define spheres as:

  <bean id="ldapRealm" class="org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm"> <property name="url" value="ldap:/ldapserver:389" /> </bean> 

Then pass the scope to your Security Manager:

 <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> <property name="realm" ref="ldapRealm" /> </bean> 

Then enter the login code wherever you want.

0
source share

All Articles