[英]Spring Oauth and security redirect to /login when login success
使用 Spring 安全和 oauth 時
我有一個問題,當我成功登錄時,它重定向到“/ login”,但我從未設置它,如何在登錄前重定向到頁面?
以下是詳細信息:
認證中心:
spring:
application:
name: auth-server
server:
port: 6001
servlet:
context-path: /uaa
登錄頁面 url: /login
以下是配置
@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);
}
客戶:
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
以下是安全配置
@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();
}
當我成功登錄時,它將重定向到
http://localhost:6001/uaa/oauth/authorize?client_id=community&redirect_uri=http://127.0.0.1:4000/login&response_type=code&state=jy2gLx
但 4000 是客戶端端口。
我找到了答案,客戶端的application.yml中有一些錯誤
resource:
userInfoUri: http://localhost:6001/uaa/oauth/user/me
url 是錯誤的
resource:
userInfoUri: http://localhost:6001/uaa/user/me
我糾正它並且它工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.