首先,我告诉你,我是一名初级开发人员。所以我请求你对我的问题宽容:)
我想做的是一个带有 Keycloak 的简单产品 POC,用于带有 Java 后端和 Postgres 数据库的 Angular 8 前端。我正在使用 OVH VPS,使用 Nginx / Certbot 进行 ssl 和 https 管理。
什么不起作用: - 访问私有 URL(受 keycloak 保护,在我的 Angular 应用程序中使用 [AppAuthGuard] :Keycloak 在登录页面上正确重定向,但登录不起作用。我从 Keycloak 收到错误:“我们抱歉...发生错误,请通过您的应用程序重新登录。”。
我的浏览器显示:“状态代码:400 错误请求”当我检查 Keycloak 容器日志时,出现警告:
WARN [org.keycloak.events] (default task-1) type=LOGIN_ERROR, realmId=TheLibrary, clientId=null, userId=null, ipAddress=192.168.80.1, error=invalid_code
Run Code Online (Sandbox Code Playgroud)
话虽这么说,我的网址确实有领域和 clientId,它必须在...
什么工作正常: - 使用我在 VPS 上创建的子域进行 url 重定向, - 访问我的 Keycloak 管理控制台, - 访问我的前端的公共 url(我的意思是没有 [AppAuthGuard] 的 url) - 一切,如果我运行我的本地环境中的后端/前端/Keycloak 代码,无需 ssl 或 https。
四天以来我一直在为登录错误而苦苦挣扎。这让我发疯……我几乎没有任何线索可以调查。
我在网上没有找到类似的问题。
我注意到的唯一一件事是,我的本地 poc 工作正常(使用本地独立的 …
我精确地说,我是Java Developper一年级的法国学生。
我正在使用以下程序开发一个多模块应用程序:Spring Boot,Spring安全性,Hibernate,Spring Data,Spring MVC和Thymeleaf。
我想在登录时在会话中设置User,或者至少在userId中设置。这样,我不必每次需要时都将其手动放入会话或模型中。
但是当我使用默认的Spring Security登录和身份验证配置时,我真的不知道如何或在何处调用这种方法:
void putUserInHttpSession( HttpSession httpSession ) {
httpSession.setAttribute( "user" , getManagerFactory().getUserManager().findByUserName( SecurityContextHolder.getContext().getAuthentication().getName()) );
}
Run Code Online (Sandbox Code Playgroud)
我可以在需要的时候做到这一点,但我发现很难做到不只是在登录时这样做!
这是我认为您可能需要帮助的内容(那真是太棒了!!! :)
我的WebSecurityConfig类:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsServiceImpl userDetailsService;
@Autowired
private DataSource dataSource;
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// Setting Service to find User in the database.
// And Setting PassswordEncoder
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Override
protected void configure( HttpSecurity http ) …Run Code Online (Sandbox Code Playgroud)