Guest User

Untitled

a guest
Jul 3rd, 2017
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10. ##############################################
  11. I am unable to access the url=/ using access_token, can anyone please suggest me where i am doing wrong
  12. Thanks
  13.  
  14. application.yml
  15. management:
  16. context_path: /admin
  17. security:
  18. user:
  19. password: password
  20. basic:
  21. enabled: false
  22. oauth2:
  23. client:
  24. client-id: my-client-with-secret
  25. client-secret: secret
  26. access-token-validity-seconds: 60
  27. access-token-uri: http://x.x.x.x:8080/uaa/oauth/token
  28. scope: read
  29. resource:
  30. id: demo
  31.  
  32.  
  33. debug: true
  34.  
  35. logging:
  36. level:
  37. org.springframework.web: DEBUG
  38. org.springframework.security: DEBUG
  39. #################################################################
  40. Application.java
  41. #####################################################################3
  42. @SpringBootApplication
  43. @RestController
  44. public class Application {
  45.  
  46. public static void main(String[] args) {
  47. SpringApplication.run(Application.class, args);
  48. }
  49.  
  50. @RequestMapping("/")
  51. public String home() {
  52. return "Hello World";
  53. }
  54.  
  55. @Configuration
  56. @EnableResourceServer
  57. protected static class ResourceServer extends ResourceServerConfigurerAdapter {
  58.  
  59. @Override
  60. public void configure(HttpSecurity http) throws Exception {
  61. // @formatter:off
  62. http
  63. // Just for laughs, apply OAuth protection to only 2 resources
  64. .requestMatcher(new OrRequestMatcher(
  65. new AntPathRequestMatcher("/"),
  66. new AntPathRequestMatcher("/admin/beans")
  67. ))
  68. .authorizeRequests()
  69. .anyRequest().access("#oauth2.hasScope('read')");
  70. // @formatter:on
  71. }
  72.  
  73. @Override
  74. public void configure(ResourceServerSecurityConfigurer resources)
  75. throws Exception {
  76. resources.resourceId("demo");
  77. }
  78.  
  79. }
  80.  
  81. @Configuration
  82. @EnableAuthorizationServer
  83. protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {
  84.  
  85. @Autowired
  86. private AuthenticationManager authenticationManager;
  87.  
  88. @Override
  89. public void configure(AuthorizationServerEndpointsConfigurer endpoints)
  90. throws Exception {
  91. endpoints.authenticationManager(authenticationManager);
  92. }
  93.  
  94.  
  95. }
  96.  
  97. }
Add Comment
Please, Sign In to add comment