Skip to content
Permalink
Browse files
enhancing security service to be fully contextual
  • Loading branch information
rmannibucau committed Nov 2, 2018
1 parent bb43afb commit d9138f13da353df9662e9aaaa0b48779fde99648
Showing 1 changed file with 13 additions and 2 deletions.
@@ -16,19 +16,30 @@
*/
package org.apache.geronimo.microprofile.impl.jwtauth.tck;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;
import java.security.Principal;
import java.util.function.Supplier;

import javax.enterprise.inject.spi.CDI;
import javax.servlet.http.HttpServletRequest;

import org.apache.webbeans.corespi.security.SimpleSecurityService;
import org.eclipse.microprofile.jwt.JsonWebToken;

// to drop upgrading MW
public class TckSecurityService extends SimpleSecurityService {
@Override
public Principal getCurrentPrincipal() {
return ((Supplier<Principal>) CDI.current().select(HttpServletRequest.class).get()
.getAttribute(Principal.class.getName() + ".supplier")).get();
return Principal.class.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class<?>[]{Principal.class, JsonWebToken.class},
(proxy, method, args) -> {
try {
return method.invoke(((Supplier<Principal>) CDI.current().select(HttpServletRequest.class).get()
.getAttribute(Principal.class.getName() + ".supplier")).get(), args);
} catch (final InvocationTargetException ite) {
throw ite.getTargetException();
}
}));
}
}

0 comments on commit d9138f1

Please sign in to comment.