use of org.apache.shiro.authc.AuthenticationInfo in project killbill by killbill.
the class ModularRealmAuthenticatorWith540 method doMultiRealmAuthentication.
/**
* Performs the multi-realm authentication attempt by calling back to a {@link AuthenticationStrategy} object
* as each realm is consulted for {@code AuthenticationInfo} for the specified {@code token}.
*
* @param realms the multiple realms configured on this Authenticator instance.
* @param token the submitted AuthenticationToken representing the subject's (user's) log-in principals and credentials.
* @return an aggregated AuthenticationInfo instance representing account data across all the successfully
* consulted realms.
*/
protected AuthenticationInfo doMultiRealmAuthentication(final Collection<Realm> realms, final AuthenticationToken token) {
final AuthenticationStrategy strategy = getAuthenticationStrategy();
AuthenticationInfo aggregate = strategy.beforeAllAttempts(realms, token);
if (log.isTraceEnabled()) {
log.trace("Iterating through {} realms for PAM authentication", realms.size());
}
for (final Realm realm : realms) {
aggregate = strategy.beforeAttempt(realm, token, aggregate);
if (realm.supports(token)) {
log.trace("Attempting to authenticate token [{}] using realm [{}]", token, realm);
AuthenticationInfo info = null;
Throwable t = null;
try {
info = realm.getAuthenticationInfo(token);
} catch (final Throwable throwable) {
t = throwable;
if (log.isDebugEnabled()) {
final String msg = "Realm [" + realm + "] threw an exception during a multi-realm authentication attempt:";
log.debug(msg, t);
}
}
aggregate = strategy.afterAttempt(realm, token, info, aggregate, t);
if (strategy instanceof FirstSuccessfulStrategyWith540) {
// check if we should check the next realm, or just stop here.
if (!((FirstSuccessfulStrategyWith540) strategy).continueAfterAttempt(info, aggregate, t)) {
log.trace("Will not consult any other realms for authentication, last realm [{}].", realm);
break;
}
}
} else {
log.debug("Realm [{}] does not support token {}. Skipping realm.", realm, token);
}
}
aggregate = strategy.afterAllAttempts(token, aggregate);
return aggregate;
}
use of org.apache.shiro.authc.AuthenticationInfo in project neo4j by neo4j.
the class PluginRealm method doGetAuthenticationInfo.
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
if (token instanceof ShiroAuthToken) {
try {
AuthToken pluginAuthToken = PluginApiAuthToken.createFromMap(((ShiroAuthToken) token).getAuthTokenMap());
if (authPlugin != null) {
AuthInfo authInfo = authPlugin.authenticateAndAuthorize(pluginAuthToken);
if (authInfo != null) {
PluginAuthInfo pluginAuthInfo = PluginAuthInfo.createCacheable(authInfo, getName(), secureHasher);
cacheAuthorizationInfo(pluginAuthInfo);
return pluginAuthInfo;
}
} else if (authenticationPlugin != null) {
org.neo4j.server.security.enterprise.auth.plugin.spi.AuthenticationInfo authenticationInfo = authenticationPlugin.authenticate(pluginAuthToken);
if (authenticationInfo != null) {
return PluginAuthenticationInfo.createCacheable(authenticationInfo, getName(), secureHasher);
}
}
} catch (org.neo4j.server.security.enterprise.auth.plugin.api.AuthenticationException | InvalidAuthTokenException e) {
throw new AuthenticationException(e.getMessage(), e.getCause());
}
}
return null;
}
use of org.apache.shiro.authc.AuthenticationInfo 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());
}
use of org.apache.shiro.authc.AuthenticationInfo in project ddf by codice.
the class SecurityManagerImplTest method testAuthToken.
/**
* Creates mock objects and uses those to pass through the system when an authentication token
* is used.
*
* @throws SecurityServiceException
*/
@Test
public void testAuthToken() throws SecurityServiceException {
// mock setup
SimplePrincipalCollection principals = new SimplePrincipalCollection();
SecurityToken secToken = new SecurityToken();
principals.add(secToken, REALM_NAME);
AuthenticationToken authToken = mock(AuthenticationToken.class);
when(authToken.getCredentials()).thenReturn("testUser");
AuthenticationInfo info = mock(AuthenticationInfo.class);
when(info.getPrincipals()).thenReturn(principals);
// realm
Realm realm = mock(Realm.class);
when(realm.getAuthenticationInfo(authToken)).thenReturn(info);
when(realm.supports(authToken)).thenReturn(Boolean.TRUE);
when(realm.getName()).thenReturn(REALM_NAME);
SecurityManagerImpl manager = new SecurityManagerImpl();
manager.setRealms(Arrays.asList(new Realm[] { realm }));
Subject subject = manager.getSubject(authToken);
assertNotNull(subject);
}
use of org.apache.shiro.authc.AuthenticationInfo in project zeppelin by apache.
the class PamRealmTest method testDoGetAuthenticationInfo.
@Test
public void testDoGetAuthenticationInfo() {
PamRealm realm = new PamRealm();
realm.setService("sshd");
String pam_user = System.getenv("PAM_USER");
String pam_pass = System.getenv("PAM_PASS");
assumeTrue(pam_user != null);
assumeTrue(pam_pass != null);
// mock shiro auth token
UsernamePasswordToken authToken = mock(UsernamePasswordToken.class);
when(authToken.getUsername()).thenReturn(pam_user);
when(authToken.getPassword()).thenReturn(pam_pass.toCharArray());
when(authToken.getCredentials()).thenReturn(pam_pass);
AuthenticationInfo authInfo = realm.doGetAuthenticationInfo(authToken);
assertTrue(authInfo.getCredentials() != null);
}
Aggregations