Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Application found for security initialization when run with Arquillian #4

Open
flavienlaurent opened this issue Jul 19, 2018 · 2 comments

Comments

@flavienlaurent
Copy link

flavienlaurent commented Jul 19, 2018

I configured Keycloak with kumuluzee-security-keycloak and I'm trying to write some integration tests with Arquillian.

When I run the app the normal way with EeApplication, Keycloak is intialized and the resources are secured. But when I run the app the Arquillian way, Keycloak is loaded as an extension:

2018-07-19 17:19:19,112 INFO -- EeApplication --  Found extension implemented by keycloak {}  
2018-07-19 17:19:19,112 INFO -- com.kumuluz.ee.security.extensions.KeycloakSecurityExtension --  Initialised security implemented by Keycloak. {}  
2018-07-19 17:19:19,112 INFO -- com.kumuluz.ee.security.extensions.KeycloakSecurityExtension --  Initialising security implemented by Keycloak. {}  

But the AnnotationProcessorUtil class doesn't find my Application (via ServiceLoader.load(Application.class)) so security configuration is not initialized and the resources are not secured.

@urbim
Copy link
Member

urbim commented Jul 20, 2018

There are two ServiceLoader files generated compile-time by the extension, which need to be included in the deployment:

META-INF/resources/java.lang.Object
META-INF/services/javax.ws.rs.core.Application

You can include them by doing something like this:

    @Deployment
    public static JavaArchive createDeployment() {
        JavaArchive jar = ShrinkWrap.create(JavaArchive.class);

        // add classes to jar

        try {
            jar.addAsResource("META-INF/resources/java.lang.Object");
        } catch (IllegalArgumentException ignored) {
        }
        try {
            jar.addAsResource("META-INF/services/javax.ws.rs.core.Application");
        } catch (IllegalArgumentException ignored) {
        }

        return jar;
    }

The try-catch blocks are needed because the files are not always generated and Arquillian throws an IllegalArgumentException if resource is not found.

@flavienlaurent
Copy link
Author

flavienlaurent commented Aug 3, 2018

Ok thanks for those explanations.

As I want to keep full control on the arquillian deployment, I prefer to do something like

jar.addAsManifestResource(new StringAsset(MyController.class.getName()), "resources/java.lang.Object")
jar.addAsManifestResource(new StringAsset(MyApplication.class.getName()), "services/javax.ws.rs.core.Application");

But the result is the same ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants