Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 27 java ee 8 Interceptors are typically shipped by a library and can be applied bound to a bean thats owned by the application So how do you bind a library shipped interceptor to a library shipped built in bean In CDI 12 and before this wasnt really possible but in CDI 20 you can take advantage of the new InterceptionFactory to do this Its not entirely trivial yet but its doable Here is how to apply the @ RememberMe interceptor binding from the new Java EE 8 Security specification to a built in bean of type HttpAuthenticationMechanism which is from the Java EE Security spec as well First configure the authentication mechanism by means of the following annotation @ BasicAuthenticationMechanismDefinition realmName foo This annotation causes the container to enable a built in bean with an interface type of HttpAuthenticationMechanism but having an unknown vendor specific implementation The annotation can be placed on almost any class on the classpath Next define an alternative for this bean via a CDI producer @ Alternative @ Priority 500 @ ApplicationScoped public class ApplicationInit @ Produces public HttpAuthenticationMechanism produce InterceptionFactory HttpAuthenticationMechanismWrapper interceptionFactory BeanManager beanManager return
You must have JavaScript enabled to view digital editions.