Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <init-param>
- <param-name>com.sun.jersey.spi.container.ResourceFilters</param-name>
- <param-value>
- com.sun.jersey.api.container.filter.RolesAllowedResourceFilterFactory
- </param-value>
- </init-param>
- <dependency>
- <groupId>javax.annotation</groupId>
- <artifactId>jsr250-api</artifactId>
- <version>1.0</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.0.1</version>
- <scope>provided</scope>
- </dependency>
- <bean class="my.pkg.HelloWorld" id="helloWorldService"/>
- <jaxrs:serviceBeans>
- <ref bean="helloWorldService"/>
- </jaxrs:serviceBeans>
- <bean id="authorizationInterceptor"
- class="org.apache.cxf.interceptor.security.SecureAnnotationsInterceptor">
- <property name="securedObject" ref="helloWorldService" />
- </bean>
- <role rolename="hello-user" />
- <role rolename="hello-role1"/>
- <role rolename="hello-role2" />
- <user username="hello1" password="Password1" roles="hello-role1,hello-user"/>
- <user username="hello2" password="Password1" roles="hello-role2,hello-user"/>
- <security-constraint>
- <web-resource-collection>
- <web-resource-name>Hello Services</web-resource-name>
- <url-pattern>/hello/*</url-pattern>
- </web-resource-collection>
- <auth-constraint>
- <role-name>hello-user</role-name>
- </auth-constraint>
- </security-constraint>
- <login-config>
- <auth-method>BASIC</auth-method>
- <realm-name>default</realm-name>
- </login-config>
- @Path("/hello")
- @RolesAllowed("hello-user")
- public class HelloWorld {
- @GET
- @Path("/echo/{input}")
- @Produces("text/plain")
- @RolesAllowed("hello-role1")
- public String ping(@PathParam("input") String input) {
- return input;
- }
- @POST
- @Produces("application/json")
- @Consumes("application/json")
- @Path("/jsonBean")
- @RolesAllowed("hello-role2")
- public Response modifyJson(JsonBean input) {
- input.setVal2(input.getVal1());
- return Response.ok().entity(input).build();
- }
- @GET
- @Produces("text/plain")
- @Path("/cliche")
- public Response getClichedMessage(@Context HttpServletRequest request) {
- return Response.
- ok().
- entity("Sending "Hello World" to user "" + request.getUserPrincipal().getName() + """).
- build();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement