Search in sources :

Example 6 with AuthenticationInfo

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));
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) Test(org.testng.annotations.Test)

Example 7 with 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;
    }
}
Also used : AuthProviderTimeoutException(org.neo4j.graphdb.security.AuthProviderTimeoutException) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) NamingException(javax.naming.NamingException) InvalidAuthTokenException(org.neo4j.kernel.api.security.exception.InvalidAuthTokenException) AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) SocketTimeoutException(java.net.SocketTimeoutException) AuthProviderTimeoutException(org.neo4j.graphdb.security.AuthProviderTimeoutException) IOException(java.io.IOException) AuthProviderFailedException(org.neo4j.graphdb.security.AuthProviderFailedException) AuthorizationException(org.apache.shiro.authz.AuthorizationException) CommunicationException(javax.naming.CommunicationException)

Example 8 with AuthenticationInfo

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);
}
Also used : AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) Realm(org.apache.shiro.realm.Realm) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) Test(org.junit.Test)

Example 9 with AuthenticationInfo

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());
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Element(org.w3c.dom.Element) BaseAuthenticationToken(org.codice.ddf.security.handler.api.BaseAuthenticationToken) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with AuthenticationInfo

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());
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) BaseAuthenticationToken(org.codice.ddf.security.handler.api.BaseAuthenticationToken) BSTAuthenticationToken(org.codice.ddf.security.handler.api.BSTAuthenticationToken) SAMLAuthenticationToken(org.codice.ddf.security.handler.api.SAMLAuthenticationToken) Element(org.w3c.dom.Element) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)10 Test (org.junit.Test)5 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)4 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)3 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)3 Realm (org.apache.shiro.realm.Realm)3 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)2 BaseAuthenticationToken (org.codice.ddf.security.handler.api.BaseAuthenticationToken)2 Ignore (org.junit.Ignore)2 InvalidAuthTokenException (org.neo4j.kernel.api.security.exception.InvalidAuthTokenException)2 Test (org.testng.annotations.Test)2 Element (org.w3c.dom.Element)2 Subject (ddf.security.Subject)1 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 Properties (java.util.Properties)1 CommunicationException (javax.naming.CommunicationException)1 NamingException (javax.naming.NamingException)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 AuthorizationException (org.apache.shiro.authz.AuthorizationException)1