我需要在 JBoss 6.4.0 服务器上运行 Spring Boot(版本 1.3.0.RELEASE)应用程序。
最初遇到了以下问题,根据作者的建议添加了解决方案。
http://ilya-murzinov.github.io/articles/spring-boot-jboss/
但是我仍然遇到问题。该应用程序使用 Spring security 来管理访问,并且已配置为忽略某些路径。不幸的是,当在 JBoss 上运行时,设置为忽略的端点似乎没有被拾取,并且尝试登录失败(以及所有其他被忽略的端点)。
这里是一个代码示例,显示了如何实现端点忽略。也许这些实现不正确,或者排序有问题?
package com.company.product.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
/**
* The configuration class responsible for handling security
*/
@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Value("${server.servlet-path}")
private String basePath;
@Autowired
private JWTAuthenticationProvider authenticationProvider;
@Autowired
private TokenHandler tokenHandler;
/**
* Adding custom provider to global authentication manager
*
* @param auth the authentication manager
*/
@Autowired
public void configureGlobal(final AuthenticationManagerBuilder auth) {
auth.authenticationProvider(this.authenticationProvider);
}
@Override
public void configure(final WebSecurity web) throws Exception {
//Specifies unsecured end-points
//previous approach example
//web.ignoring().antMatchers(this.basePath + "/login")
web.ignoring().antMatchers(this.basePath + "/login/**") //end point still cannot be reached
.antMatchers(this.basePath + "/endpoint1/**")
.antMatchers(this.basePath + "/endpoint2/**")
.antMatchers(this.basePath + "/v2/endpoint3/**");
}
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.addFilterBefore(new StatelessAuthenticationFilter(this.tokenHandler),
UsernamePasswordAuthenticationFilter.class).authorizeRequests().anyRequest().authenticated().and()
.csrf().disable();
}
}
代码使用其嵌入式 Tomcat 服务器可以正常工作。
当我们尝试访问登录端点时,我们收到“访问被拒绝”错误。该端点不应具有任何安全性,我们已将其作为忽略模式添加到我们的配置中。忽略配置对于 html 等静态页面似乎可以正常工作,但在本例中则不然。
最佳答案
问题已解决。事实证明,问题不在于 Spring 安全性。由于缺少 LDAP 服务器,在 org.springframework.ldap.core.ContextSource getReadOnlyContext() 方法中抛出 NamingException。恢复此服务器解决了问题。
关于java - 在 JBoss 上运行 Spring Boot 应用程序 - 忽略端点的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35221365/