Search in sources :

Example 41 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class OperationsTest method runForSecurityLevel.

protected String runForSecurityLevel(Executable executable, AccessMode mode, boolean shoudldBeAuthorized) throws Exception {
    SecurityContext securityContext = SecurityContext.authDisabled(mode, ClientConnectionInfo.EMBEDDED_CONNECTION, DB_NAME);
    when(transaction.securityContext()).thenReturn(securityContext);
    when(transaction.securityAuthorizationHandler()).thenReturn(new SecurityAuthorizationHandler(securityLog));
    when(nodeCursor.next()).thenReturn(true);
    when(nodeCursor.hasLabel(2)).thenReturn(false);
    when(nodeCursor.hasLabel(3)).thenReturn(true);
    when(tokenHolders.labelTokens().getTokenById(anyInt())).thenReturn(new NamedToken("Label", 2));
    if (shoudldBeAuthorized) {
        assertAuthorized(executable);
        return null;
    } else {
        AuthorizationViolationException exception = assertThrows(AuthorizationViolationException.class, executable);
        return exception.getMessage();
    }
}
Also used : SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) NamedToken(org.neo4j.token.api.NamedToken) AuthorizationViolationException(org.neo4j.graphdb.security.AuthorizationViolationException) SecurityAuthorizationHandler(org.neo4j.internal.kernel.api.security.SecurityAuthorizationHandler)

Example 42 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class BatchingTokenRepositoryTest method shouldFlushNewTokens.

@Test
void shouldFlushNewTokens() {
    // given
    try (NeoStores stores = newNeoStores(StoreType.PROPERTY_KEY_TOKEN, StoreType.PROPERTY_KEY_TOKEN_NAME)) {
        TokenStore<PropertyKeyTokenRecord> tokenStore = stores.getPropertyKeyTokenStore();
        int rounds = 3;
        int tokensPerRound = 4;
        BatchingPropertyKeyTokenRepository repo = new BatchingPropertyKeyTokenRepository(tokenStore);
        // when first creating some tokens
        int expectedId = 0;
        int tokenNameAsInt = 0;
        for (int round = 0; round < rounds; round++) {
            for (int i = 0; i < tokensPerRound; i++) {
                int tokenId = repo.getOrCreateId(String.valueOf(tokenNameAsInt++));
                assertEquals(expectedId + i, tokenId);
            }
            assertEquals(expectedId, tokenStore.getHighId());
            repo.flush(NULL);
            assertEquals(expectedId + tokensPerRound, tokenStore.getHighId());
            expectedId += tokensPerRound;
        }
        repo.flush(NULL);
        List<NamedToken> tokens = tokenStore.getTokens(NULL);
        assertEquals(tokensPerRound * rounds, tokens.size());
        for (NamedToken token : tokens) {
            assertEquals(token.id(), parseInt(token.name()));
        }
    }
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) BatchingPropertyKeyTokenRepository(org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingPropertyKeyTokenRepository) NamedToken(org.neo4j.token.api.NamedToken) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) Test(org.junit.jupiter.api.Test)

Example 43 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistryTest method putAllMustThrowOnDuplicateNameWithExistingToken.

@Test
void putAllMustThrowOnDuplicateNameWithExistingToken() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1));
    assertThrows(NonUniqueTokenException.class, () -> registry.putAll(singletonList(new NamedToken(INBOUND1_TYPE, 2))));
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 44 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistryTest method setInitialTokensMustNotThrowOnDuplicateWithExistingToken.

@Test
void setInitialTokensMustNotThrowOnDuplicateWithExistingToken() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1));
    registry.setInitialTokens(singletonList(new NamedToken(INBOUND1_TYPE, 1)));
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 45 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistry method insertAllChecked.

private Registries insertAllChecked(List<NamedToken> tokens, Registries registries) {
    MutableObjectIntMap<String> uniquePublicNames = new ObjectIntHashMap<>();
    MutableObjectIntMap<String> uniqueInternalNames = new ObjectIntHashMap<>();
    MutableIntSet uniqueIds = new IntHashSet();
    for (NamedToken token : tokens) {
        if (token.isInternal()) {
            checkNameUniqueness(uniqueInternalNames, token, registries);
            checkNameUniqueness(registries.internalNameToId, token, registries);
            uniqueInternalNames.put(token.name(), token.id());
        } else {
            checkNameUniqueness(uniquePublicNames, token, registries);
            checkNameUniqueness(registries.publicNameToId, token, registries);
            uniquePublicNames.put(token.name(), token.id());
        }
        if (!uniqueIds.add(token.id()) || registries.idToToken.containsKey(token.id())) {
            NamedToken existingToken = registries.idToToken.get(token.id());
            throw new NonUniqueTokenException(tokenType, token, existingToken);
        }
        insertUnchecked(token, registries);
    }
    return registries;
}
Also used : MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) ObjectIntHashMap(org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap) NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet) NamedToken(org.neo4j.token.api.NamedToken)

Aggregations

NamedToken (org.neo4j.token.api.NamedToken)63 Test (org.junit.jupiter.api.Test)41 ArrayList (java.util.ArrayList)6 TokenNotFoundException (org.neo4j.token.api.TokenNotFoundException)6 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5 SchemaRule (org.neo4j.internal.schema.SchemaRule)5 NonUniqueTokenException (org.neo4j.token.api.NonUniqueTokenException)5 TokenHolder (org.neo4j.token.api.TokenHolder)5 AlreadyConstrainedException (org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 IntSupplier (java.util.function.IntSupplier)3 KernelException (org.neo4j.exceptions.KernelException)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3 IdCapacityExceededException (org.neo4j.internal.id.IdCapacityExceededException)3 Token (org.neo4j.internal.kernel.api.Token)3 TokenWrite.checkValidTokenName (org.neo4j.internal.kernel.api.TokenWrite.checkValidTokenName)3 LabelNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException)3 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)3 RelationshipTypeIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException)3