令牌身份验证旁边的单个路径的Spring Security基本身份验证

时间:2017-04-07 09:17:16

标签: authentication spring-boot spring-security basic-authentication spring-security-oauth2

我有一个自定义的ResourceServerTokenServices:

@Configuration
public class CloudSecurityConfig {
    @Bean
    protected MyResourceServerTokenServices() {
        return new MyResourceServerTokenServices();
    }
}

然后我有follogin ResourceServerConfigurerAdapter:

@Configuration
@EnableWebSecurity
@EnableResourceServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityResourceConfiguration extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);

        http.authorizeRequests().accessDecisionManager(accessDecisionManager())
            .antMatchers("/h2-console/**").anonymous()
            .antMatchers("/health/**").permitAll()
            .antMatchers("/v*/api-docs").permitAll().anyRequest()
            .authenticated().and().httpBasic().and().headers()
            .frameOptions().disable();
    }

    @Bean
    protected UnanimousBased accessDecisionManager() {
        List<AccessDecisionVoter<? extends Object>> voterList = new ArrayList<>();
        WebExpressionVoter expressionVoter = new WebExpressionVoter();
        expressionVoter.setExpressionHandler(new OAuth2WebSecurityExpressionHandler());
        voterList.add(expressionVoter);
        voterList.add(new AuthenticatedVoter());
        return new UnanimousBased(voterList);
    }
}

现在我需要为一个端点添加基本身份验证(使用inMemory凭据)(比如/ myEndpoint **)。我怎样才能做到这一点?

谢谢!

0 个答案:

没有答案
相关问题