有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将SpringWeb应用程序(Web.xml)迁移到Springboot 1.5.10

我在生产中有三个应用程序,我试图一次迁移一个应用程序到SpringBoot1.5.10。我们使用基本身份验证,并且用户凭证在tomcat用户中。xml文件,如果应用程序部署在Tomcat中,或部署在应用程序用户中。属性文件,如果是Wildfly。我们的配置允许用户进行一次身份验证,而无需在每个应用程序中进行身份验证

我在迁移网站的一小部分时遇到问题。xml到Java,请参见以下内容:

<web-app>
   <security-constraint>
      <web-resource-collection>
        <web-resource-name>All resources</web-resource-name>
        <description>Protects all resources</description>
        <url-pattern>/*</url-pattern>
      </web-resource-collection>
      <auth-constraint>
        <role-name>*</role-name>
      </auth-constraint>
   </security-constraint>

   <login-config>
      <auth-method>BASIC</auth-method>
      <realm-name>myRealm</realm-name>
   </login-config>

   <security-role>
      <role-name>*</role-name>
   </security-role>

   <error-page>
     <exception-type>java.lang.Throwable</exception-type>
     <location>/aviso_page.jsp</location>
   </error-page>
</web-app>

下面是我用java进行配置的尝试。我的网站安全配置适配器是:

@ComponentScan
@EnableGlobalMethodSecurity(securedEnabled = true)
public class MySecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired MyAuthProvider myAuthProvider;

    @Override
    protected void configure(final HttpSecurity http) throws Exception {
         http
             .authorizeRequests()
             .anyRequest().fullyAuthenticated()
           .and()
             .httpBasic()
             .realmName("myRealm")
          .and()
            .csrf().disable();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) {
         auth.authenticationProvider(myAuthProvider);
    }
 }

我的身份验证提供程序是:

@Component
public class MyAuthProvider implements AuthenticationProvider {

  @Override
  public Authentication authenticate(Authentication authentication) {
    UsernamePasswordAuthenticationToken authenticationToken = (UsernamePasswordAuthenticationToken) authentication;
    Object login = authenticationToken.getPrincipal();
    Object password = authenticationToken.getCredentials();

    return new UsernamePasswordAuthenticationToken(login, password);
  }

  @Override
  public boolean supports(Class<?> authentication) {
    return authentication.equals(UsernamePasswordAuthenticationToken.class);
  }

}

使用这种Java配置,我无法使用tomcat用户进行身份验证。xml或应用程序用户。属性,也不能在三个应用程序之间共享身份验证

那么,我做错了什么


共 (0) 个答案