Search in sources :

Example 6 with SimpleHash

use of org.apache.shiro.crypto.hash.SimpleHash in project neo4j by neo4j.

the class LdapRealm method createAuthenticationInfo.

@Override
protected AuthenticationInfo createAuthenticationInfo(AuthenticationToken token, Object ldapPrincipal, Object ldapCredentials, LdapContext ldapContext) throws NamingException {
    // the search for groups directly here while the user's authenticated ldap context is open.
    if (authorizationEnabled && !useSystemAccountForAuthorization) {
        String username = (String) token.getPrincipal();
        Set<String> roleNames = findRoleNamesForUser(username, ldapContext);
        cacheAuthorizationInfo(username, roleNames);
    }
    if (isAuthenticationCachingEnabled()) {
        SimpleHash hashedCredentials = secureHasher.hash(((String) token.getCredentials()).getBytes());
        return new ShiroAuthenticationInfo(token.getPrincipal(), hashedCredentials.getBytes(), hashedCredentials.getSalt(), getName(), AuthenticationResult.SUCCESS);
    } else {
        return new ShiroAuthenticationInfo(token.getPrincipal(), getName(), AuthenticationResult.SUCCESS);
    }
}
Also used : SimpleHash(org.apache.shiro.crypto.hash.SimpleHash)

Example 7 with SimpleHash

use of org.apache.shiro.crypto.hash.SimpleHash in project neo4j by neo4j.

the class PluginAuthenticationInfoTest method shouldCreateCorrectAuthenticationInfoFromCustomCacheable.

@Test
public void shouldCreateCorrectAuthenticationInfoFromCustomCacheable() {
    SecureHasher hasher = mock(SecureHasher.class);
    when(hasher.hash(Matchers.any())).thenReturn(new SimpleHash("some-hash"));
    PluginAuthenticationInfo internalAuthInfo = PluginAuthenticationInfo.createCacheable(CustomCacheableAuthenticationInfo.of("thePrincipal", ignoredAuthToken -> true), "theRealm", hasher);
    assertThat((List<String>) internalAuthInfo.getPrincipals().asList(), containsInAnyOrder("thePrincipal"));
}
Also used : List(java.util.List) CacheableAuthenticationInfo(org.neo4j.server.security.enterprise.auth.plugin.spi.CacheableAuthenticationInfo) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers(org.mockito.Matchers) Test(org.junit.Test) SecureHasher(org.neo4j.server.security.enterprise.auth.SecureHasher) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Mockito.when(org.mockito.Mockito.when) SimpleHash(org.apache.shiro.crypto.hash.SimpleHash) AuthenticationInfo(org.neo4j.server.security.enterprise.auth.plugin.spi.AuthenticationInfo) CustomCacheableAuthenticationInfo(org.neo4j.server.security.enterprise.auth.plugin.spi.CustomCacheableAuthenticationInfo) Mockito.mock(org.mockito.Mockito.mock) SecureHasher(org.neo4j.server.security.enterprise.auth.SecureHasher) SimpleHash(org.apache.shiro.crypto.hash.SimpleHash) Test(org.junit.Test)

Aggregations

SimpleHash (org.apache.shiro.crypto.hash.SimpleHash)7 ByteSource (org.apache.shiro.util.ByteSource)3 DateTime (org.joda.time.DateTime)2 Test (org.junit.Test)2 SecurityApiException (org.killbill.billing.security.SecurityApiException)2 SecureHasher (org.neo4j.server.security.enterprise.auth.SecureHasher)2 Handle (org.skife.jdbi.v2.Handle)2 TransactionStatus (org.skife.jdbi.v2.TransactionStatus)2 List (java.util.List)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)1 EntityPersistenceException (org.killbill.billing.entity.EntityPersistenceException)1 TenantApiException (org.killbill.billing.tenant.api.TenantApiException)1 EntitySqlDaoWrapperFactory (org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperFactory)1 Matchers (org.mockito.Matchers)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 AuthenticationInfo (org.neo4j.server.security.enterprise.auth.plugin.spi.AuthenticationInfo)1 CacheableAuthInfo (org.neo4j.server.security.enterprise.auth.plugin.spi.CacheableAuthInfo)1 CacheableAuthenticationInfo (org.neo4j.server.security.enterprise.auth.plugin.spi.CacheableAuthenticationInfo)1