Search in sources :

Example 1 with SecurityConfig

use of org.killbill.billing.util.config.definition.SecurityConfig in project killbill by killbill.

the class TestKillBillJndiLdapRealm method testCheckLDAPConnection.

@Test(groups = "external", enabled = false)
public void testCheckLDAPConnection() throws Exception {
    // Convenience method to verify your LDAP connectivity
    final Properties props = new Properties();
    props.setProperty("org.killbill.security.ldap.userDnTemplate", "uid={0},ou=users,dc=mycompany,dc=com");
    props.setProperty("org.killbill.security.ldap.searchBase", "ou=groups,dc=mycompany,dc=com");
    props.setProperty("org.killbill.security.ldap.groupSearchFilter", "memberOf=uid={0},ou=users,dc=mycompany,dc=com");
    props.setProperty("org.killbill.security.ldap.groupNameId", "cn");
    props.setProperty("org.killbill.security.ldap.url", "ldap://ldap:389");
    props.setProperty("org.killbill.security.ldap.disableSSLCheck", "true");
    props.setProperty("org.killbill.security.ldap.systemUsername", "cn=root");
    props.setProperty("org.killbill.security.ldap.systemPassword", "password");
    props.setProperty("org.killbill.security.ldap.authenticationMechanism", "simple");
    props.setProperty("org.killbill.security.ldap.permissionsByGroup", "support-group: entitlement:*\n" + "finance-group: invoice:*, payment:*\n" + "ops-group: *:*");
    final ConfigSource customConfigSource = new SimplePropertyConfigSource(props);
    final SecurityConfig securityConfig = new ConfigurationObjectFactory(customConfigSource).build(SecurityConfig.class);
    final KillBillJndiLdapRealm ldapRealm = new KillBillJndiLdapRealm(securityConfig);
    final String username = "pierre";
    final String password = "password";
    // Check authentication
    final UsernamePasswordToken token = new UsernamePasswordToken(username, password);
    final AuthenticationInfo authenticationInfo = ldapRealm.getAuthenticationInfo(token);
    System.out.println(authenticationInfo);
    // Check permissions
    final SimplePrincipalCollection principals = new SimplePrincipalCollection(username, username);
    final AuthorizationInfo authorizationInfo = ldapRealm.queryForAuthorizationInfo(principals, ldapRealm.getContextFactory());
    System.out.println("Roles: " + authorizationInfo.getRoles());
    System.out.println("Permissions: " + authorizationInfo.getStringPermissions());
}
Also used : SimplePropertyConfigSource(org.skife.config.SimplePropertyConfigSource) ConfigSource(org.skife.config.ConfigSource) SimplePropertyConfigSource(org.skife.config.SimplePropertyConfigSource) SecurityConfig(org.killbill.billing.util.config.definition.SecurityConfig) ConfigurationObjectFactory(org.skife.config.ConfigurationObjectFactory) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Properties(java.util.Properties) AuthorizationInfo(org.apache.shiro.authz.AuthorizationInfo) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) Test(org.testng.annotations.Test)

Example 2 with SecurityConfig

use of org.killbill.billing.util.config.definition.SecurityConfig in project killbill by killbill.

the class SecurityModule method installConfig.

private void installConfig() {
    final SecurityConfig securityConfig = new ConfigurationObjectFactory(skifeConfigSource).build(SecurityConfig.class);
    bind(SecurityConfig.class).toInstance(securityConfig);
}
Also used : SecurityConfig(org.killbill.billing.util.config.definition.SecurityConfig) ConfigurationObjectFactory(org.skife.config.ConfigurationObjectFactory)

Aggregations

SecurityConfig (org.killbill.billing.util.config.definition.SecurityConfig)2 ConfigurationObjectFactory (org.skife.config.ConfigurationObjectFactory)2 Properties (java.util.Properties)1 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1 ConfigSource (org.skife.config.ConfigSource)1 SimplePropertyConfigSource (org.skife.config.SimplePropertyConfigSource)1 Test (org.testng.annotations.Test)1