情况:
def str = """
<foo xmlns:weird="http://localhost/">
<bar>sudo </bar>
<weird:bar>make me a sandwich!</weird:bar>
</foo>
"""
def xml = new XmlSlurper().parseText(str)
println xml.bar
Run Code Online (Sandbox Code Playgroud)
这个片段的输出是
# sudo make me a sandwich!
Run Code Online (Sandbox Code Playgroud)
似乎解析器合并了<bar>和的内容<weird:bar>.
是否需要这种行为,如果是,我该如何避免这种情况并仅选择<bar>或<weird:bar>?
是否可以以从外部文件读取配置详细信息并相应配置的方式配置Spring安全性.
(我不是在运行时更改配置.我在谈论在启动时从文件中读取)
我现有 Sporing安全配置的一个示例是:
@EnableWebSecurity
@Configuration
public class SecurityConfig {
@Bean
public UserDetailsService userDetailsService() throws Exception {
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
manager.createUser(User.withUsername("user").password("userPass").roles("USER").build());
manager.createUser(User.withUsername("admin").password("adminPass").roles("ADMIN").build());
return manager;
}
@Configuration
@Order(1)
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
public void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication().withUser("user").password("user").roles("USER");
auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN");
}
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/api/v1/**")
.authorizeRequests()
.antMatchers("/api/v1/**").authenticated()
.and()
.httpBasic();
}
}
@Configuration
@Order(2)
public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
public void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication().withUser("user1").password("user").roles("USER"); …Run Code Online (Sandbox Code Playgroud)