This repository has been archived by the owner on Nov 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Using OSGi JAX RS Connector Security with Spring
hstaudacher edited this page Sep 18, 2014
·
2 revisions
This HowTo was written by @thilker. Please contact him if you have any questions.
- Get the security bundle from here: http://maven-repository.com/artifact/com.eclipsesource.jaxrs/provider-security.
- Install the bundle (Depends on your IDE, Server, OS, etc. how to do it)
- Create a new class implementing the interfaces “AuthenticationHandler” and “AuthorizationHandler“
- Annotate the new class with “org.springframework.stereotype.Service”. Make sure to set the base package to be scanned in your Spring-Config
<context:component-scan base-package="your.base.package" />
- Annotate your REST-Service as descripted here https://github.com/hstaudacher/osgi-jax-rs-connector/wiki/security.
@RolesAllowed( "secure" )
- Some additional packages have to be declared in the manifest. For example
javax.ws.rs.container
andjavax.annotation.security
. At least you will see what is missing when you start the app. - Declare the Springbean (the Handler) as OSGi-Services in your Spring-OSGi-Config:
<osgi:service ref="securityHandler" interface="com.eclipsesource.jaxrs.provider.security.AuthenticationHandler" /> <osgi:service ref="securityHandler" interface="com.eclipsesource.jaxrs.provider.security.AuthorizationHandler" />
Keep in mind, that the “ref”-name is the name of the bean. My class’s name is “SecurityHandler”, so the “@Service”-annotation causes the bean name to be “securityHandler”.
- Start the application.
- Test the REST-service but keep in mind to set a HTTP-Header with the attribute you have choosen in
public Principal authenticate(ContainerRequestContext requestContext)
for the user. Normally it is “user”. - For being able to set HTTP-Headers I would recommend “GraphicalHttpClient (OSX)”. But there are many more (fiddler, etc.).