질문
312
작성한 질문수 2
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
- 먼저 유사한 질문이 안녕하세요
실전프로젝트 -인증 프로세스 Form 인증 구현 - 1강을 듣고 따라하고있는데
저는 user ID로 로그인했을때 /messages에도 접근가능한데 왜 이럴까요 ㅠㅠ
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
//사용자 추가
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
String password = passwordEncoder().encode("1111");
auth.inMemoryAuthentication().withUser("user").password(password).roles("USER");
auth.inMemoryAuthentication().withUser("manager").password(password).roles("MANAGER");
auth.inMemoryAuthentication().withUser("admin").password(password).roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll() //루트 페이지는 전부 접근 가능
.antMatchers("/config").hasRole("ADMIN")
.antMatchers("/messages").hasRole("MANAGER")
.antMatchers("/mypage").hasRole("USER")
.anyRequest().authenticated()
.and()
.formLogin();
}
}@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
//사용자 추가
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
String password = passwordEncoder().encode("1111");
auth.inMemoryAuthentication().withUser("user").password(password).roles("USER");
auth.inMemoryAuthentication().withUser("manager").password(password).roles("MANAGER");
auth.inMemoryAuthentication().withUser("admin").password(password).roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll() //루트 페이지는 전부 접근 가능
.antMatchers("/config").hasRole("ADMIN")
.antMatchers("/messages").hasRole("MANAGER")
.antMatchers("/mypage").hasRole("USER")
.anyRequest().authenticated()
.and()
.formLogin();
}
}있었는지 검색해보세요.
- 서로 예의를 지키며 존중하는 문화를 만들어가요.
- 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.
답변 1
0
네
코드에는 특별한 문제가 없어 보입니다.
그리고 제가 위의 코드로 직접 테스트해 봐도 /messages 로 user 계정으로 접근하면 접근이 거부되고 있습니다
즉 Forbidden, status=403 이 나오고 있습니다.
그래서 정상 동작하는 것 같습니다.
호출 url 이 정확한지 확인 해 보시기 바랍니다.
시큐리티 공부 버전 질문
0
190
1
[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈
0
197
1
AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우
0
186
1
강의 코드가 왜이렇게 뒤죽박죽인가요...
0
271
1
메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..
0
248
1
파라미터값이 넘어가지 않습니다 ....
0
382
1
security filterChain 설정 질문이 있습니다.
0
337
1
소스 부분 질문 드립니다.
0
213
2
섹션4 7번 강의 문제가 있는거 같네요.
0
352
2
파일이 수시로 이름이 바껴있네요 ㄷㄷ
0
312
1
HttpSessionSecurityContextRepository를 사용안하는 문제
0
566
2
error , exception 이 잘 안됩니다.
0
289
2
thymeleaf tag 질문합니다.
0
201
2
버전업하면서 deprecated된 것들이 너무많아요
0
483
1
spring security 패치 관련
0
442
1
모바일을 사용할때 토큰말고 세션
0
869
2
DB 연동한 인가 부분에 대한 질문입니다!
0
269
1
Ajax방식도 똑같이 Session방식을 사용하는건가요?
0
313
1
Config 파일 생성 시 질문이 있습니다.
0
238
1
강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..
1
443
2
403 에러 뜹니다.
0
828
2
login_proc의 존재에 대한 간략한 설명입니다
0
283
1
top.html에 로그인 링크를 만들어서 로그인을 해봤습니다
0
295
2
안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!
0
196
1





