Skip to content

Commit

Permalink
Add AuthenticationException to plugin api
Browse files Browse the repository at this point in the history
- Move RealmLifeCycle to plugin spi
  • Loading branch information
henriknyman committed Sep 16, 2016
1 parent 06d287a commit 761f1b9
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 26 deletions.
Expand Up @@ -55,6 +55,7 @@
import org.neo4j.server.security.auth.UserRepository;
import org.neo4j.server.security.auth.exception.ConcurrentModificationException;
import org.neo4j.server.security.enterprise.auth.plugin.api.PredefinedRoles;
import org.neo4j.server.security.enterprise.auth.plugin.spi.RealmLifecycle;

import static java.lang.String.format;

Expand Down
Expand Up @@ -44,6 +44,7 @@
import org.neo4j.kernel.api.security.exception.InvalidAuthTokenException;
import org.neo4j.kernel.enterprise.api.security.EnterpriseAuthSubject;
import org.neo4j.kernel.impl.enterprise.SecurityLog;
import org.neo4j.server.security.enterprise.auth.plugin.spi.RealmLifecycle;

import static org.neo4j.helpers.Strings.escape;

Expand Down
Expand Up @@ -29,12 +29,12 @@
import org.apache.shiro.subject.PrincipalCollection;

import org.neo4j.server.security.enterprise.auth.PredefinedRolesBuilder;
import org.neo4j.server.security.enterprise.auth.RealmLifecycle;
import org.neo4j.server.security.enterprise.auth.ShiroAuthToken;
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.AuthenticationPlugin;
import org.neo4j.server.security.enterprise.auth.plugin.spi.AuthorizationPlugin;
import org.neo4j.server.security.enterprise.auth.plugin.spi.RealmLifecycle;

public class PluginRealm extends AuthorizingRealm implements RealmLifecycle
{
Expand Down Expand Up @@ -85,27 +85,34 @@ protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token
{
if ( token instanceof ShiroAuthToken )
{
if ( authPlugin != null )
try
{
AuthInfo authInfo = authPlugin.getAuthInfo( ((ShiroAuthToken) token).getAuthTokenMap() );
if ( authInfo != null )
if ( authPlugin != null )
{
PluginAuthInfo pluginAuthInfo = PluginAuthInfo.create( authInfo, getName() );
AuthInfo authInfo = authPlugin.getAuthInfo( ((ShiroAuthToken) token).getAuthTokenMap() );
if ( authInfo != null )
{
PluginAuthInfo pluginAuthInfo = PluginAuthInfo.create( authInfo, getName() );

cacheAuthorizationInfo( pluginAuthInfo );
cacheAuthorizationInfo( pluginAuthInfo );

return pluginAuthInfo;
return pluginAuthInfo;
}
}
}
else if ( authenticationPlugin != null )
{
org.neo4j.server.security.enterprise.auth.plugin.spi.AuthenticationInfo authenticationInfo =
authenticationPlugin.getAuthenticationInfo( ((ShiroAuthToken) token).getAuthTokenMap() );
if ( authenticationInfo != null )
else if ( authenticationPlugin != null )
{
return PluginAuthenticationInfo.create( authenticationInfo, getName() );
org.neo4j.server.security.enterprise.auth.plugin.spi.AuthenticationInfo authenticationInfo =
authenticationPlugin.getAuthenticationInfo( ((ShiroAuthToken) token).getAuthTokenMap() );
if ( authenticationInfo != null )
{
return PluginAuthenticationInfo.create( authenticationInfo, getName() );
}
}
}
catch ( org.neo4j.server.security.enterprise.auth.plugin.api.AuthenticationException e )
{
throw new AuthenticationException( e.getMessage(), e.getCause() );
}
}
return null;
}
Expand Down
Expand Up @@ -17,12 +17,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.server.security.enterprise.auth;
package org.neo4j.server.security.enterprise.auth.plugin.api;

public interface RealmLifecycle
public class AuthenticationException extends Exception
{
void initialize() throws Throwable;
void start() throws Throwable;
void stop() throws Throwable;
void shutdown() throws Throwable;
}
Expand Up @@ -21,7 +21,7 @@

import java.util.Map;

import org.neo4j.server.security.enterprise.auth.RealmLifecycle;
import org.neo4j.server.security.enterprise.auth.plugin.api.AuthenticationException;

/**
* TODO
Expand All @@ -31,5 +31,5 @@ public interface AuthPlugin extends RealmLifecycle
/**
* TODO
*/
AuthInfo getAuthInfo( Map<String,Object> authToken );
AuthInfo getAuthInfo( Map<String,Object> authToken ) throws AuthenticationException;
}
Expand Up @@ -21,8 +21,6 @@

import java.util.Map;

import org.neo4j.server.security.enterprise.auth.RealmLifecycle;

/**
* TODO
*/
Expand Down
Expand Up @@ -21,8 +21,6 @@

import java.util.Collection;

import org.neo4j.server.security.enterprise.auth.RealmLifecycle;

/**
* TODO
*/
Expand Down
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.server.security.enterprise.auth.plugin.spi;

public interface RealmLifecycle
{
void initialize() throws Throwable;
void start() throws Throwable;
void stop() throws Throwable;
void shutdown() throws Throwable;

class Adapter implements RealmLifecycle
{
@Override
public void initialize() throws Throwable
{
}

@Override
public void start() throws Throwable
{
}

@Override
public void stop() throws Throwable
{
}

@Override
public void shutdown() throws Throwable
{
}
}
}

0 comments on commit 761f1b9

Please sign in to comment.