我需要在JBoss 6.4.0服务器上运行Spring (版本1.3.0.RELEASE)应用程序。
最初,遇到了以下问题,并根据提交人的建议添加了一个解决方案。
http://ilya-murzinov.github.io/articles/spring-boot-jboss/
然而,我仍然遇到了一个问题。应用程序使用Spring安全性来管理访问,并且它被配置为忽略某些路径。不幸的是,当在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 ),忽略配置似乎可以正常工作,但在本例中则不行。
发布于 2016-02-08 08:58:00
这个问题已经解决了。事实证明,问题不在于Spring的安全性。由于缺少LDAP服务器,NamingException在org.springframework.ldap.core.ContextSource getReadOnlyContext()方法中被抛出。恢复此服务器修复了问题。
https://stackoverflow.com/questions/35221365
复制相似问题