Spring Boot OAuth2.0授权问题

时间:2020-05-10 19:29:57

标签: spring-boot spring-security oauth-2.0

用户如何通过Spring Boot OAuth 2.0获取数据?用户可以进行身份​​验证,但随后无法接收数据。

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            .antMatchers("/addPet").access("hasAnyAuthority('USER', 'ADMIN')")
            .antMatchers("/", "/**").access("permitAll")
            .and().formLogin().loginPage("/login").loginProcessingUrl("/login").usernameParameter("login").passwordParameter("password")
            .defaultSuccessUrl("/", true)
            .and().oauth2Login().loginPage("/login")
            .defaultSuccessUrl("/", true)
            .and().logout().logoutSuccessUrl("/").deleteCookies("JSESSIONID").and().csrf().disable();
}

@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
    auth.jdbcAuthentication().dataSource(dataSource)
            .usersByUsernameQuery(
                    "select login, password, enabled from users where login=?")
            .authoritiesByUsernameQuery(
                    "select login, role from users where login=?");
}

1 个答案:

答案 0 :(得分:0)

用户可以通过以下方式从网站获取信息:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            .antMatchers("/addPet").authenticated()
            .antMatchers("/", "/**").access("permitAll")
            .and().oauth2Login().loginPage("/login").defaultSuccessUrl("/", true).and().logout().logoutSuccessUrl("/")


            .and().formLogin().loginPage("/login").loginProcessingUrl("/login").usernameParameter("login").passwordParameter("password")
            .defaultSuccessUrl("/", true).and().logout().logoutSuccessUrl("/").deleteCookies("JSESSIONID").and().csrf().disable()

    ;

}