Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##############################################
- I am unable to access the url=/ using access_token, can anyone please suggest me where i am doing wrong
- Thanks
- application.yml
- management:
- context_path: /admin
- security:
- user:
- password: password
- basic:
- enabled: false
- oauth2:
- client:
- client-id: my-client-with-secret
- client-secret: secret
- access-token-validity-seconds: 60
- access-token-uri: http://x.x.x.x:8080/uaa/oauth/token
- scope: read
- resource:
- id: demo
- debug: true
- logging:
- level:
- org.springframework.web: DEBUG
- org.springframework.security: DEBUG
- #################################################################
- Application.java
- #####################################################################3
- @SpringBootApplication
- @RestController
- public class Application {
- public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
- }
- @RequestMapping("/")
- public String home() {
- return "Hello World";
- }
- @Configuration
- @EnableResourceServer
- protected static class ResourceServer extends ResourceServerConfigurerAdapter {
- @Override
- public void configure(HttpSecurity http) throws Exception {
- // @formatter:off
- http
- // Just for laughs, apply OAuth protection to only 2 resources
- .requestMatcher(new OrRequestMatcher(
- new AntPathRequestMatcher("/"),
- new AntPathRequestMatcher("/admin/beans")
- ))
- .authorizeRequests()
- .anyRequest().access("#oauth2.hasScope('read')");
- // @formatter:on
- }
- @Override
- public void configure(ResourceServerSecurityConfigurer resources)
- throws Exception {
- resources.resourceId("demo");
- }
- }
- @Configuration
- @EnableAuthorizationServer
- protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {
- @Autowired
- private AuthenticationManager authenticationManager;
- @Override
- public void configure(AuthorizationServerEndpointsConfigurer endpoints)
- throws Exception {
- endpoints.authenticationManager(authenticationManager);
- }
- }
- }
Add Comment
Please, Sign In to add comment