私はSpringの上に構築したWebサービスを持っています。Springセキュリティによる認可と認証
@Configuration
@EnableGlobalMethodSecurity(securedEnabled=true)
@EnableWebSecurity
public class ServerSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private Properties properties;
private static final String ALL_URI = "/v1/**";
private static final String HEALTH_URI = "/v1/healthCheck";
@Override
protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(getFilter(), BasicAuthenticationFilter.class);
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.authorizeRequests()
.antMatchers(HEALTH_URI).permitAll()
.anyRequest().authenticated();
http.csrf().disable();
}
private AuthenticationFilter getFilter() {
return new AuthenticationFilter(properties.getKey());
}
}
私AuthenticationFilter
クラスはAbstractAuthenticationProcessingFilter
を拡張し、実際の認証を行い、次のように私は現在、春のセキュリティを使用して認証しています。私のセキュリティに認証を追加したいのであれば、認証フィルターのattemptAuthentication
メソッドでこれらのチェックを行うだけですか?それとももっと良い方法がありますか?私が理解しているのは、認可と認証を別々に行うべきだということです。最初に認証し、アクセス許可を確認します。だから、私は、Spring Security内で許可を行うより良いアプローチが、attemptAuthentication
メソッドに追加するよりもむしろ良いと思うでしょう。