您好,我有一个 Rest WS,使用 WebSecurityConfigurerAdapter 来实现 HTTP 基本身份验证。允许更新密码,我需要让 WS 在不重新启动服务器的情况下获取更新的密码以下是代码:安全配置// init a user with credentials admin/password@Configuration@EnableWebSecuritypublic class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http //disable csrf .csrf().disable() //authentic all requests .authorizeRequests().anyRequest().authenticated().and().httpBasic() //disable session .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); } @Override public void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(inMemoryUserDetailsManager()); } @Bean public InMemoryUserDetailsManager inMemoryUserDetailsManager() { Properties users = new Properties(); users.put("admin", "password,USER,enabled"); return new InMemoryUserDetailsManager(users); }}将更新密码的控制器@RestControllerpublic class someController{ @Autowired public InMemoryUserDetailsManager inMemoryUserDetailsManager; // update password from password -> pass @RequestMapping(...) public updatePass(){ ArrayList<GrantedAuthority> grantedAuthoritiesList = new ArrayList<>(); grantedAuthoritiesList.add(new SimpleGrantedAuthority("USER")); this.inMemoryUserDetailsManager.updateUser(new User("admin", "pass", grantedAuthoritiesList)); }第一次使用凭据 admin/password 调用 updatePass() 后,我可以看到密码已在调试器中更新为“pass”我认为如果我要再次调用 updatePass() ,我应该使用admin/pass。然而事实证明仍在使用旧的admin/password。我在编写此代码时引用的来源source1 source2*我正在使用 Advance Rest Client 拨打电话
添加回答
举报
0/150
提交
取消