Cannot inject javax.security.enterprise.SecurityContext in basic JEE8 login application

1.1k Views Asked by At

I'be been struggling for about 20 hours and also working in the weekend as you can see and I can't make this work. I think I have exhausted all the online options

I have copied the example here https://rieckpil.de/howto-simple-form-based-authentication-for-jsf-2-3-with-java-ee-8-security-api/ in a new Dynamic web project in Eclipse for Java Enterprise Developers. I activated JSF 2.3 in the project facets (since I know that TomEE can use them) I copied the classes, I set the web.xml to be the same. My project runtime is TomEE8 (which is basically Tomcat9 with CDI and other stuff)

When I try to run the project on TomEE, I get this error:

javax.enterprise.inject.UnsatisfiedResolutionException: Api type [javax.security.enterprise.SecurityContext] is not found with the qualifiers Qualifiers: [@javax.enterprise.inject.Default()] for injection into Field Injection Point, field name : securityContext, Bean Owner : [LoginBacking, WebBeansType:MANAGED, Name:loginBacking, API Types:[java.lang.Object,LoginBacking], Qualifiers:[javax.inject.Named,javax.enterprise.inject.Default,javax.enterprise.inject.Any]]

I have tried creating the beans.xml file in my WEB-INF folder I have created another bean with this annotation:

@FacesConfig(
    // Activates CDI build-in beans
    version = JSF_2_3 
)

I have tried not using TomEE and using Tomcat 9 with weld, same problem.

I have no idea how to make this work. The thing is I need to add user login to my main application, but if this simple example won't work I don't think I can do this and I'm feeling very down. If anyone can help me see the light, I'd be appreciative. I am also open to using the old method (ManagedBean and ManagedProperty I guess), but I'm not sure if it has the same effect. Thanks!

1

There are 1 best solutions below

2
On

Time for an answer. It seems like TomEE does not provide an implementation for javaee-web-api. I had to add my own. I have added the Soteria implementation to my lib file https://search.maven.org/classic/#search%7Cga%7C1%7Ca%3A%22javax.security.enterprise%22 Now all seems well (at least the app is running). Good luck!