简体   繁体   English

登录成功时 Spring Oauth 和安全重定向到 /login

[英]Spring Oauth and security redirect to /login when login success

When use Spring security and oauth使用 Spring 安全和 oauth 时

I have a problem, when I login in successfully, it redirect to "/login", but I never set it, How can it redirect to the page before login?我有一个问题,当我成功登录时,它重定向到“/ login”,但我从未设置它,如何在登录前重定向到页面?

follow is details:以下是详细信息:

auth-center:认证中心:

spring:
  application:
    name: auth-server
server:
  port: 6001
  servlet:
    context-path: /uaa

the login page url: /login登录页面 url: /login

follow is the configure以下是配置

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.antMatcher("/**")
                .authorizeRequests()
                .antMatchers("/login", "/oauth/authorize**")
                .permitAll()
                .anyRequest()
                .authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .failureUrl("/login?error=true")
                .permitAll()
                .and()
                .logout()
                .invalidateHttpSession(true)
                .clearAuthentication(true)
                .logoutUrl("/logout")
                .and()
                .exceptionHandling()
                .accessDeniedPage("/403"); 

        http.cors().and().csrf().disable();
        http.sessionManagement().invalidSessionUrl("/login");
        http.sessionManagement().maximumSessions(1).maxSessionsPreventsLogin(true);
    }



client:客户:

server:
  port: 4000

security:
  oauth2:
    client:
      clientId: community
      clientSecret: 123456
      accessTokenUri: http://localhost:6001/uaa/oauth/token
      userAuthorizationUri: http://localhost:6001/uaa/oauth/authorize
    resource:
      userInfoUri: http://localhost:6001/uaa/oauth/user/me

follow is the security configure以下是安全配置

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                .logout()
                .invalidateHttpSession(true)
                .clearAuthentication(true)
                .logoutSuccessUrl("http://localhost:6001/uaa/auth/logout")
                .and()
                .exceptionHandling()
                .accessDeniedHandler(deniedHandler);

        http.csrf().disable();

        http.httpBasic().disable();
    }

when I login successfully, it will redirect to当我成功登录时,它将重定向到

http://localhost:6001/uaa/oauth/authorize?client_id=community&redirect_uri=http://127.0.0.1:4000/login&response_type=code&state=jy2gLx

but 4000 is client port.但 4000 是客户端端口。

I find the answer,There are some error in application.yml in the client我找到了答案,客户端的application.yml中有一些错误

resource:
      userInfoUri: http://localhost:6001/uaa/oauth/user/me

the url is wrong url 是错误的

resource:
      userInfoUri: http://localhost:6001/uaa/user/me

I correct it and it work我纠正它并且它工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM