Search in sources :

Example 1 with SimplePropertyConfigSource

use of org.skife.config.SimplePropertyConfigSource 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 SimplePropertyConfigSource

use of org.skife.config.SimplePropertyConfigSource in project killbill by killbill.

the class TestKillBillOktaRealm method testCheckOktaConnection.

@Test(groups = "external", enabled = false)
public void testCheckOktaConnection() throws Exception {
    // Convenience method to verify your Okta connectivity
    final Properties props = new Properties();
    props.setProperty("org.killbill.security.okta.url", "https://dev-XXXXXX.oktapreview.com");
    props.setProperty("org.killbill.security.okta.apiToken", "YYYYYY");
    props.setProperty("org.killbill.security.okta.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 KillBillOktaRealm oktaRealm = new KillBillOktaRealm(securityConfig);
    final String username = "pierre";
    final String password = "password";
    // Check authentication
    final UsernamePasswordToken token = new UsernamePasswordToken(username, password);
    final AuthenticationInfo authenticationInfo = oktaRealm.getAuthenticationInfo(token);
    System.out.println(authenticationInfo);
    // Check permissions
    final SimplePrincipalCollection principals = new SimplePrincipalCollection(username, username);
    final AuthorizationInfo authorizationInfo = oktaRealm.doGetAuthorizationInfo(principals);
    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 3 with SimplePropertyConfigSource

use of org.skife.config.SimplePropertyConfigSource in project killbill by killbill.

the class TestKillBillAuth0Realm method testCheckAuth0Connection.

@Test(groups = "external", enabled = false)
public void testCheckAuth0Connection() throws Exception {
    // Convenience method to verify your Auth0 connectivity
    final Properties props = new Properties();
    props.setProperty("org.killbill.security.auth0.url", "https://XXX.us.auth0.com");
    props.setProperty("org.killbill.security.auth0.clientId", "YYY");
    props.setProperty("org.killbill.security.auth0.clientSecret", "ZZZ");
    props.setProperty("org.killbill.security.auth0.apiIdentifier", "WWW");
    props.setProperty("org.killbill.security.auth0.databaseConnectionName", "Username-Password-Authentication");
    props.setProperty("org.killbill.security.auth0.allowedClockSkew", "2000s");
    final ConfigSource customConfigSource = new SimplePropertyConfigSource(props);
    final SecurityConfig securityConfig = new ConfigurationObjectFactory(customConfigSource).build(SecurityConfig.class);
    final KillBillAuth0Realm auth0Realm = new KillBillAuth0Realm(securityConfig, clock);
    final String username = "test@example.com";
    final String password = "password";
    // Check authentication
    final AuthenticationToken token = new UsernamePasswordToken(username, password);
    final AuthenticationInfo authenticationInfo = auth0Realm.getAuthenticationInfo(token);
    System.out.println(authenticationInfo);
    // Check permissions
    final PrincipalCollection principals = new SimplePrincipalCollection(username, username);
    final AuthorizationInfo authorizationInfo = auth0Realm.doGetAuthorizationInfo(principals);
    System.out.println("Roles: " + authorizationInfo.getRoles());
    System.out.println("Permissions: " + authorizationInfo.getStringPermissions());
    // Check JWT
    final Claims claims = auth0Realm.verifyJWT("JWT");
    System.out.println("Token claims: " + claims);
}
Also used : SimplePropertyConfigSource(org.skife.config.SimplePropertyConfigSource) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) Claims(io.jsonwebtoken.Claims) ConfigurationObjectFactory(org.skife.config.ConfigurationObjectFactory) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) 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) SimplePropertyConfigSource(org.skife.config.SimplePropertyConfigSource) ConfigSource(org.skife.config.ConfigSource) SecurityConfig(org.killbill.billing.util.config.definition.SecurityConfig) Test(org.testng.annotations.Test)

Aggregations

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