use of org.apache.shiro.authc.AuthenticationInfo in project killbill by killbill.
the class TestDefaultTenantDao method testWeCanStoreAndMatchCredentials.
@Test(groups = "slow")
public void testWeCanStoreAndMatchCredentials() throws Exception {
final DefaultTenant tenant = new DefaultTenant(UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString());
tenantDao.create(new TenantModelDao(tenant), internalCallContext);
// Verify we can retrieve it
Assert.assertEquals(tenantDao.getTenantByApiKey(tenant.getApiKey()).getId(), tenant.getId());
// Verify we can authenticate against it
final AuthenticationInfo authenticationInfo = tenantDao.getAuthenticationInfoForTenant(tenant.getId());
// Good combo
final AuthenticationToken goodToken = new UsernamePasswordToken(tenant.getApiKey(), tenant.getApiSecret());
Assert.assertTrue(KillbillCredentialsMatcher.getCredentialsMatcher(securityConfig).doCredentialsMatch(goodToken, authenticationInfo));
// Bad combo
final AuthenticationToken badToken = new UsernamePasswordToken(tenant.getApiKey(), tenant.getApiSecret() + "T");
Assert.assertFalse(KillbillCredentialsMatcher.getCredentialsMatcher(securityConfig).doCredentialsMatch(badToken, authenticationInfo));
}
use of org.apache.shiro.authc.AuthenticationInfo in project neo4j by neo4j.
the class LdapRealm method queryForAuthenticationInfo.
@Override
protected AuthenticationInfo queryForAuthenticationInfo(AuthenticationToken token, LdapContextFactory ldapContextFactory) throws NamingException {
if (authenticationEnabled) {
String serverString = server((JndiLdapContextFactory) ldapContextFactory);
try {
AuthenticationInfo info = useStartTls ? queryForAuthenticationInfoUsingStartTls(token, ldapContextFactory) : super.queryForAuthenticationInfo(token, ldapContextFactory);
securityLog.debug(withRealm("Authenticated user '%s' against %s", token.getPrincipal(), serverString));
return info;
} catch (Exception e) {
securityLog.error(withRealm("Failed to authenticate user '%s' against %s: %s", token.getPrincipal(), serverString, e.getMessage()));
if (isExceptionAnLdapConnectionTimeout(e)) {
securityLog.error(withRealm("LDAP connection to %s timed out.", serverString));
throw new AuthProviderTimeoutException(LDAP_CONNECTION_TIMEOUT_CLIENT_MESSAGE, e);
} else if (isExceptionAnLdapReadTimeout(e)) {
securityLog.error(withRealm("LDAP response from %s timed out.", serverString));
throw new AuthProviderTimeoutException(LDAP_READ_TIMEOUT_CLIENT_MESSAGE, e);
}
// This exception will be caught and rethrown by Shiro, and then by us, so we do not need to wrap it here
throw e;
}
} else {
return null;
}
}
use of org.apache.shiro.authc.AuthenticationInfo in project ddf by codice.
the class SecurityManagerImplTest method testAuthTokenNoRealm.
/**
* Test to check for failure when no realms are added.
*
* @throws SecurityServiceException
*/
@Test
public void testAuthTokenNoRealm() throws SecurityServiceException {
thrown.expect(org.apache.shiro.authc.AuthenticationException.class);
thrown.expectMessage("Authentication failed for token submission");
AuthenticationToken token = mock(AuthenticationToken.class);
when(token.getCredentials()).thenReturn("testUser");
AuthenticationInfo info = mock(AuthenticationInfo.class);
Realm realm = mock(Realm.class);
when(realm.getAuthenticationInfo(token)).thenReturn(info);
SecurityManagerImpl manager = new SecurityManagerImpl();
manager.getSubject(token);
}
use of org.apache.shiro.authc.AuthenticationInfo in project ddf by codice.
the class TestStsRealm method testDoGetAuthenticationInfoBase.
@Ignore
@Test
public void testDoGetAuthenticationInfoBase() throws ParserConfigurationException, SAXException, IOException {
Element issuedAssertion = this.readDocument("/saml.xml").getDocumentElement();
String assertionId = issuedAssertion.getAttributeNodeNS(null, "ID").getNodeValue();
final SecurityToken token = new SecurityToken(assertionId, issuedAssertion, null);
StsRealm realm = new StsRealm() {
protected SecurityToken requestSecurityToken(Object obj) {
return token;
}
protected STSClient configureStsClient() {
return null;
}
};
BaseAuthenticationToken authenticationToken = mock(BaseAuthenticationToken.class);
when(authenticationToken.getCredentialsAsXMLString()).thenReturn("creds");
AuthenticationInfo authenticationInfo = realm.doGetAuthenticationInfo(authenticationToken);
assertNotNull(authenticationInfo.getCredentials());
assertNotNull(authenticationInfo.getPrincipals());
}
use of org.apache.shiro.authc.AuthenticationInfo in project ddf by codice.
the class TestStsRealm method testDoGetAuthenticationInfoSAML.
@Ignore
@Test
public void testDoGetAuthenticationInfoSAML() throws ParserConfigurationException, SAXException, IOException {
StsRealm realm = new StsRealm() {
protected SecurityToken renewSecurityToken(SecurityToken securityToken) {
return securityToken;
}
protected STSClient configureStsClient() {
return null;
}
};
Element issuedAssertion = this.readDocument("/saml.xml").getDocumentElement();
String assertionId = issuedAssertion.getAttributeNodeNS(null, "ID").getNodeValue();
SecurityToken token = new SecurityToken(assertionId, issuedAssertion, null);
AuthenticationToken authenticationToken = mock(SAMLAuthenticationToken.class);
when(authenticationToken.getCredentials()).thenReturn(token);
AuthenticationInfo authenticationInfo = realm.doGetAuthenticationInfo(authenticationToken);
assertNotNull(authenticationInfo.getCredentials());
assertNotNull(authenticationInfo.getPrincipals());
}
Aggregations