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 ) if ( authorizationPlugin != null )
{ {
org.neo4j.server.security.enterprise.auth.plugin.spi.AuthorizationInfo authorizationInfo = org.neo4j.server.security.enterprise.auth.plugin.spi.AuthorizationInfo authorizationInfo =
authorizationPlugin.getAuthorizationInfo( getPrincipalAndRealmCollection( principals ) ); authorizationPlugin.authorize( getPrincipalAndRealmCollection( principals ) );
if ( authorizationInfo != null ) if ( authorizationInfo != null )
{ {
return PluginAuthorizationInfo.create( authorizationInfo ); return PluginAuthorizationInfo.create( authorizationInfo );
Expand All @@ -163,7 +163,7 @@ protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token
{ {
if ( authPlugin != null ) if ( authPlugin != null )
{ {
AuthInfo authInfo = authPlugin.getAuthInfo( ((ShiroAuthToken) token).getAuthTokenMap() ); AuthInfo authInfo = authPlugin.authenticateAndAuthorize( ((ShiroAuthToken) token).getAuthTokenMap() );
if ( authInfo != null ) if ( authInfo != null )
{ {
PluginAuthInfo pluginAuthInfo = PluginAuthInfo pluginAuthInfo =
Expand All @@ -177,7 +177,7 @@ protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token
else if ( authenticationPlugin != null ) else if ( authenticationPlugin != null )
{ {
org.neo4j.server.security.enterprise.auth.plugin.spi.AuthenticationInfo authenticationInfo = org.neo4j.server.security.enterprise.auth.plugin.spi.AuthenticationInfo authenticationInfo =
authenticationPlugin.getAuthenticationInfo( ((ShiroAuthToken) token).getAuthTokenMap() ); authenticationPlugin.authenticate( ((ShiroAuthToken) token).getAuthTokenMap() );
if ( authenticationInfo != null ) if ( authenticationInfo != null )
{ {
return PluginAuthenticationInfo.createCacheable( authenticationInfo, getName(), secureHasher ); 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. * <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 * @see CacheableAuthInfo
*/ */
public interface AuthInfo extends Serializable public interface AuthInfo extends Serializable
Expand Down
Expand Up @@ -37,7 +37,7 @@ public interface AuthPlugin extends RealmLifecycle
/** /**
* TODO * TODO
*/ */
AuthInfo getAuthInfo( Map<String,Object> authToken ) throws AuthenticationException; AuthInfo authenticateAndAuthorize( Map<String,Object> authToken ) throws AuthenticationException;


abstract class Adapter implements AuthPlugin 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>. * 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 public interface AuthenticationInfo extends Serializable
{ {
Expand Down
Expand Up @@ -36,7 +36,7 @@ public interface AuthenticationPlugin extends RealmLifecycle
/** /**
* TODO * TODO
*/ */
AuthenticationInfo getAuthenticationInfo( Map<String,Object> authToken ); AuthenticationInfo authenticate( Map<String,Object> authToken );


abstract class Adapter implements AuthenticationPlugin 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>. * 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 public interface AuthorizationInfo extends Serializable
{ {
Expand Down
Expand Up @@ -58,7 +58,7 @@ public String realm()
/** /**
* TODO * TODO
*/ */
AuthorizationInfo getAuthorizationInfo( Collection<PrincipalAndRealm> principals ); AuthorizationInfo authorize( Collection<PrincipalAndRealm> principals );


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


@Override @Override
public AuthorizationInfo getAuthorizationInfo( Collection<PrincipalAndRealm> principals ) public AuthorizationInfo authorize( Collection<PrincipalAndRealm> principals )
{ {
return null; 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> * <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>. * 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 org.neo4j.server.security.enterprise.auth.plugin.api.RealmOperations#setAuthenticationCachingEnabled(boolean)
* @see AuthInfo * @see AuthInfo
* @see AuthenticationPlugin * @see AuthenticationPlugin
Expand Down Expand Up @@ -73,7 +73,7 @@ public interface CacheableAuthInfo extends AuthInfo
* @return credentials that can be cached * @return credentials that can be cached
* *
* @see org.neo4j.server.security.enterprise.auth.plugin.api.AuthToken#CREDENTIALS * @see org.neo4j.server.security.enterprise.auth.plugin.api.AuthToken#CREDENTIALS
* @see AuthPlugin#getAuthInfo(Map) * @see AuthPlugin#authenticateAndAuthorize(Map)
*/ */
byte[] getCredentials(); byte[] getCredentials();


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


Expand Down
Expand Up @@ -35,7 +35,7 @@
* *
* <p>NOTE: Caching only occurs if it is explicitly enabled by the plugin. * <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 org.neo4j.server.security.enterprise.auth.plugin.api.RealmOperations#setAuthenticationCachingEnabled(boolean)
* @see CacheableAuthenticationInfo * @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.AuthToken;
import org.neo4j.server.security.enterprise.auth.plugin.api.AuthenticationException; 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.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.AuthInfo;
import org.neo4j.server.security.enterprise.auth.plugin.spi.AuthPlugin; 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_BASE = "ou=groups,dc=example,dc=com";
private static final String GROUP_SEARCH_FILTER = "(&(objectClass=posixGroup)(memberUid={0}))"; private static final String GROUP_SEARCH_FILTER = "(&(objectClass=posixGroup)(memberUid={0}))";
Expand All @@ -54,7 +53,7 @@ public String name()
} }


@Override @Override
public AuthInfo getAuthInfo( Map<String,Object> authToken ) throws AuthenticationException public AuthInfo authenticateAndAuthorize( Map<String,Object> authToken ) throws AuthenticationException
{ {
try 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 private LdapContext authenticate( String username, String password ) throws NamingException
{ {
Hashtable<String,Object> env = new Hashtable<>(); Hashtable<String,Object> env = new Hashtable<>();
Expand Down
Expand Up @@ -19,7 +19,6 @@
*/ */
package org.neo4j.server.security.enterprise.auth.plugin; package org.neo4j.server.security.enterprise.auth.plugin;


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


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


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


if ( principal.equals( "neo4j" ) && credentials.equals( "neo4j" ) ) if ( principal.equals( "neo4j" ) && credentials.equals( "neo4j" ) )
{ {
return new AuthInfo() return AuthInfo.of( "neo4j", Collections.singleton( PredefinedRoles.READER ) );
{
@Override
public Object getPrincipal()
{
return "neo4j";
}

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


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


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


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


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


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


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


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


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


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


Expand Down

0 comments on commit bd13995

Please sign in to comment.