Skip to content

Commit

Permalink
Rename main plugin methods to clarify concepts
Browse files Browse the repository at this point in the history
- getAuthenticationInfo -> authenticate
- getAuthorizationInfo -> authorize
- getAuthInfo -> authenticateAndAuthorize
  • Loading branch information
henriknyman committed Sep 16, 2016
1 parent 6d4b69a commit bd13995
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 61 deletions.
Expand Up @@ -145,7 +145,7 @@ protected AuthorizationInfo doGetAuthorizationInfo( PrincipalCollection principa
if ( authorizationPlugin != null )
{
org.neo4j.server.security.enterprise.auth.plugin.spi.AuthorizationInfo authorizationInfo =
authorizationPlugin.getAuthorizationInfo( getPrincipalAndRealmCollection( principals ) );
authorizationPlugin.authorize( getPrincipalAndRealmCollection( principals ) );
if ( authorizationInfo != null )
{
return PluginAuthorizationInfo.create( authorizationInfo );
Expand All @@ -163,7 +163,7 @@ protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token
{
if ( authPlugin != null )
{
AuthInfo authInfo = authPlugin.getAuthInfo( ((ShiroAuthToken) token).getAuthTokenMap() );
AuthInfo authInfo = authPlugin.authenticateAndAuthorize( ((ShiroAuthToken) token).getAuthTokenMap() );
if ( authInfo != null )
{
PluginAuthInfo pluginAuthInfo =
Expand All @@ -177,7 +177,7 @@ protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token
else if ( authenticationPlugin != null )
{
org.neo4j.server.security.enterprise.auth.plugin.spi.AuthenticationInfo authenticationInfo =
authenticationPlugin.getAuthenticationInfo( ((ShiroAuthToken) token).getAuthTokenMap() );
authenticationPlugin.authenticate( ((ShiroAuthToken) token).getAuthTokenMap() );
if ( authenticationInfo != null )
{
return PluginAuthenticationInfo.createCacheable( authenticationInfo, getName(), secureHasher );
Expand Down
Expand Up @@ -30,7 +30,7 @@
*
* <p>NOTE: If authentication caching is enabled the result type <tt>CacheableAuthInfo</tt> should be used instead.
*
* @see AuthPlugin#getAuthInfo(Map)
* @see AuthPlugin#authenticateAndAuthorize(Map)
* @see CacheableAuthInfo
*/
public interface AuthInfo extends Serializable
Expand Down
Expand Up @@ -37,7 +37,7 @@ public interface AuthPlugin extends RealmLifecycle
/**
* TODO
*/
AuthInfo getAuthInfo( Map<String,Object> authToken ) throws AuthenticationException;
AuthInfo authenticateAndAuthorize( Map<String,Object> authToken ) throws AuthenticationException;

abstract class Adapter implements AuthPlugin
{
Expand Down
Expand Up @@ -25,7 +25,7 @@
/**
* An object that can be returned as the result of successful authentication by an <tt>AuthenticationPlugin</tt>.
*
* @see AuthenticationPlugin#getAuthenticationInfo(Map)
* @see AuthenticationPlugin#authenticate(Map)
*/
public interface AuthenticationInfo extends Serializable
{
Expand Down
Expand Up @@ -36,7 +36,7 @@ public interface AuthenticationPlugin extends RealmLifecycle
/**
* TODO
*/
AuthenticationInfo getAuthenticationInfo( Map<String,Object> authToken );
AuthenticationInfo authenticate( Map<String,Object> authToken );

abstract class Adapter implements AuthenticationPlugin
{
Expand Down
Expand Up @@ -25,7 +25,7 @@
/**
* An object that can be returned as the result of authorization by an <tt>AuthorizationPlugin</tt>.
*
* @see AuthorizationPlugin#getAuthorizationInfo(Collection)
* @see AuthorizationPlugin#authorize(Collection)
*/
public interface AuthorizationInfo extends Serializable
{
Expand Down
Expand Up @@ -58,7 +58,7 @@ public String realm()
/**
* TODO
*/
AuthorizationInfo getAuthorizationInfo( Collection<PrincipalAndRealm> principals );
AuthorizationInfo authorize( Collection<PrincipalAndRealm> principals );

class Adapter implements AuthorizationPlugin
{
Expand All @@ -70,7 +70,7 @@ public String name()
}

@Override
public AuthorizationInfo getAuthorizationInfo( Collection<PrincipalAndRealm> principals )
public AuthorizationInfo authorize( Collection<PrincipalAndRealm> principals )
{
return null;
}
Expand Down
Expand Up @@ -40,7 +40,7 @@
* <p>NOTE: Caching of the authorization info (assigned roles) does not require the use of a <tt>CacheableAuthInfo</tt>
* but will work fine with a regular <tt>AuthInfo</tt>.
*
* @see AuthPlugin#getAuthInfo(Map)
* @see AuthPlugin#authenticateAndAuthorize(Map)
* @see org.neo4j.server.security.enterprise.auth.plugin.api.RealmOperations#setAuthenticationCachingEnabled(boolean)
* @see AuthInfo
* @see AuthenticationPlugin
Expand Down Expand Up @@ -73,7 +73,7 @@ public interface CacheableAuthInfo extends AuthInfo
* @return credentials that can be cached
*
* @see org.neo4j.server.security.enterprise.auth.plugin.api.AuthToken#CREDENTIALS
* @see AuthPlugin#getAuthInfo(Map)
* @see AuthPlugin#authenticateAndAuthorize(Map)
*/
byte[] getCredentials();

Expand Down
Expand Up @@ -33,7 +33,7 @@
*
* <p>NOTE: Caching only occurs if it is explicitly enabled by the plugin.
*
* @see AuthenticationPlugin#getAuthenticationInfo(Map)
* @see AuthenticationPlugin#authenticate(Map)
* @see org.neo4j.server.security.enterprise.auth.plugin.api.RealmOperations#setAuthenticationCachingEnabled(boolean)
* @see CustomCacheableAuthenticationInfo
*/
Expand Down Expand Up @@ -63,7 +63,7 @@ public interface CacheableAuthenticationInfo extends AuthenticationInfo
* @return credentials that can be cached
*
* @see org.neo4j.server.security.enterprise.auth.plugin.api.AuthToken#CREDENTIALS
* @see AuthenticationPlugin#getAuthenticationInfo(Map)
* @see AuthenticationPlugin#authenticate(Map)
*/
byte[] getCredentials();

Expand Down
Expand Up @@ -35,7 +35,7 @@
*
* <p>NOTE: Caching only occurs if it is explicitly enabled by the plugin.
*
* @see AuthenticationPlugin#getAuthenticationInfo(Map)
* @see AuthenticationPlugin#authenticate(Map)
* @see org.neo4j.server.security.enterprise.auth.plugin.api.RealmOperations#setAuthenticationCachingEnabled(boolean)
* @see CacheableAuthenticationInfo
*/
Expand Down
Expand Up @@ -37,11 +37,10 @@
import org.neo4j.server.security.enterprise.auth.plugin.api.AuthToken;
import org.neo4j.server.security.enterprise.auth.plugin.api.AuthenticationException;
import org.neo4j.server.security.enterprise.auth.plugin.api.PredefinedRoles;
import org.neo4j.server.security.enterprise.auth.plugin.api.RealmOperations;
import org.neo4j.server.security.enterprise.auth.plugin.spi.AuthInfo;
import org.neo4j.server.security.enterprise.auth.plugin.spi.AuthPlugin;

public class LdapGroupHasUsersAuthPlugin implements AuthPlugin
public class LdapGroupHasUsersAuthPlugin extends AuthPlugin.Adapter
{
private static final String GROUP_SEARCH_BASE = "ou=groups,dc=example,dc=com";
private static final String GROUP_SEARCH_FILTER = "(&(objectClass=posixGroup)(memberUid={0}))";
Expand All @@ -54,7 +53,7 @@ public String name()
}

@Override
public AuthInfo getAuthInfo( Map<String,Object> authToken ) throws AuthenticationException
public AuthInfo authenticateAndAuthorize( Map<String,Object> authToken ) throws AuthenticationException
{
try
{
Expand All @@ -72,26 +71,6 @@ public AuthInfo getAuthInfo( Map<String,Object> authToken ) throws Authenticatio
}
}

@Override
public void initialize( RealmOperations realmOperations ) throws Throwable
{
}

@Override
public void start() throws Throwable
{
}

@Override
public void stop() throws Throwable
{
}

@Override
public void shutdown() throws Throwable
{
}

private LdapContext authenticate( String username, String password ) throws NamingException
{
Hashtable<String,Object> env = new Hashtable<>();
Expand Down
Expand Up @@ -19,7 +19,6 @@
*/
package org.neo4j.server.security.enterprise.auth.plugin;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

Expand All @@ -38,27 +37,14 @@ public String name()
}

@Override
public AuthInfo getAuthInfo( Map<String,Object> authToken )
public AuthInfo authenticateAndAuthorize( Map<String,Object> authToken )
{
String principal = (String) authToken.get( AuthToken.PRINCIPAL );
String credentials = (String) authToken.get( AuthToken.CREDENTIALS );

if ( principal.equals( "neo4j" ) && credentials.equals( "neo4j" ) )
{
return new AuthInfo()
{
@Override
public Object getPrincipal()
{
return "neo4j";
}

@Override
public Collection<String> getRoles()
{
return Collections.singleton( PredefinedRoles.READER );
}
};
return AuthInfo.of( "neo4j", Collections.singleton( PredefinedRoles.READER ) );
}
return null;
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public String name()
}

@Override
public AuthenticationInfo getAuthenticationInfo( Map<String,Object> authToken )
public AuthenticationInfo authenticate( Map<String,Object> authToken )
{
String principal = (String) authToken.get( AuthToken.PRINCIPAL );
String credentials = (String) authToken.get( AuthToken.CREDENTIALS );
Expand Down
Expand Up @@ -35,7 +35,7 @@ public String name()
}

@Override
public AuthorizationInfo getAuthorizationInfo( Collection<PrincipalAndRealm> principals )
public AuthorizationInfo authorize( Collection<PrincipalAndRealm> principals )
{
if ( principals.stream().anyMatch( p -> "neo4j".equals( p.principal() ) ) )
{
Expand Down
Expand Up @@ -38,7 +38,7 @@ public String name()
}

@Override
public AuthInfo getAuthInfo( Map<String,Object> authToken )
public AuthInfo authenticateAndAuthorize( Map<String,Object> authToken )
{
getAuthInfoCallCount.incrementAndGet();

Expand Down
Expand Up @@ -36,7 +36,7 @@ public String name()
}

@Override
public AuthenticationInfo getAuthenticationInfo( Map<String,Object> authToken )
public AuthenticationInfo authenticate( Map<String,Object> authToken )
{
getAuthenticationInfoCallCount.incrementAndGet();

Expand Down
Expand Up @@ -40,7 +40,7 @@ public String name()
}

@Override
public AuthenticationInfo getAuthenticationInfo( Map<String,Object> authToken )
public AuthenticationInfo authenticate( Map<String,Object> authToken )
{
String principal = (String) authToken.get( AuthToken.PRINCIPAL );
String credentials = (String) authToken.get( AuthToken.CREDENTIALS );
Expand All @@ -53,7 +53,7 @@ public AuthenticationInfo getAuthenticationInfo( Map<String,Object> authToken )
}

@Override
public AuthorizationInfo getAuthorizationInfo( Collection<PrincipalAndRealm> principals )
public AuthorizationInfo authorize( Collection<PrincipalAndRealm> principals )
{
if ( principals.stream().anyMatch( p -> "neo4j".equals( p.principal() ) ) )
{
Expand Down
Expand Up @@ -37,7 +37,7 @@ public String name()
}

@Override
public AuthenticationInfo getAuthenticationInfo( Map<String,Object> authToken )
public AuthenticationInfo authenticate( Map<String,Object> authToken )
{
getAuthenticationInfoCallCount.incrementAndGet();

Expand Down

0 comments on commit bd13995

Please sign in to comment.