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

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

Introduction

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

Prototype

public void setSystemUsername(String systemUsername) 

Source Link

Document

Sets the system username that will be used when creating an LDAP connection used for authorization queries.

Usage

From source file:io.vertx.ext.auth.impl.realms.LDAPAuthRealm.java

License:Open Source License

@Override
public void init(JsonObject config) {
    this.config = config;
    JndiLdapRealm ldapRealm = new JndiLdapRealm();
    JndiLdapContextFactory factory = new JndiLdapContextFactory();
    String userDNTemplate = config.getString(LDAP_USER_DN_TEMPLATE_FIELD);
    if (userDNTemplate != null) {
        ldapRealm.setUserDnTemplate(userDNTemplate);
    }/*from   www.  j av  a 2  s .co m*/
    String url = config.getString(LDAP_URL);
    if (url != null) {
        factory.setUrl(url);
    }
    String authenticationMechanism = config.getString(LDAP_AUTHENTICATION_MECHANISM);
    if (authenticationMechanism != null) {
        factory.setAuthenticationMechanism(authenticationMechanism);
    }
    String contextFactoryClassName = config.getString(LDAP_CONTEXT_FACTORY_CLASS_NAME);
    if (contextFactoryClassName != null) {
        factory.setContextFactoryClassName(contextFactoryClassName);
    }
    boolean poolingEnabled = config.getBoolean(LDAP_POOLING_ENABLED, false);
    factory.setPoolingEnabled(poolingEnabled);
    String referral = config.getString(LDAP_REFERRAL);
    if (referral != null) {
        factory.setReferral(referral);
    }
    String systemUsername = config.getString(LDAP_SYSTEM_USERNAME);
    if (systemUsername != null) {
        factory.setSystemUsername(systemUsername);
    }
    String systemPassword = config.getString(LDAP_SYSTEM_PASSWORD);
    if (systemPassword != null) {
        factory.setSystemPassword(systemPassword);
    }
    ldapRealm.setContextFactory(factory);
    ldapRealm.init();
    this.securityManager = new DefaultSecurityManager(ldapRealm);
    this.realm = ldapRealm;
}

From source file:io.vertx.ext.auth.shiro.impl.LDAPAuthProvider.java

License:Open Source License

public static Realm createRealm(JsonObject config) {
    JndiLdapRealm ldapRealm = new JndiLdapRealm();
    JndiLdapContextFactory factory = new JndiLdapContextFactory();
    String userDNTemplate = config.getString(LDAP_USER_DN_TEMPLATE_FIELD);
    if (userDNTemplate != null) {
        ldapRealm.setUserDnTemplate(userDNTemplate);
    }//from   www .j a  v a 2s . c  o m
    String url = config.getString(LDAP_URL);
    if (url != null) {
        factory.setUrl(url);
    }
    String authenticationMechanism = config.getString(LDAP_AUTHENTICATION_MECHANISM);
    if (authenticationMechanism != null) {
        factory.setAuthenticationMechanism(authenticationMechanism);
    }
    String contextFactoryClassName = config.getString(LDAP_CONTEXT_FACTORY_CLASS_NAME);
    if (contextFactoryClassName != null) {
        factory.setContextFactoryClassName(contextFactoryClassName);
    }
    boolean poolingEnabled = config.getBoolean(LDAP_POOLING_ENABLED, false);
    factory.setPoolingEnabled(poolingEnabled);
    String referral = config.getString(LDAP_REFERRAL);
    if (referral != null) {
        factory.setReferral(referral);
    }
    String systemUsername = config.getString(LDAP_SYSTEM_USERNAME);
    if (systemUsername != null) {
        factory.setSystemUsername(systemUsername);
    }
    String systemPassword = config.getString(LDAP_SYSTEM_PASSWORD);
    if (systemPassword != null) {
        factory.setSystemPassword(systemPassword);
    }
    ldapRealm.setContextFactory(factory);
    ldapRealm.init();
    return ldapRealm;
}

From source file:io.vertx.ext.auth.shiro.impl.LDAPAuthRealm.java

License:Open Source License

public LDAPAuthRealm(JsonObject config) {
    JndiLdapRealm ldapRealm = new JndiLdapRealm();
    JndiLdapContextFactory factory = new JndiLdapContextFactory();
    String userDNTemplate = config.getString(LDAP_USER_DN_TEMPLATE_FIELD);
    if (userDNTemplate != null) {
        ldapRealm.setUserDnTemplate(userDNTemplate);
    }/*from  ww w  . jav a 2 s. c o m*/
    String url = config.getString(LDAP_URL);
    if (url != null) {
        factory.setUrl(url);
    }
    String authenticationMechanism = config.getString(LDAP_AUTHENTICATION_MECHANISM);
    if (authenticationMechanism != null) {
        factory.setAuthenticationMechanism(authenticationMechanism);
    }
    String contextFactoryClassName = config.getString(LDAP_CONTEXT_FACTORY_CLASS_NAME);
    if (contextFactoryClassName != null) {
        factory.setContextFactoryClassName(contextFactoryClassName);
    }
    boolean poolingEnabled = config.getBoolean(LDAP_POOLING_ENABLED, false);
    factory.setPoolingEnabled(poolingEnabled);
    String referral = config.getString(LDAP_REFERRAL);
    if (referral != null) {
        factory.setReferral(referral);
    }
    String systemUsername = config.getString(LDAP_SYSTEM_USERNAME);
    if (systemUsername != null) {
        factory.setSystemUsername(systemUsername);
    }
    String systemPassword = config.getString(LDAP_SYSTEM_PASSWORD);
    if (systemPassword != null) {
        factory.setSystemPassword(systemPassword);
    }
    ldapRealm.setContextFactory(factory);
    ldapRealm.init();
    this.securityManager = new DefaultSecurityManager(ldapRealm);
    this.realm = ldapRealm;
}

From source file:org.apache.airavata.security.userstore.LDAPUserStore.java

License:Apache License

protected void initializeLDAP(String ldapUrl, String systemUser, String systemUserPassword,
        String userNameTemplate) {

    JndiLdapContextFactory jndiLdapContextFactory = new JndiLdapContextFactory();

    jndiLdapContextFactory.setUrl(ldapUrl);
    jndiLdapContextFactory.setSystemUsername(systemUser);
    jndiLdapContextFactory.setSystemPassword(systemUserPassword);

    ldapRealm = new JndiLdapRealm();

    ldapRealm.setContextFactory(jndiLdapContextFactory);
    ldapRealm.setUserDnTemplate(userNameTemplate);

    ldapRealm.init();//from  www .  j a v  a 2 s.  c  om

}

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

License:Apache License

@Inject
public KillBillJndiLdapRealm(final SecurityConfig securityConfig) {
    super();/*from  ww w.j  av a 2s . co 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);
            }
        }
    }
}

From source file:rbac.configuration.security.shiro.ShiroConfiguration.java

License:Apache License

@Bean
public JndiLdapContextFactory jndiLdapContextFactory() {
    JndiLdapContextFactory jndiLdapContextFactory = new JndiLdapContextFactory();
    jndiLdapContextFactory.setUrl("ldaps://192.168.1.6:636");
    jndiLdapContextFactory.setSystemUsername("{0}");
    jndiLdapContextFactory.setSystemPassword("{0}");
    jndiLdapContextFactory.setAuthenticationMechanism("DIGEST-MD5");
    return jndiLdapContextFactory;
}