回不到的未来 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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料