为什么Spring Security在Tomcat中可以工作,而在部署到Weblogic时却不能工作?

乔恩·海斯特

我不是真正的Java开发人员,但是需要为客户设计一个项目,所以也许我缺少明显的东西。

我正在使用SpringBoot,并且当应用程序在本地计算机和测试服务器上的Tomcat中运行时,一切正常。但是,一旦将应用程序部署到Weblogic,就好像没有安全性,所有路由都可访问。登录和注销路径也不存在。

话虽如此。其他一切似乎都可以正常工作,只是完全没有任何安全性。

我没有访问Weblogic的权限,因为客户端是部署代码的客户端,但是他们告诉我们它在12c上运行。我该怎么解决或解决此问题?

这是我的Application.java中的相关配置:

/**
 * The type Authentication security.
 */
@Order(Ordered.HIGHEST_PRECEDENCE)
@Configuration
protected static class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter {

    /**
     * The Users.
     */
    @Autowired
    private Users users;

    /**
     * Init void.
     *
     * @param auth the auth
     * @throws Exception the exception
     */
    @Override
    public void init(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(users).passwordEncoder(new BCryptPasswordEncoder());
    }
}

/**
 * The type Application security.
 */
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {

    /**
     * Configure void.
     *
     * @param http the http
     * @throws Exception the exception
     */
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        http.authorizeRequests()
                .antMatchers("/vendor/*","/public/**/*","/partners/*","/events/*", "/login").permitAll()
                .anyRequest().fullyAuthenticated().and().formLogin().loginPage("/login")
                .and().logout()
                .logoutRequestMatcher(new AntPathRequestMatcher("/logout")).and()
                .exceptionHandling().accessDeniedPage("/access?error");
        // @formatter:on
    }

}

提前致谢。

罗伯·温奇

听起来好像您正在遇到SEC-2465一样简而言之,WebLogic中存在一个与添加过滤器实例有关的错误。从上面的JIRA:

Oracle确认其为错误:17382048,已通过补丁16769849进行了修复。据报告已在WLS 12.1.3中修复。

客户端应更新其WebLogic服务器以获得修补程序。另外,您可以创建自己的AbstractSecurityWebApplicationInitializer版本,版本使用类方法注册springSecurityFilterChain:

servletContext.addFilter(String filterName, java.lang.Class<? extends Filter> filterClass)

然后,您的AbstractSecurityWebApplicationInitializer的子类将扩展自定义类。

更新资料

根据更新的信息,我仍然认为该问题与上述WebLogic错误有关。当使用SpringBootServletInitializer时,过滤器是作为实例而不是类FilterRegistrationBean一起添加的

最简单的选择是更新到WebLogic,因为一切都应该照常进行。

要解决该问题,您可以禁用Spring Security和任何其他过滤器的注册。您可以通过如下创建一个FilterRegistrationBean来做到这一点

@Bean
public FilterRegistrationBean springSecurityFilterChainRegistrationBean(@Qualifier("springSecurityFilterChain") Filter filter) {
    FilterRegistrationBean bean = new FilterRegistrationBean();
    bean.setFilter(filter);
    bean.setEnabled(false);
    return bean;
}

然后,您需要确保使用

servletContext.addFilter(String filterName, java.lang.Class<? extends Filter> filterClass)

通过实施,Spring Security可以通过上述机制进行注册WebApplicationInitializer例如,您可以创建以下类:

package demo;

import java.util.EnumSet;

import javax.servlet.FilterRegistration.Dynamic;
import javax.servlet.*;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.filter.DelegatingFilterProxy;

public class SecurityInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext context) throws ServletException {
        Dynamic registration =
                context.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class);
        EnumSet<DispatcherType> dispatcherTypes =
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR, DispatcherType.ASYNC);
        registration.addMappingForUrlPatterns(dispatcherTypes, true, "/*");
    }
}

DelegatingFilterProxy 将在每次调用doFilter时查找名称为“ springSecurityFilterChain”的bean并委托给它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么我的 bash 脚本可以在终端中工作,而在使用 crontab 时却不能?

为什么相同的Scala代码在命令行中可以正常工作而在Intellij中却不能正常工作?

为什么DocumentBuilder Parse在Eclipse中可以正常工作,而在IntelliJ IDEA中却不能工作?

为什么php脚本可以在免费托管上工作,而在我的vps上却不能工作?

为什么iptables NAT可以在mininet中工作,而iptables日志记录却不能工作?

为什么用xor交换在c ++中可以正常工作,而在java中却不能呢?一些困惑

为什么foldr可以在Haskell中的无限列表上工作,而foldl却不能呢?

为什么带有参数的object .__ new__在Python 2.x中不能正常工作,而在Python 3.3+中却不能正常工作?

为什么作为功能的Angular控制器可以工作,而封装中的控制器却不能工作呢?

为什么float类型在Keil上不能很好地工作,而在Eclipse(gcc)上却不能工作

为什么可以在PHP中覆盖实例变量,而在Java中却不能?

为什么`int;`可以在C语言中很好地编译,而在C ++中却不能?

为什么我的扬声器可以工作,但耳机却不能工作?

为什么bash test.sh可以工作,而./test.sh却不能工作?

为什么对于同一Backbone集合,fetch()可以工作,而sync()却不能工作?

为什么退出窗口按钮可以工作,但游戏中的退出按钮却不能工作?

为什么jQuery的.on()可以工作,而本机JavaScript的.addEventListener()却不能工作?

为什么端口3000可以工作,而其他端口却不能工作?

为什么此代码在Python 3.3中能很好地工作而在Python 2.7中却不能很好地工作?

为什么setLandingPageType(“ billing”)在沙盒中工作,而在PAYPAL PHP REST API SDK WebProfile中的实时版本中却不能工作

创建新列时,为什么它可以与函数一起工作,而没有它却不能?

为什么一种字体可以在IE中工作,而另一种却不能

为什么 zsh 中只有某些插件可以工作,而其他插件却不能?

为什么在单元测试中使用RESTful Web服务(使用javax.ws.rs。*和Jsersey)可以工作,但是提交给Spark时却不能工作?

为什么在nautilus中可以访问没有执行特权的目录,而在终端中却不能访问目录?

为什么在打印值时循环工作,但在将它们添加到列表时却不能工作?

在Laravel中,为什么在应用程序事件之前,Request :: segment()方法可以正常工作,而Route :: currentRouteName()却不能正常工作?

为什么您可以在for循环中遍历一个隐式元组,而在Python中却不能理解?

为什么C ++中的void方法可以返回void值,而在其他语言中却不能呢?