2016-02-05 66 views
0

我有要求在JBoss 6.4.0服务器上运行Spring Boot(version 1.3.0.RELEASE)应用程序。在JBoss上运行Spring Boot应用程序 - 忽略端点的问题

最初,遇到了以下问题,并根据作者的建议添加了解决方案。

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),忽略配置似乎工作正常,但在这种情况下不会。

+1

检查'basePath'属性是否正确填充,是否与您期望的匹配。 –

+0

Thanks @ M.Deinum是的,basePath具有期望的值。 – Gordon

回答

0

问题已解决。事实证明,问题不在于Spring安全性。由于缺少LDAP服务器,在org.springframework.ldap.core.ContextSource getReadOnlyContext()方法中抛出了NamingException。恢复此服务器解决了问题。

相关问题