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);
}
}
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"));
}
Aggregations