Search in sources :

Example 1 with SecureHasher

use of org.neo4j.cypher.internal.security.SecureHasher in project neo4j by neo4j.

the class BasicSystemGraphRealmIT method setUp.

@BeforeEach
void setUp() {
    dbManager = new BasicSystemGraphRealmTestHelper.TestDatabaseManager(testDirectory);
    SecureHasher secureHasher = new SecureHasher();
    realmHelper = new SystemGraphRealmHelper(SystemGraphRealmHelper.makeSystemSupplier(dbManager), secureHasher);
    defaultConfig = Config.defaults();
    oldUsers = new InMemoryUserRepository();
    initialPassword = new InMemoryUserRepository();
}
Also used : SecureHasher(org.neo4j.cypher.internal.security.SecureHasher) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) SystemGraphRealmHelper(org.neo4j.server.security.systemgraph.SystemGraphRealmHelper) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SecureHasher

use of org.neo4j.cypher.internal.security.SecureHasher in project neo4j by neo4j.

the class SecurityContextDescriptionTest method setup.

@BeforeEach
void setup() throws Throwable {
    SystemGraphRealmHelper realmHelper = spy(new SystemGraphRealmHelper(null, new SecureHasher()));
    BasicSystemGraphRealm realm = new BasicSystemGraphRealm(realmHelper, new RateLimitedAuthenticationStrategy(Clocks.systemClock(), Config.defaults()));
    User user = new User.Builder("johan", credentialFor("bar")).withId("id").build();
    doReturn(user).when(realmHelper).getUser("johan");
    context = realm.login(authToken("johan", "bar"), EMBEDDED_CONNECTION).authorize(LoginContext.IdLookup.EMPTY, DEFAULT_DATABASE_NAME, CommunitySecurityLog.NULL_LOG);
}
Also used : User(org.neo4j.kernel.impl.security.User) SecureHasher(org.neo4j.cypher.internal.security.SecureHasher) BasicSystemGraphRealm(org.neo4j.server.security.systemgraph.BasicSystemGraphRealm) SystemGraphRealmHelper(org.neo4j.server.security.systemgraph.SystemGraphRealmHelper) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with SecureHasher

use of org.neo4j.cypher.internal.security.SecureHasher in project neo4j by neo4j.

the class UserSerialization method deserializeCredentials.

private static Credential deserializeCredentials(String part, int lineNumber) throws FormatException {
    String[] split = part.split(CREDENTIAL_SEPARATOR, -1);
    String algorithm = split[0];
    int iterations;
    String hasherVersion;
    if (split.length == 4) {
        iterations = Integer.parseInt(split[3]);
    } else if (split.length == 3) {
        iterations = LegacyCredential.ITERATIONS;
    } else {
        throw new FormatException(format("wrong number of credential fields [line %d]", lineNumber));
    }
    try {
        hasherVersion = SecureHasherConfigurations.getVersionForConfiguration(algorithm, iterations);
    } catch (InvalidArgumentException e) {
        throw new FormatException(format("unknown digest \"%s\" [line %d]:", part, lineNumber));
    }
    if (hasherVersion.equals("0")) {
        byte[] decodedPassword = HexString.decodeHexString(split[1]);
        byte[] decodedSalt = HexString.decodeHexString(split[2]);
        return new LegacyCredential(decodedSalt, decodedPassword);
    } else {
        return SystemGraphCredential.deserialize(part, new SecureHasher(hasherVersion));
    }
}
Also used : InvalidArgumentException(org.neo4j.exceptions.InvalidArgumentException) SecureHasher(org.neo4j.cypher.internal.security.SecureHasher) HexString(org.neo4j.string.HexString) FormatException(org.neo4j.cypher.internal.security.FormatException)

Example 4 with SecureHasher

use of org.neo4j.cypher.internal.security.SecureHasher in project neo4j by neo4j.

the class CommunitySecurityModule method setup.

@Override
public void setup() {
    Supplier<GraphDatabaseService> systemSupplier = () -> {
        DatabaseManager<?> databaseManager = globalDependencies.resolveDependency(DatabaseManager.class);
        return databaseManager.getDatabaseContext(NAMED_SYSTEM_DATABASE_ID).orElseThrow(() -> new RuntimeException("No database called `" + SYSTEM_DATABASE_NAME + "` was found.")).databaseFacade();
    };
    authManager = new BasicSystemGraphRealm(new SystemGraphRealmHelper(systemSupplier, new SecureHasher()), createAuthenticationStrategy(config));
    registerProcedure(globalDependencies.resolveDependency(GlobalProcedures.class), logProvider.getLog(getClass()), AuthProcedures.class, null);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) DatabaseManager(org.neo4j.dbms.database.DatabaseManager) SecureHasher(org.neo4j.cypher.internal.security.SecureHasher) BasicSystemGraphRealm(org.neo4j.server.security.systemgraph.BasicSystemGraphRealm) SystemGraphRealmHelper(org.neo4j.server.security.systemgraph.SystemGraphRealmHelper) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures)

Example 5 with SecureHasher

use of org.neo4j.cypher.internal.security.SecureHasher in project neo4j by neo4j.

the class BasicSystemGraphRealmTest method setUp.

@BeforeEach
void setUp() {
    authStrategy = mock(AuthenticationStrategy.class);
    realmHelper = spy(new SystemGraphRealmHelper(null, new SecureHasher()));
    realm = new BasicSystemGraphRealm(realmHelper, authStrategy);
}
Also used : SecureHasher(org.neo4j.cypher.internal.security.SecureHasher) BasicSystemGraphRealm(org.neo4j.server.security.systemgraph.BasicSystemGraphRealm) SystemGraphRealmHelper(org.neo4j.server.security.systemgraph.SystemGraphRealmHelper) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SecureHasher (org.neo4j.cypher.internal.security.SecureHasher)6 SystemGraphRealmHelper (org.neo4j.server.security.systemgraph.SystemGraphRealmHelper)5 BasicSystemGraphRealm (org.neo4j.server.security.systemgraph.BasicSystemGraphRealm)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 User (org.neo4j.kernel.impl.security.User)2 Config (org.neo4j.configuration.Config)1 FormatException (org.neo4j.cypher.internal.security.FormatException)1 DatabaseManager (org.neo4j.dbms.database.DatabaseManager)1 InvalidArgumentException (org.neo4j.exceptions.InvalidArgumentException)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 GlobalProcedures (org.neo4j.kernel.api.procedure.GlobalProcedures)1 InMemoryUserRepository (org.neo4j.server.security.auth.InMemoryUserRepository)1 RateLimitedAuthenticationStrategy (org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy)1 HexString (org.neo4j.string.HexString)1