Skip to content

Commit

Permalink
Load auth manager in ha and core-edge
Browse files Browse the repository at this point in the history
  • Loading branch information
henriknyman committed May 11, 2016
1 parent 20a04a0 commit ac9b09f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 37 deletions.
Expand Up @@ -29,7 +29,6 @@
import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.DatabaseAvailability; import org.neo4j.kernel.DatabaseAvailability;
import org.neo4j.kernel.NeoStoreDataSource; import org.neo4j.kernel.NeoStoreDataSource;
import org.neo4j.kernel.api.security.AuthManager;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.api.SchemaWriteGuard; import org.neo4j.kernel.impl.api.SchemaWriteGuard;
import org.neo4j.kernel.impl.api.index.RemoveOrphanConstraintIndexesOnStartup; import org.neo4j.kernel.impl.api.index.RemoveOrphanConstraintIndexesOnStartup;
Expand Down Expand Up @@ -210,40 +209,6 @@ else if ( key.equals( "" ) )
throw new IllegalArgumentException( "No lock manager found with the name '" + key + "'." ); throw new IllegalArgumentException( "No lock manager found with the name '" + key + "'." );
} }


public static AuthManager createAuthManager( Config config, LogService logging )
{
boolean authEnabled = config.get( GraphDatabaseSettings.auth_enabled );
if ( !authEnabled )
{
return AuthManager.NO_AUTH;
}

String key = config.get( GraphDatabaseSettings.auth_manager );
for ( AuthManager.Factory candidate : Service.load( AuthManager.Factory.class ) )
{
String candidateId = candidate.getKeys().iterator().next();
if ( candidateId.equals( key ) )
{
return candidate.newInstance( config, logging.getUserLogProvider() );
}
else if ( key.equals( "" ) )
{
logging.getInternalLog( CommunityFacadeFactory.class )
.info( "No auth manager implementation specified, defaulting to '" + candidateId + "'" );
return candidate.newInstance( config, logging.getUserLogProvider() );
}
}

if ( key.equals( "" ) )
{
logging.getUserLog( CommunityFacadeFactory.class )
.error( "No auth manager implementation specified and no default could be loaded." );
throw new IllegalArgumentException( "No auth manager found." );
}

throw new IllegalArgumentException( "No auth manager found with the name '" + key + "'." );
}

protected TransactionHeaderInformationFactory createHeaderInformationFactory() protected TransactionHeaderInformationFactory createHeaderInformationFactory()
{ {
return TransactionHeaderInformationFactory.DEFAULT; return TransactionHeaderInformationFactory.DEFAULT;
Expand Down
Expand Up @@ -19,11 +19,12 @@
*/ */
package org.neo4j.kernel.impl.factory; package org.neo4j.kernel.impl.factory;


import java.io.File;

import org.neo4j.graphdb.DependencyResolver; import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.Service;
import org.neo4j.io.pagecache.IOLimiter; import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.kernel.NeoStoreDataSource; import org.neo4j.kernel.NeoStoreDataSource;
import org.neo4j.kernel.api.security.AuthManager;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.api.CommitProcessFactory; import org.neo4j.kernel.impl.api.CommitProcessFactory;
import org.neo4j.kernel.impl.api.SchemaWriteGuard; import org.neo4j.kernel.impl.api.SchemaWriteGuard;
Expand All @@ -34,6 +35,7 @@
import org.neo4j.kernel.impl.coreapi.CoreAPIAvailabilityGuard; import org.neo4j.kernel.impl.coreapi.CoreAPIAvailabilityGuard;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.Configuration; import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.Configuration;
import org.neo4j.kernel.impl.locking.Locks; import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.store.format.RecordFormats; import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory; import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory; import org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory;
Expand Down Expand Up @@ -102,4 +104,38 @@ protected EditionModule.SPI spi()
{ {
return null; return null;
} }

public static AuthManager createAuthManager( Config config, LogService logging )
{
boolean authEnabled = config.get( GraphDatabaseSettings.auth_enabled );
if ( !authEnabled )
{
return AuthManager.NO_AUTH;
}

String key = config.get( GraphDatabaseSettings.auth_manager );
for ( AuthManager.Factory candidate : Service.load( AuthManager.Factory.class ) )
{
String candidateId = candidate.getKeys().iterator().next();
if ( candidateId.equals( key ) )
{
return candidate.newInstance( config, logging.getUserLogProvider() );
}
else if ( key.equals( "" ) )
{
logging.getInternalLog( CommunityFacadeFactory.class )
.info( "No auth manager implementation specified, defaulting to '" + candidateId + "'" );
return candidate.newInstance( config, logging.getUserLogProvider() );
}
}

if ( key.equals( "" ) )
{
logging.getUserLog( CommunityFacadeFactory.class )
.error( "No auth manager implementation specified and no default could be loaded." );
throw new IllegalArgumentException( "No auth manager found." );
}

throw new IllegalArgumentException( "No auth manager found with the name '" + key + "'." );
}
} }
6 changes: 6 additions & 0 deletions enterprise/core-edge/pom.xml
Expand Up @@ -119,6 +119,12 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>


<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-security-enterprise</artifactId>
<version>${project.version}</version>
</dependency>

<dependency> <dependency>
<groupId>org.neo4j</groupId> <groupId>org.neo4j</groupId>
<artifactId>neo4j-logging</artifactId> <artifactId>neo4j-logging</artifactId>
Expand Down
Expand Up @@ -450,6 +450,8 @@ fileSystem, new File( clusterStateDirectory, "id-allocation-state" ), "id-alloca
dependencies.satisfyDependency( createKernelData( fileSystem, platformModule.pageCache, storeDir, dependencies.satisfyDependency( createKernelData( fileSystem, platformModule.pageCache, storeDir,
config, graphDatabaseFacade, life ) ); config, graphDatabaseFacade, life ) );


life.add( dependencies.satisfyDependency( createAuthManager( config, logging ) ) );

headerInformationFactory = createHeaderInformationFactory(); headerInformationFactory = createHeaderInformationFactory();


schemaWriteGuard = createSchemaWriteGuard(); schemaWriteGuard = createSchemaWriteGuard();
Expand Down
Expand Up @@ -119,6 +119,9 @@ public EnterpriseEdgeEditionModule( final PlatformModule platformModule,


life.add( dependencies.satisfyDependency( life.add( dependencies.satisfyDependency(
new DefaultKernelData( fileSystem, pageCache, storeDir, config, graphDatabaseFacade ) ) ); new DefaultKernelData( fileSystem, pageCache, storeDir, config, graphDatabaseFacade ) ) );

life.add( dependencies.satisfyDependency( createAuthManager( config, logging ) ) );

headerInformationFactory = TransactionHeaderInformationFactory.DEFAULT; headerInformationFactory = TransactionHeaderInformationFactory.DEFAULT;


schemaWriteGuard = () -> {}; schemaWriteGuard = () -> {};
Expand Down
5 changes: 5 additions & 0 deletions enterprise/ha/pom.xml
Expand Up @@ -100,6 +100,11 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-security-enterprise</artifactId>
<version>${project.version}</version>
</dependency>


<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
Expand Down
Expand Up @@ -478,6 +478,9 @@ public void elected( String role, InstanceId instanceId, URI electedMember )
dependencies.satisfyDependency( dependencies.satisfyDependency(
createKernelData( config, platformModule.graphDatabaseFacade, members, fs, platformModule.pageCache, createKernelData( config, platformModule.graphDatabaseFacade, members, fs, platformModule.pageCache,
storeDir, lastUpdateTime, lastTxIdGetter, life ) ); storeDir, lastUpdateTime, lastTxIdGetter, life ) );

life.add( dependencies.satisfyDependency( createAuthManager( config, logging ) ) );

commitProcessFactory = createCommitProcessFactory( dependencies, logging, monitors, config, paxosLife, commitProcessFactory = createCommitProcessFactory( dependencies, logging, monitors, config, paxosLife,
clusterClient, members, platformModule.jobScheduler, master, requestContextFactory, clusterClient, members, platformModule.jobScheduler, master, requestContextFactory,
componentSwitcherContainer, logEntryReader ); componentSwitcherContainer, logEntryReader );
Expand Down

0 comments on commit ac9b09f

Please sign in to comment.