File tree Expand file tree Collapse file tree 3 files changed +45
-7
lines changed
Expand file tree Collapse file tree 3 files changed +45
-7
lines changed Original file line number Diff line number Diff line change 1+ package ru .javaops .bootjava .config ;
2+
3+ import org .springframework .beans .factory .annotation .Autowired ;
4+ import org .springframework .context .annotation .Configuration ;
5+ import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
6+ import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
7+ import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
8+ import org .springframework .security .crypto .factory .PasswordEncoderFactories ;
9+
10+ @ Configuration
11+ @ EnableWebSecurity
12+ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
13+
14+ @ Autowired
15+ public void configureGlobal (AuthenticationManagerBuilder auth ) throws Exception {
16+ auth .inMemoryAuthentication ()
17+ .passwordEncoder (PasswordEncoderFactories .createDelegatingPasswordEncoder ())
18+ .withUser ("user@gmail.com" ).password ("{noop}password" ).roles ("USER" ).and ()
19+ .withUser ("admin@javaops.ru" ).password ("{noop}admin" ).roles ("USER" , "ADMIN" );
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ package ru .javaops .bootjava .web ;
2+
3+ import org .springframework .http .MediaType ;
4+ import org .springframework .security .core .annotation .AuthenticationPrincipal ;
5+ import org .springframework .web .bind .annotation .GetMapping ;
6+ import org .springframework .web .bind .annotation .RequestMapping ;
7+ import org .springframework .web .bind .annotation .RestController ;
8+
9+ @ RestController
10+ @ RequestMapping (value = "/api/account" )
11+ public class AccountController {
12+
13+ @ GetMapping (produces = MediaType .APPLICATION_JSON_VALUE )
14+ public Object get (@ AuthenticationPrincipal Object authUser ) {
15+ return authUser ;
16+ }
17+ }
Original file line number Diff line number Diff line change @@ -33,18 +33,18 @@ spring:
3333 basePath : /api
3434 returnBodyOnCreate : true
3535
36- # https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#security-properties
37- security :
38- user :
39- name : user
40- password : password
41- roles : USER
36+ # https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#security-properties
37+ # security:
38+ # user:
39+ # name: user
40+ # password: password
41+ # roles: USER
4242
4343logging :
4444 level :
4545 root : WARN
4646 ru.javaops.bootjava : DEBUG
47- org.springframework.security.web.FilterChainProxy : DEBUG
47+ # org.springframework.security.web.FilterChainProxy: DEBUG
4848
4949# Jackson Serialization Issue Resolver
5050# jackson:
You can’t perform that action at this time.
0 commit comments