java - 登录成功时,Spring Oauth 和安全重定向到 /login
问题描述
使用 Spring security 和 oauth 时
我有一个问题,当我成功登录时,它重定向到“/ login”,但我从未设置它,如何在登录前重定向到页面?
以下是详细信息:
认证中心:
spring:
application:
name: auth-server
server:
port: 6001
servlet:
context-path: /uaa
登录页面网址:/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
网址错误
resource:
userInfoUri: http://localhost:6001/uaa/user/me
我纠正它并且它工作
推荐阅读
- asp.net - 在 ASP.NET Core 中使用 Yandex 登录
- javascript - 即使我切换选项卡,css动画也在运行
- jenkins - Windows shell 命令失败,但在 Jenkins 管道中执行时返回 0
- python - Tkinter 仅在创建结束时显示
- ffmpeg - 为什么ffmpeg会导出黑色视频?
- python - 无法使用 ctypes 从 python 读取'const char *'
- jquery - Jquery Datatables 仅在几列的标题中添加搜索过滤器
- python - 使用 putty 私钥、sqlalchemy 和 pyodbc 从 linux 环境连接到 sql server
- visual-studio-code - VSCode:Markdown 文件使用 3 个空格而不是制表符缩进列表项
- openlayers - Openlayers 6.9.0,无法创建生产包