File tree Expand file tree Collapse file tree 3 files changed +23
-6
lines changed
src/main/java/ru/techdemo Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ Spring:
2020@EnableOAuth2Sso makes application an OAuth2 client
2121############################################################################################################################################
2222#################################################### INTERNAL OAUTH2 SECTION ###############################################################
23- Application deploys on localhost:8080, context path is /
23+ Application deploying on localhost:8080, context path is /
2424Therefore if we try to get resource /api/users we send HTTP GET on localhost:8080/api/users, but without Oauth2 token we getting
2525401 Response with following JSON:
2626{
@@ -82,6 +82,7 @@ You'll receive following JSON on userInfo request:
8282{
8383 "sub": "mjolnir"
8484}
85+
8586###########################################################################################################################################
8687############################################################## RESOURCES ##################################################################
8788OAuth protocol description: https://tools.ietf.org/html/rfc6749#section-3
Original file line number Diff line number Diff line change 55 */
66package ru .techdemo .controllers .api ;
77
8- import org .springframework .web .bind .annotation .RequestMapping ;
8+ import java .util .List ;
9+ import org .springframework .beans .factory .annotation .Autowired ;
10+ import org .springframework .web .bind .annotation .GetMapping ;
11+ import org .springframework .web .bind .annotation .PathVariable ;
912import org .springframework .web .bind .annotation .RestController ;
13+ import ru .techdemo .dal .IApplicationDataContext ;
14+ import ru .techdemo .dal .entity .UserEntity ;
1015
1116@ RestController
1217public class UsersController {
1318
14- // todo: umv: implement proiperly, get from context
15- @ RequestMapping ( "/api/users" )
16- public String get (){
17- return "{ \" userId \" : \" 0 \" , \" userName \" : \" admin \" }" ;
19+ @ GetMapping ( "/api/users" )
20+ public List < UserEntity > get (){
21+ List < UserEntity > users = dataContext . getUsersRepository (). getAll ();
22+ return users ;
1823 }
24+
25+ @ GetMapping ("/api/users/{id}" )
26+ public UserEntity get (@ PathVariable (required = true )Long id ){
27+ UserEntity user = dataContext .getUsersRepository ().getById (id );
28+ return user ;
29+ }
30+
31+ @ Autowired
32+ IApplicationDataContext dataContext ;
1933}
Original file line number Diff line number Diff line change 99import java .util .Arrays ;
1010import java .util .List ;
1111import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
12+ import org .springframework .stereotype .Service ;
1213import ru .techdemo .dal .entity .RoleEntity ;
1314import ru .techdemo .dal .entity .UserEntity ;
1415import ru .techdemo .dal .repository .IRepository ;
1516import ru .techdemo .dal .repository .MockRepository ;
1617
1718
19+ @ Service
1820public class InMemoryMockApplicationContext implements IApplicationDataContext {
1921
2022 public InMemoryMockApplicationContext (){
You can’t perform that action at this time.
0 commit comments