回不到的未来 2018-12-21 18:30 采纳率: 0%
浏览 1420

spring oauth2 资源服务器问题

我定义了三个类

@Configuration
@EnableWebSecurity
public class BCSecurityConfig extends WebSecurityConfigurerAdapter{

    @Autowired
    private DataSource dataSource;


    @Override
    public void configure(HttpSecurity http) throws Exception {
        super.configure(http);
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.jdbcAuthentication().dataSource(dataSource);
    }

}

另外两个是认证服务器

@Configuration
@EnableAuthorizationServer
public class BCAuthorizationServerConfig {

}

和资源服务器

@Configuration
@EnableResourceServer
public class BCResourceServerConfig extends ResourceServerConfigurerAdapter{

    @Override
    public void configure(HttpSecurity http) throws Exception {
        //表单登录 方式
        http.formLogin().and()
                .authorizeRequests()
                .antMatchers("/api/**")
                .authenticated()
                .antMatchers("/oauth/token").permitAll()
                .and()
                .csrf().disable();
    }

}

有一个问题就是,当你配置了资源服务器的时候访问需要认证的链接返回的是
图片说明
这是没有问题的,但是我想实现的是当你在没有认证的情况下访问其他的链接的时候自动跳转到登录页,也就是我想让BCResourceServerConfig资源服务器不处理的链接交给我配置的BCSecurityConfig这个类处理?请问怎么实现呢,请不吝赐教不胜感激!!!

我的最终目的是它既能提供安全的网页服务(登陆验证)!又能够通过oauth提供token

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘