回不到的未来 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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)