Example usage for org.apache.shiro.realm.ldap JndiLdapContextFactory getEnvironment

List of usage examples for org.apache.shiro.realm.ldap JndiLdapContextFactory getEnvironment

Introduction

In this page you can find the example usage for org.apache.shiro.realm.ldap JndiLdapContextFactory getEnvironment.

Prototype

public Map getEnvironment() 

Source Link

Document

Returns the base JNDI environment template to use when acquiring an LDAP connection (an LdapContext ).

Usage

From source file:org.killbill.billing.util.security.shiro.realm.KillBillJndiLdapRealm.java

License:Apache License

@Inject
public KillBillJndiLdapRealm(final SecurityConfig securityConfig) {
    super();//from  www  .j a  v  a2  s  .  c  o  m

    if (securityConfig.getShiroLDAPUserDnTemplate() != null) {
        setUserDnTemplate(securityConfig.getShiroLDAPUserDnTemplate());
    }

    final JndiLdapContextFactory contextFactory = (JndiLdapContextFactory) getContextFactory();
    if (securityConfig.disableShiroLDAPSSLCheck()) {
        contextFactory.getEnvironment().put("java.naming.ldap.factory.socket",
                SkipSSLCheckSocketFactory.class.getName());
    }
    if (securityConfig.getShiroLDAPUrl() != null) {
        contextFactory.setUrl(securityConfig.getShiroLDAPUrl());
    }
    if (securityConfig.getShiroLDAPSystemUsername() != null) {
        contextFactory.setSystemUsername(securityConfig.getShiroLDAPSystemUsername());
    }
    if (securityConfig.getShiroLDAPSystemPassword() != null) {
        contextFactory.setSystemPassword(securityConfig.getShiroLDAPSystemPassword());
    }
    if (securityConfig.getShiroLDAPAuthenticationMechanism() != null) {
        contextFactory.setAuthenticationMechanism(securityConfig.getShiroLDAPAuthenticationMechanism());
    }
    setContextFactory(contextFactory);

    searchBase = securityConfig.getShiroLDAPSearchBase();
    groupSearchFilter = securityConfig.getShiroLDAPGroupSearchFilter();
    groupNameId = securityConfig.getShiroLDAPGroupNameID();

    if (securityConfig.getShiroLDAPPermissionsByGroup() != null) {
        final Ini ini = new Ini();
        // When passing properties on the command line, \n can be escaped
        ini.load(securityConfig.getShiroLDAPPermissionsByGroup().replace("\\n", "\n"));
        for (final Section section : ini.getSections()) {
            for (final String role : section.keySet()) {
                final Collection<String> permissions = ImmutableList
                        .<String>copyOf(SPLITTER.split(section.get(role)));
                permissionsByGroup.put(role, permissions);
            }
        }
    }
}