자바/Spring

Spring Security Authorization(권한 부여)

끄적끄적 2023. 9. 17. 20:06
  • Authority : String형태(Read, Write 등)의 권한을 정의하거나 ROLE(Autority에는 ROLE_권한형태로 저장) 사용
  • AuthorizationFilter에서 AuthorizationManager(주로 AuthorityAuthorizationManager)에 의해 체크됨

AuthorizationFilter
권한부여

 

  • mvcMatchers : *는 한 경로 이름 대체, **는 여러 경로이름 대체, 정규식 가능
    • antMatchers : 사용법은 유사하나 /hello 경로에 지정할 경우 /hello/ 경로는 제외된다(mvcMatcher는 둘다 포함됨)
http.authorizeRequests()
    .mvcMatchers(HttpMethod.GET, "/a").authenticated()
    .mvcMatchers(HttpMethod.POST, "/a").permitAll()
    .anyRequest().denyAll();
                
http.authorizeRequests()
    .mvcMatchers( "/a/b/**").authenticated()
    .anyRequest().permitAll();
    
http.authorizeRequests()
    .mvcMatchers( "/product/{code:^[0-9]*$}").permitAll()
    .anyRequest().denyAll();
반응형