File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
spring-security-oauth-resource/src/main/java/org/baeldung/web/controller Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 3
3
import static org .apache .commons .lang3 .RandomStringUtils .randomAlphabetic ;
4
4
import static org .apache .commons .lang3 .RandomStringUtils .randomNumeric ;
5
5
6
+ import java .util .Map ;
7
+
6
8
import org .baeldung .web .dto .Foo ;
7
9
import org .springframework .http .HttpStatus ;
8
10
import org .springframework .security .access .prepost .PreAuthorize ;
11
+ import org .springframework .security .core .Authentication ;
12
+ import org .springframework .security .oauth2 .provider .authentication .OAuth2AuthenticationDetails ;
9
13
import org .springframework .stereotype .Controller ;
10
14
import org .springframework .web .bind .annotation .PathVariable ;
11
15
import org .springframework .web .bind .annotation .RequestBody ;
@@ -25,7 +29,11 @@ public FooController() {
25
29
@ PreAuthorize ("#oauth2.hasScope('foo') and #oauth2.hasScope('read')" )
26
30
@ RequestMapping (method = RequestMethod .GET , value = "/foos/{id}" )
27
31
@ ResponseBody
28
- public Foo findById (@ PathVariable final long id ) {
32
+ public Foo findById (@ PathVariable final long id , Authentication auth ) {
33
+ OAuth2AuthenticationDetails oauthDetails = (OAuth2AuthenticationDetails ) auth .getDetails ();
34
+ Map <String , Object > details = (Map <String , Object >) oauthDetails .getDecodedDetails ();
35
+ System .out .println ("User organization is " + details .get ("organization" ));
36
+
29
37
return new Foo (Long .parseLong (randomNumeric (2 )), randomAlphabetic (4 ));
30
38
}
31
39
You can’t perform that action at this time.
0 commit comments