How to secure a MVC application with OAuth2 using Spring?

前端 未结 2 1881
长发绾君心
长发绾君心 2021-01-11 19:13

Sorry, my English.

I have an application I can login in the usual way.

@Configuration
@EnableWebSecurity
public class LoginSecurityConfig extends We         


        
2条回答
  •  暖寄归人
    2021-01-11 19:51

    Simple as 1,2,3 ...

    Just change a little my OAuth2 server to accept oauth/authorize method.

    @Override
    protected void configure(HttpSecurity http) throws Exception {
    
        http
            .requestMatchers()
            .antMatchers("/login", "/oauth/authorize")
        .and()
            .authorizeRequests()
            .anyRequest()
            .authenticated()
        .and()
            .formLogin()
            .permitAll();       
    }
    

    and create a custom login form. Now all clients (web applications) can login into it.

    Here you can find a sample client and a more details: http://www.baeldung.com/sso-spring-security-oauth2

    Also you can check my entire server and client at my github repo:

    https://github.com/icemagno/geoinfra/cerberus

    and

    https://github.com/icemagno/geoinfra/atlas

    It is in pt_BR

提交回复
热议问题