Search in sources :

Example 1 with DatabaseIdentityStoreDefinition

use of javax.security.enterprise.identitystore.DatabaseIdentityStoreDefinition in project tomee by apache.

the class TomEEELInvocationHandlerTest method canCreateInvocationHandler.

@Test
public void canCreateInvocationHandler() {
    final DatabaseIdentityStoreDefinition annotation = Color.class.getAnnotation(DatabaseIdentityStoreDefinition.class);
    final ELProcessor elProcessor = new ELProcessor();
    final ELResolver elResolver = bm().getELResolver();
    elProcessor.getELManager().addELResolver(elResolver);
    // small trick because of the @Vetoed bellow - OWB won't pick it up
    // so we will register one ourselves into the processor so it is resolved
    elProcessor.defineBean("color", new Color());
    final DatabaseIdentityStoreDefinition proxiedAnnotation = TomEEELInvocationHandler.of(DatabaseIdentityStoreDefinition.class, annotation, elProcessor);
    Assert.assertEquals("select password from caller where name = ?", proxiedAnnotation.callerQuery());
    Assert.assertEquals(90, proxiedAnnotation.priority());
    Assert.assertEquals("90", proxiedAnnotation.priorityExpression());
    Assert.assertArrayEquals(new IdentityStore.ValidationType[] { IdentityStore.ValidationType.VALIDATE }, proxiedAnnotation.useFor());
    Assert.assertEquals("select group_name from caller_groups where caller_name = ?", proxiedAnnotation.groupsQuery());
    final String[] hashAlgorithmParameters = proxiedAnnotation.hashAlgorithmParameters();
    Assert.assertArrayEquals(new String[] { "Pbkdf2PasswordHash.Iterations=3072", "${color.dyna}" }, hashAlgorithmParameters);
    final Set<String> evaluatedHashParameters = stream(hashAlgorithmParameters).flatMap(s -> toStream(eval(elProcessor, s, Object.class))).collect(toSet());
    System.out.println(evaluatedHashParameters);
    final Map<String, String> parametersMap = evaluatedHashParameters.stream().collect(toMap(s -> (String) s.substring(0, s.indexOf('=')), s -> (String) eval(elProcessor, s.substring(s.indexOf('=') + 1), String.class)));
    System.out.println(parametersMap);
}
Also used : TomEEDatabaseIdentityStore(org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore) Vetoed(javax.enterprise.inject.Vetoed) PasswordHash(javax.security.enterprise.identitystore.PasswordHash) CDI(javax.enterprise.inject.spi.CDI) IdentityStore(javax.security.enterprise.identitystore.IdentityStore) Set(java.util.Set) TomEEDatabaseIdentityStore.eval(org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore.eval) Test(org.junit.Test) ELProcessor(javax.el.ELProcessor) ELResolver(javax.el.ELResolver) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) DatabaseIdentityStoreDefinition(javax.security.enterprise.identitystore.DatabaseIdentityStoreDefinition) Map(java.util.Map) Named(javax.inject.Named) Assert(org.junit.Assert) Arrays.stream(java.util.Arrays.stream) BeanManager(javax.enterprise.inject.spi.BeanManager) Collectors.toSet(java.util.stream.Collectors.toSet) TomEEDatabaseIdentityStore.toStream(org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore.toStream) ELResolver(javax.el.ELResolver) ELProcessor(javax.el.ELProcessor) DatabaseIdentityStoreDefinition(javax.security.enterprise.identitystore.DatabaseIdentityStoreDefinition) TomEEDatabaseIdentityStore(org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore) IdentityStore(javax.security.enterprise.identitystore.IdentityStore) Test(org.junit.Test)

Aggregations

Arrays.stream (java.util.Arrays.stream)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Stream (java.util.stream.Stream)1 ELProcessor (javax.el.ELProcessor)1 ELResolver (javax.el.ELResolver)1 Vetoed (javax.enterprise.inject.Vetoed)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 CDI (javax.enterprise.inject.spi.CDI)1 Named (javax.inject.Named)1 DatabaseIdentityStoreDefinition (javax.security.enterprise.identitystore.DatabaseIdentityStoreDefinition)1 IdentityStore (javax.security.enterprise.identitystore.IdentityStore)1 PasswordHash (javax.security.enterprise.identitystore.PasswordHash)1 TomEEDatabaseIdentityStore (org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore)1 TomEEDatabaseIdentityStore.eval (org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore.eval)1 TomEEDatabaseIdentityStore.toStream (org.apache.tomee.security.identitystore.TomEEDatabaseIdentityStore.toStream)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1