Search in sources :

Example 11 with AuthSubject

use of org.neo4j.kernel.api.security.AuthSubject in project neo4j by neo4j.

the class TransactionEventsIT method shouldGetSpecifiedUsernameAndMetaDataInTXData.

@Test
public void shouldGetSpecifiedUsernameAndMetaDataInTXData() {
    final AtomicReference<String> usernameRef = new AtomicReference<>();
    final AtomicReference<Map<String, Object>> metaDataRef = new AtomicReference<>();
    db.registerTransactionEventHandler(getBeforeCommitHandler(txData -> {
        usernameRef.set(txData.username());
        metaDataRef.set(txData.metaData());
    }));
    AuthSubject subject = mock(AuthSubject.class);
    when(subject.username()).thenReturn("Christof");
    SecurityContext securityContext = new SecurityContext.Frozen(subject, AccessMode.Static.WRITE);
    Map<String, Object> metadata = genericMap("username", "joe");
    runTransaction(securityContext, metadata);
    assertThat("Should have specified username", usernameRef.get(), equalTo("Christof"));
    assertThat("Should have metadata with specified username", metaDataRef.get(), equalTo(metadata));
}
Also used : Label(org.neo4j.graphdb.Label) AnonymousContext(org.neo4j.kernel.api.security.AnonymousContext) RootCauseMatcher(org.neo4j.test.mockito.matcher.RootCauseMatcher) TransactionData(org.neo4j.graphdb.event.TransactionData) TransactionEventHandler(org.neo4j.graphdb.event.TransactionEventHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) DatabaseRule(org.neo4j.test.rule.DatabaseRule) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) RandomRule(org.neo4j.test.rule.RandomRule) MapUtil.genericMap(org.neo4j.helpers.collection.MapUtil.genericMap) Map(java.util.Map) AccessMode(org.neo4j.kernel.api.security.AccessMode) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Transaction(org.neo4j.graphdb.Transaction) ExpectedException(org.junit.rules.ExpectedException) AuthSubject(org.neo4j.kernel.api.security.AuthSubject) ImpermanentDatabaseRule(org.neo4j.test.rule.ImpermanentDatabaseRule) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) RuleChain(org.junit.rules.RuleChain) Consumer(java.util.function.Consumer) List(java.util.List) Rule(org.junit.Rule) Relationship(org.neo4j.graphdb.Relationship) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Matchers.equalTo(org.hamcrest.Matchers.equalTo) RelationshipType(org.neo4j.graphdb.RelationshipType) PropertyContainer(org.neo4j.graphdb.PropertyContainer) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) AuthSubject(org.neo4j.kernel.api.security.AuthSubject) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) MapUtil.genericMap(org.neo4j.helpers.collection.MapUtil.genericMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

AuthSubject (org.neo4j.kernel.api.security.AuthSubject)11 Test (org.junit.Test)10 Matchers.containsString (org.hamcrest.Matchers.containsString)5 BasicSecurityContext (org.neo4j.server.security.auth.BasicSecurityContext)5 AuthenticationResult (org.neo4j.kernel.api.security.AuthenticationResult)3 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 ExpectedException (org.junit.rules.ExpectedException)1 RuleChain (org.junit.rules.RuleChain)1 Mockito.mock (org.mockito.Mockito.mock)1