use of javax.el.ELProcessor 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);
}
use of javax.el.ELProcessor in project Payara by payara.
the class RolesPermittedInterceptor method checkAccessPermitted.
/**
* Check that the roles allowed by the class or method match the roles
* currently granted to the caller.
*
* @param roles The roles declared within the @Roles annotation.
* @param invocationContext
* @return True if access is allowed, false otherwise
*/
public boolean checkAccessPermitted(RolesPermitted roles, InvocationContext invocationContext) {
authenticate(roles.value());
ELProcessor eLProcessor = null;
if (hasAnyELExpression(roles.value())) {
eLProcessor = getElProcessor(invocationContext);
}
List<String> permittedRoles = asList(roles.value());
final SecurityContext securityContext = lazyProperties.getSecurityContext();
if (OR.equals(roles.semantics())) {
for (String role : permittedRoles) {
if (eLProcessor != null && hasAnyELExpression(role)) {
role = evalELExpression(eLProcessor, role);
}
if (securityContext.isCallerInRole(role)) {
return true;
}
}
} else if (AND.equals(roles.semantics())) {
for (String role : permittedRoles) {
if (eLProcessor != null && hasAnyELExpression(role)) {
role = evalELExpression(eLProcessor, role);
}
if (!securityContext.isCallerInRole(role)) {
return false;
}
}
return true;
}
return false;
}
Aggregations