Spring security 在jhipster生成的应用程序中使用spring security进行用户模拟

Spring security 在jhipster生成的应用程序中使用spring security进行用户模拟,spring-security,jhipster,impersonation,Spring Security,Jhipster,Impersonation,我已将jhipster应用程序部署为双节点设置。当我登录node1时 并将资产转移到另一个具有不同使用角色的节点2,但我不知道节点2用户的密码。要求管理员/超级用户能够以任何其他用户的身份登录并切换到原始用户。我使用spring security尝试了SwitchUserFilter @EnableWebSecurity @EnableGlobalMethodSecurity(Prespenabled=true,securedEnabled=true) @导入(SecurityProblemSu

我已将jhipster应用程序部署为双节点设置。当我登录node1时 并将资产转移到另一个具有不同使用角色的节点2,但我不知道节点2用户的密码。要求管理员/超级用户能够以任何其他用户的身份登录并切换到原始用户。我使用spring security尝试了
SwitchUserFilter

@EnableWebSecurity
@EnableGlobalMethodSecurity(Prespenabled=true,securedEnabled=true)
@导入(SecurityProblemSupport.class)
公共类安全配置扩展了WebSecurity配置适配器{
专用最终令牌提供者令牌提供者;
私人最终公司过滤器;
私人最终证券问题支持问题支持;
@豆子
公共SwitchUserFilter SwitchUserFilter(){
SwitchUserFilter SwitchUserFilter=新的SwitchUserFilter();
setUserDetailsService(userDetailsService());
switchUserFilter.setSwitchUserUrl(“/impersonate”);
switchUserFilter.setSwitchFailureUrl(“/switchUser”);
返回开关用户过滤器;
}
公共安全配置(令牌提供程序令牌提供程序、CorsFilter CorsFilter、SecurityProblemSupport problemSupport){
this.tokenProvider=tokenProvider;
this.corsFilter=corsFilter;
this.problemSupport=problemSupport;
}
@豆子
公共密码编码器PasswordEncoder(){
返回新的BCryptPasswordEncoder();
}
@凌驾
public void configure(WebSecurity web)引发异常{
忽略
.antMatchers(HttpMethod.OPTIONS,“/**”)
.antMatchers(“/swagger ui/index.html”)
.antMatchers(“/test/**”);
}
@凌驾
public void configure(HttpSecurity http)引发异常{
//@formatter:off
http
.csrf()
.disable()
.addFilterBefore(corsFilter,UsernamePasswordAuthenticationFilter.class)
.例外处理()
.authenticationEntryPoint(问题支持)
.accessDeniedHandler(问题支持)
.及()
.headers()
.frameOptions()
.disable()
.及()
.会议管理()
.sessionCreationPolicy(sessionCreationPolicy.STATELESS)
.及()
.授权请求()
.antMatchers(“/api/authenticate”).permitAll()
.antMatchers(“/api/register”).permitAll()
.antMatchers(“/api/activate”).permitAll()
.antMatchers(“/api/account/reset password/init”).permitAll()
.antMatchers(“/api/account/reset password/finish”).permitAll()
.antMatchers(“/api/**”).authenticated()
.antMatchers(“/management/health”).permitAll()
.antMatchers(“/management/info”).permitAll()
.antMatchers(“/management/prometheus”).permitAll()
.antMatchers(“/switchUser”).hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers(“/management/**”).hasAuthority(AuthoritiesConstants.ADMIN)
.及()
.apply(securityConfigureAdapter());
//@formatter:on
}
@豆子
@凌驾
公共用户详细信息服务用户详细信息服务(){
用户详细信息用户=
User.withDefaultPasswordEncoder()
.用户名(“用户”)
.密码(“密码”)
.角色(“角色\管理”)
.build();
UserDetails admin=User.withDefaultPasswordEncoder()
.用户名(“管理员”)
.密码(“管理员”)
.角色(“角色\管理”)
.build();
返回新的InMemoryUserDetailsManager(用户、管理员);
}
专用JWTConfigurer安全配置适配器(){
返回新的JWTConfigurer(令牌提供者);
}
}

SwitchUserFilter
SecurityConfiguration.java进行更改后,如何调用/模拟url?我应该在UserResource.java中创建rest端点吗?

您解决了这个问题吗?你有答案吗?我已经按照这个例子使用超级用户admin对外部节点进行了身份验证。你只需要在代码下面添加UserJwtController.java。你解决了这个问题吗?你有答案吗?我已经按照这个例子使用超级用户admin对外部节点进行了身份验证。你只需要在下面的代码中添加UserJwtController.java