小编Sus*_*del的帖子

Spring Security的@EnableWebSecurity vs oauth的@EnableResourceServer

我有一个使用Spring Boot,Angular 2,Spring OAuth 2的系统,我使用@EnableWebSecurity实现了安全性,并在同一个应用程序中使用@EnableResourceServer和@EnableAuthorizationServer实现了oauth.

以下是已实现的类:

SecurityConfig.java

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {


    @Autowired
    private ClientDetailsService clientDetailsService;

    @Autowired
    public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("user").password("pass").roles("USER").and()
                .withUser("username").password("password").roles("USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                .antMatchers("/private/**").hasRole("USER")
                .antMatchers("/public/**").permitAll();
    }

    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
}
Run Code Online (Sandbox Code Playgroud)

AuthorizationServerConfig.java

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    @Qualifier("authenticationManagerBean")
    private AuthenticationManager authenticationManager;

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {

        clients.inMemory()
                .withClient("my-trusted-client") …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security oauth-2.0 spring-boot

5
推荐指数
1
解决办法
1157
查看次数

标签 统计

java ×1

oauth-2.0 ×1

spring ×1

spring-boot ×1

spring-security ×1