Advertisement
Guest User

Untitled

a guest
May 19th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. <init-param>
  2. <param-name>com.sun.jersey.spi.container.ResourceFilters</param-name>
  3. <param-value>
  4. com.sun.jersey.api.container.filter.RolesAllowedResourceFilterFactory
  5. </param-value>
  6. </init-param>
  7.  
  8. <dependency>
  9. <groupId>javax.annotation</groupId>
  10. <artifactId>jsr250-api</artifactId>
  11. <version>1.0</version>
  12. </dependency>
  13. <dependency>
  14. <groupId>javax.servlet</groupId>
  15. <artifactId>javax.servlet-api</artifactId>
  16. <version>3.0.1</version>
  17. <scope>provided</scope>
  18. </dependency>
  19.  
  20. <bean class="my.pkg.HelloWorld" id="helloWorldService"/>
  21.  
  22. <jaxrs:serviceBeans>
  23. <ref bean="helloWorldService"/>
  24. </jaxrs:serviceBeans>
  25.  
  26. <bean id="authorizationInterceptor"
  27. class="org.apache.cxf.interceptor.security.SecureAnnotationsInterceptor">
  28. <property name="securedObject" ref="helloWorldService" />
  29. </bean>
  30.  
  31. <role rolename="hello-user" />
  32. <role rolename="hello-role1"/>
  33. <role rolename="hello-role2" />
  34. <user username="hello1" password="Password1" roles="hello-role1,hello-user"/>
  35. <user username="hello2" password="Password1" roles="hello-role2,hello-user"/>
  36.  
  37. <security-constraint>
  38. <web-resource-collection>
  39. <web-resource-name>Hello Services</web-resource-name>
  40. <url-pattern>/hello/*</url-pattern>
  41. </web-resource-collection>
  42. <auth-constraint>
  43. <role-name>hello-user</role-name>
  44. </auth-constraint>
  45. </security-constraint>
  46. <login-config>
  47. <auth-method>BASIC</auth-method>
  48. <realm-name>default</realm-name>
  49. </login-config>
  50.  
  51. @Path("/hello")
  52. @RolesAllowed("hello-user")
  53. public class HelloWorld {
  54.  
  55. @GET
  56. @Path("/echo/{input}")
  57. @Produces("text/plain")
  58. @RolesAllowed("hello-role1")
  59. public String ping(@PathParam("input") String input) {
  60. return input;
  61. }
  62.  
  63. @POST
  64. @Produces("application/json")
  65. @Consumes("application/json")
  66. @Path("/jsonBean")
  67. @RolesAllowed("hello-role2")
  68. public Response modifyJson(JsonBean input) {
  69. input.setVal2(input.getVal1());
  70. return Response.ok().entity(input).build();
  71. }
  72.  
  73. @GET
  74. @Produces("text/plain")
  75. @Path("/cliche")
  76. public Response getClichedMessage(@Context HttpServletRequest request) {
  77. return Response.
  78. ok().
  79. entity("Sending "Hello World" to user "" + request.getUserPrincipal().getName() + """).
  80. build();
  81.  
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement