Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:33:48+00:00 2026-06-14T22:33:48+00:00

The JavaDoc for Shiro class JndiLdapRealm explicitly says that authorization is by default disabled

  • 0

The JavaDoc for Shiro class JndiLdapRealm explicitly says that authorization is by default disabled and that authorization against an LDAP server should be implemented by the user by subclassing and overriding the JndiLdapRealm#doGetAuthorizationInfo method.
Is there sample code on how to do that including handling the communication / protocol with the LDAP server available anywhere?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:33:49+00:00Added an answer on June 14, 2026 at 10:33 pm

    you should implement your own LdapRealm extending JndiLdapRealm.
    In this implementation, you would override queryForAuthorizationInfo() ; here is a simple example :

    protected AuthorizationInfo queryForAuthorizationInfo(PrincipalCollection principals, LdapContextFactory ldapContextFactory) throws NamingException {
    
    String username = (String) getAvailablePrincipal(principals);
    
    // Perform context search
    LdapContext ldapContext = ldapContextFactory.getSystemLdapContext();
    
    Set<String> roleNames;
    
    try {
      roleNames = getRoleNamesForUser(username, ldapContext);
    } finally {
      LdapUtils.closeContext(ldapContext);
    }
    
    return buildAuthorizationInfo(roleNames);
    }
    
    protected AuthorizationInfo buildAuthorizationInfo(Set<String> roleNames) {
    return new SimpleAuthorizationInfo(roleNames);
    }
    
    protected Set<String> getRoleNamesForUser(String username, LdapContext ldapContext) throws NamingException {
    Set<String> roleNames;
    roleNames = new LinkedHashSet<String>();
    
    SearchControls searchCtls = new SearchControls();
    searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    
    //SHIRO-115 - prevent potential code injection:
    String searchFilter = "(&(objectClass=*)(CN={0}))";
    Object[] searchArguments = new Object[]{ username };
    
    NamingEnumeration answer = ldapContext.search(searchBase, searchFilter, searchArguments, searchCtls);
    
    while (answer.hasMoreElements()) {
      SearchResult sr = (SearchResult) answer.next();
    
      if (log.isDebugEnabled()) {
        log.debug("Retrieving group names for user [" + sr.getName() + "]");
      }
    
      Attributes attrs = sr.getAttributes();
    
      if (attrs != null) {
        NamingEnumeration ae = attrs.getAll();
        while (ae.hasMore()) {
          Attribute attr = (Attribute) ae.next();
    
          if (attr.getID().equals("memberOf")) {
    
            Collection<String> groupNames = LdapUtils.getAllAttributeValues(attr);
    
            if (log.isDebugEnabled()) {
              log.debug("Groups found for user [" + username + "]: " + groupNames);
            }
    
            Collection<String> rolesForGroups = getRoleNamesForGroups(groupNames);
            roleNames.addAll(rolesForGroups);
          }
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The javadoc says: Please note that this class is designed to provide convenience rather
This FileInputStream.available() javadoc says: Returns an estimate of the number of remaining bytes that
Javadoc says for .close() of the PreparedStatement says that it .. Releases this Statement
The Javadoc for EventListenerLists says that they offer a degree of MT safety (when
I am writing the Javadoc for a class that contains its own enums. Is
java.lang.String JavaDoc says nothing about the default indexOf(String) substring search algorithm. So my question
Javadoc mentions that Object class has a public no-arg constructor. But Object's source code
Reading the javadoc for EhCacheManagerFactoryBean and EhCacheFactoryBean I figured that: <bean id=cacheManager class=org.springframework.cache.ehcache.EhCacheManagerFactoryBean p:configLocation=classpath:ehcache.xml/>
MIdlet's class javadoc states that MIdlet.destroyApp() will be called if MIdlet.startApp() throws a RuntimeException
Official Javadoc says that Math.floor() returns a double that is equal to a mathematical

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.