eclipse-ee4j / eclipse-ee4j/jersey

Use Jersey With Weld, mojarra, SecurityContext does't work

Open
#4,644 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

jersey: 2.28
weld:2.4.3
Mojarra: 2.2.9
jdk:1.8

i am using jersey + weld app

```
@ApplicationPath("/rest")
public class TestApplication extends Application {

public Set> getClasses() {
return new HashSet<>( Arrays.asList(
TestService.class
) );
}
}

```

```
@Stateless
@Path("/secure/holder")
@Produces(MediaType.APPLICATION_JSON)
public class PolicyHolderService {

@Context
private SecurityContext context;
}
```

First:When I visit Web page `\welcome.xhtml` , it will be intercepted by JSF's servlet Holer, because JSF intercepts *.xhtml, so it will not enter the Jersey servlet。so' i got this error, this error is caused by @SecurityContext does't work.

```
java.lang.IllegalStateException: Not inside a request scope.
at org.glassfish.jersey.internal.guava.Preconditions.checkState(Preconditions.java:169)
at org.glassfish.jersey.process.internal.RequestScope.current(RequestScope.java:153)
at org.glassfish.jersey.inject.hk2.RequestContext.findOrCreate(RequestContext.java:55)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2102)
at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:92)
at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:66)
at org.glassfish.jersey.inject.hk2.ContextInjectionResolverImpl.resolve(ContextInjectionResolverImpl.java:103)
at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:988)
at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:985)
at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.inject(AbstractHk2InjectionManager.java:207)
at org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.inject(ImmediateHk2InjectionManager.java:30)
at org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider$InjectionManagerInjectedCdiTarget.inject(CdiComponentProvider.java:857)
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:159)
at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:70)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
```

after that, i got a web page, this page have't intercepted by jsf, and the @SecurityContext it's work.

i got two stack like this:
if this request intercepted by JSF's servlet Holer

```
current:152, RequestScope (org.glassfish.jersey.process.internal)
findOrCreate:55, RequestContext (org.glassfish.jersey.inject.hk2)
createService:2102, Utilities (org.jvnet.hk2.internal)
getService:92, ServiceHandleImpl (org.jvnet.hk2.internal)
getService:66, ServiceHandleImpl (org.jvnet.hk2.internal)
resolve:103, ContextInjectionResolverImpl (org.glassfish.jersey.inject.hk2)
justInject:988, Utilities (org.jvnet.hk2.internal)
inject:985, ServiceLocatorImpl (org.jvnet.hk2.internal)
inject:207, AbstractHk2InjectionManager (org.glassfish.jersey.inject.hk2)
inject:30, ImmediateHk2InjectionManager (org.glassfish.jersey.inject.hk2)
inject:857, CdiComponentProvider$InjectionManagerInjectedCdiTarget (org.glassfish.jersey.ext.cdi1x.internal)
create:159, ManagedBean (org.jboss.weld.bean)
get:70, DependentContextImpl (org.jboss.weld.context.unbound)
get:100, ContextualInstanceStrategy$DefaultContextualInstanceStrategy (org.jboss.weld.bean)
get:50, ContextualInstance (org.jboss.weld.bean)
getReference:758, BeanManagerImpl (org.jboss.weld.manager)
getInjectableReference:858, BeanManagerImpl (org.jboss.weld.manager)
inject:92, FieldInjectionPoint (org.jboss.weld.injection)
injectBoundFields:358, Beans (org.jboss.weld.util)
injectFieldsAndInitializers:369, Beans (org.jboss.weld.util)
proceed:70, ResourceInjector$1 (org.jboss.weld.injection.producer)
run:48, InjectionContextImpl (org.jboss.weld.injection)
inject:72, ResourceInjector (org.jboss.weld.injection.producer)
inject:117, BasicInjectionTarget (org.jboss.weld.injection.producer)
create:159, ManagedBean (org.jboss.weld.bean)
get:96, AbstractContext (org.jboss.weld.context)
get:100, ContextualInstanceStrategy$DefaultContextualInstanceStrategy (org.jboss.weld.bean)
get:177, ContextualInstanceStrategy$CachingContextualInstanceStrategy (org.jboss.weld.bean)
get:50, ContextualInstance (org.jboss.weld.bean)
getReference:758, BeanManagerImpl (org.jboss.weld.manager)
lookup:107, AbstractWeldELResolver (org.jboss.weld.el)
getValue:90, AbstractWeldELResolver (org.jboss.weld.el)
getValue:49, ForwardingELResolver (org.jboss.weld.environment.servlet.util)
getValue:62, CompositeELResolver (javax.el)
_getValue:176, DemuxCompositeELResolver (com.sun.faces.el)
getValue:203, DemuxCompositeELResolver (com.sun.faces.el)
getValue:94, AstIdentifier (org.apache.el.parser)
getValue:137, AstValue (org.apache.el.parser)
getValue:46, AstEmpty (org.apache.el.parser)
getValue:190, ValueExpressionImpl (org.apache.el)
getValue:50, WeldValueExpression (org.jboss.weld.el)
getValue:109, TagValueExpression (com.sun.faces.facelets.el)
eval:194, ComponentStateHelper (javax.faces.component)
isRendered:458, UIComponentBase (javax.faces.component)
encodeAll:1850, UIComponent (javax.faces.component)
encodeAll:1859, UIComponent (javax.faces.component)
encodeAll:1859, UIComponent (javax.faces.component)
renderView:456, FaceletViewHandlingStrategy (com.sun.faces.application.view)
renderView:134, MultiViewHandler (com.sun.faces.application.view)
renderView:337, ViewHandlerWrapper (javax.faces.application)
execute:120, RenderResponsePhase (com.sun.faces.lifecycle)
doPhase:101, Phase (com.sun.faces.lifecycle)
render:219, LifecycleImpl (com.sun.faces.lifecycle)
service:659, FacesServlet (javax.faces.webapp)
handle:876, ServletHolder (org.eclipse.jetty.servlet)
doFilter:1631, ServletHandler$CachedChain (org.eclipse.jetty.servlet)
doFilter:214, WebSocketUpgradeFilter (org.eclipse.jetty.websocket.server)
doFilter:1618, ServletHandler$CachedChain (org.eclipse.jetty.servlet)
doFilter:38, LoginFilter (org.spec.jent.insurance.filters)
doFilter:1618, ServletHandler$CachedChain (org.eclipse.jetty.servlet)
doFilter:38, LoginFilter (org.spec.jent.insurance.filters)
doFilter:1610, ServletHandler$CachedChain (org.eclipse.jetty.servlet)
doHandle:540, ServletHandler (org.eclipse.jetty.servlet)
handle:146, ScopedHandler (org.eclipse.jetty.server.handler)
handle:548, SecurityHandler (org.eclipse.jetty.security)
handle:132, HandlerWrapper (org.eclipse.jetty.server.handler)
nextHandle:257, ScopedHandler (org.eclipse.jetty.server.handler)
doHandle:1711, SessionHandler (org.eclipse.jetty.server.session)
nextHandle:255, ScopedHandler (org.eclipse.jetty.server.handler)
doHandle:1347, ContextHandler (org.eclipse.jetty.server.handler)
nextScope:203, ScopedHandler (org.eclipse.jetty.server.handler)
doScope:480, ServletHandler (org.eclipse.jetty.servlet)
doScope:1678, SessionHandler (org.eclipse.jetty.server.session)
nextScope:201, ScopedHandler (org.eclipse.jetty.server.handler)
doScope:1249, ContextHandler (org.eclipse.jetty.server.handler)
handle:144, ScopedHandler (org.eclipse.jetty.server.handler)
handle:220, ContextHandlerCollection (org.eclipse.jetty.server.handler)
handle:152, HandlerCollection (org.eclipse.jetty.server.handler)
handle:55, TasStatisticsHandler (com.thunisoft.tas.core.handler)
handle:132, HandlerWrapper (org.eclipse.jetty.server.handler)
handle:155, TasInfoHandler (com.thunisoft.tas.server.jetty.server.handler)
handle:178, InetAccessHandler (org.eclipse.jetty.server.handler)
handle:132, HandlerWrapper (org.eclipse.jetty.server.handler)
handle:505, Server (org.eclipse.jetty.server)
handle:370, HttpChannel (org.eclipse.jetty.server)
onFillable:267, HttpConnection (org.eclipse.jetty.server)
succeeded:305, AbstractConnection$ReadCallback (org.eclipse.jetty.io)
fillable:103, FillInterest (org.eclipse.jetty.io)
run:117, ChannelEndPoint$2 (org.eclipse.jetty.io)
runTask:333, EatWhatYouKill (org.eclipse.jetty.util.thread.strategy)
doProduce:310, EatWhatYouKill (org.eclipse.jetty.util.thread.strategy)
tryProduce:168, EatWhatYouKill (org.eclipse.jetty.util.thread.strategy)
run:126, EatWhatYouKill (org.eclipse.jetty.util.thread.strategy)
run:366, ReservedThreadExecutor$ReservedThread (org.eclipse.jetty.util.thread)
runJob:781, QueuedThreadPool (org.eclipse.jetty.util.thread)
run:917, QueuedThreadPool$Runner (org.eclipse.jetty.util.thread)
run:748, Thread (java.lang)
```

if the request intercepted by jersey servlet Holer

```
activate:228, RequestScope (org.glassfish.jersey.process.internal)
runInScope:264, RequestScope (org.glassfish.jersey.process.internal)
process:232, ServerRuntime (org.glassfish.jersey.server)
handle:679, ApplicationHandler (org.glassfish.jersey.server)
serviceImpl:392, WebComponent (org.glassfish.jersey.servlet)
service:346, WebComponent (org.glassfish.jersey.servlet)
service:365, ServletContainer (org.glassfish.jersey.servlet)
service:318, ServletContainer (org.glassfish.jersey.servlet)
service:205, ServletContainer (org.glassfish.jersey.servlet)
handle:876, ServletHolder (org.eclipse.jetty.servlet)
doFilter:1631, ServletHandler$CachedChain (org.eclipse.jetty.servlet)
doFilter:214, WebSocketUpgradeFilter (org.eclipse.jetty.websocket.server)
doFilter:1618, ServletHandler$CachedChain (org.eclipse.jetty.servlet)
doHandle:540, ServletHandler (org.eclipse.jetty.servlet)
handle:146, ScopedHandler (org.eclipse.jetty.server.handler)
handle:548, SecurityHandler (org.eclipse.jetty.security)
handle:132, HandlerWrapper (org.eclipse.jetty.server.handler)
nextHandle:257, ScopedHandler (org.eclipse.jetty.server.handler)
doHandle:1711, SessionHandler (org.eclipse.jetty.server.session)
nextHandle:255, ScopedHandler (org.eclipse.jetty.server.handler)
doHandle:1347, ContextHandler (org.eclipse.jetty.server.handler)
nextScope:203, ScopedHandler (org.eclipse.jetty.server.handler)
doScope:480, ServletHandler (org.eclipse.jetty.servlet)
doScope:1678, SessionHandler (org.eclipse.jetty.server.session)
nextScope:201, ScopedHandler (org.eclipse.jetty.server.handler)
doScope:1249, ContextHandler (org.eclipse.jetty.server.handler)
handle:144, ScopedHandler (org.eclipse.jetty.server.handler)
handle:220, ContextHandlerCollection (org.eclipse.jetty.server.handler)
handle:152, HandlerCollection (org.eclipse.jetty.server.handler)
handle:55, TasStatisticsHandler (com.thunisoft.tas.core.handler)
handle:132, HandlerWrapper (org.eclipse.jetty.server.handler)
handle:155, TasInfoHandler (com.thunisoft.tas.server.jetty.server.handler)
handle:178, InetAccessHandler (org.eclipse.jetty.server.handler)
handle:132, HandlerWrapper (org.eclipse.jetty.server.handler)
handle:505, Server (org.eclipse.jetty.server)
handle:370, HttpChannel (org.eclipse.jetty.server)
onFillable:267, HttpConnection (org.eclipse.jetty.server)
succeeded:305, AbstractConnection$ReadCallback (org.eclipse.jetty.io)
fillable:103, FillInterest (org.eclipse.jetty.io)
run:117, ChannelEndPoint$2 (org.eclipse.jetty.io)
runTask:333, EatWhatYouKill (org.eclipse.jetty.util.thread.strategy)
doProduce:310, EatWhatYouKill (org.eclipse.jetty.util.thread.strategy)
tryProduce:168, EatWhatYouKill (org.eclipse.jetty.util.thread.strategy)
produce:132, EatWhatYouKill (org.eclipse.jetty.util.thread.strategy)
run:-1, 584153299 (org.eclipse.jetty.io.ManagedSelector$$Lambda$240)
runJob:781, QueuedThreadPool (org.eclipse.jetty.util.thread)
run:917, QueuedThreadPool$Runner (org.eclipse.jetty.util.thread)
run:748, Thread (java.lang)
```

What should I do now? Are there any extension methods?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.