Spring boot 使用自定义登录页(不使用keybeapt';的默认登录页登录)将keybeapt与Spring boot集成
我正在努力实现的目标: 用户可以使用我们项目的登录页面(在项目内)登录,而无需重定向到KeyClope的默认登录页面。我已经用keydove配置了spring安全性,它工作正常,但用户通过keydove的默认登录页面登录 我的问题:我如何实现这个特性,我将使用RESTAPI从KeyClope获得令牌,比如 并允许访问我的Spring项目(Spring security) 据我所知,我可以在我的前端使用jquery登录并获取令牌,最终传递给spring security或其他任何东西Spring boot 使用自定义登录页(不使用keybeapt';的默认登录页登录)将keybeapt与Spring boot集成,spring-boot,spring-security,keycloak,Spring Boot,Spring Security,Keycloak,我正在努力实现的目标: 用户可以使用我们项目的登录页面(在项目内)登录,而无需重定向到KeyClope的默认登录页面。我已经用keydove配置了spring安全性,它工作正常,但用户通过keydove的默认登录页面登录 我的问题:我如何实现这个特性,我将使用RESTAPI从KeyClope获得令牌,比如 并允许访问我的Spring项目(Spring security) 据我所知,我可以在我的前端使用jquery登录并获取令牌,最终传递给spring security或其他任何东西 任何帮助都将
任何帮助都将不胜感激我们已经找到了解决此问题的好方法,我将逐步解释: 首先,如果您想使用自定义登录页面,您有两个选项: 1.修改现有的keydeport主题,如login/registration/passwordupdate,可通过/keydeport/themes目录找到/* 2.这可能有点棘手-可以通过在项目中修改Spring Security的AuthenticationProvider来实现
override fun configure(http: HttpSecurity?) {
http
?.authorizeRequests()
?.antMatchers("/**")?.authenticated()
?.and()
?.authenticationProvider(myAuthenticationProvider)
?.formLogin()
?.loginPage("/login")
?.successHandler { request, response, authentication -> redirectStrategy.sendRedirect(request, response, "/main")}
?.permitAll()
?.usernameParameter("username") //the username parameter in the queryString, default is 'username'
?.passwordParameter("password") //the password parameter in the queryString, default is 'password'
?.and()
?.logout()
?.logoutUrl("/logout") //the URL on which the clients should post if they want to logout
?.invalidateHttpSession(true)
?.and()
?.exceptionHandling()
}
MyAuthenticationProvider您应该重写此spring安全类
在上面的问题中,我又问了一件事,如果我使用RESTAPI访问spring项目,在这种情况下,您应该实现Key隐形WebSecurityConfigureAdapter而不是WebSecurityConfigureAdapter,该怎么办
如果有什么不合理的,你可以随时与我联系。)
override fun configure(http: HttpSecurity?) {
http
?.authorizeRequests()
?.antMatchers("/**")?.authenticated()
?.and()
?.authenticationProvider(myAuthenticationProvider)
?.formLogin()
?.loginPage("/login")
?.successHandler { request, response, authentication -> redirectStrategy.sendRedirect(request, response, "/main")}
?.permitAll()
?.usernameParameter("username") //the username parameter in the queryString, default is 'username'
?.passwordParameter("password") //the password parameter in the queryString, default is 'password'
?.and()
?.logout()
?.logoutUrl("/logout") //the URL on which the clients should post if they want to logout
?.invalidateHttpSession(true)
?.and()
?.exceptionHandling()
}