英文:
Custom Realm not invoked in the Spring Boot Application
问题
Spring Boot版本:2.2.6.RELEASE
我正在将一个旧的应用程序迁移到Spring Boot。在旧的应用程序中,在Tomcat的server.xml中,我有以下Realm配置:
<Realm className="com.test.realm.AuthServletRealm" authServletUrl="http://localhost:8080/dh-services/auth" allowInternalToken="true" tokenValidationPeriod="60000"/>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="com.test.realm.AuthServletValve" />
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
<Valve className="org.apache.catalina.valves.ErrorReportValve" showReport="false" showServerInfo="false" />
</Host>
我正在尝试将这个配置转换为一个Spring配置类,代码如下:
@Configuration
public class TomcatConfiguration {
@Bean
public ConfigurableServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addContextCustomizers(TomcatConfiguration::customize);
factory.addEngineValves(new SingleSignOn());
factory.addEngineValves(new ErrorReportValve());
factory.addContextValves(new AuthServletValve());
return factory;
}
private static void customize(Context context) {
context.setRealm(new AuthServletRealm());
context.addConstraint(createSecurityConstraint());
}
private static SecurityConstraint createSecurityConstraint() {
SecurityConstraint securityConstraint = new SecurityConstraint();
SecurityCollection securityCollection = new SecurityCollection();
securityCollection.addPattern("/*");
securityConstraint.addCollection(securityCollection);
return securityConstraint;
}
}
阀门被正确调用,但是我的AuthServletValve没有被调用。我期望在每次调用我的Spring Boot API时,AuthServletValve被调用以获取主体。但什么都没有发生。
英文:
Spring boot version: 2.2.6.RELEASE
I'm migrating a legacy application to the Spring Boot.
In the legacy application, in the server.xml of the Tomcat, I had the following Realm configuration:
<Realm className="com.test.realm.AuthServletRealm" authServletUrl="http://localhost:8080/dh-services/auth" allowInternalToken="true" tokenValidationPeriod="60000"/>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="com.test.realm.AuthServletValve" />
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
<Valve className="org.apache.catalina.valves.ErrorReportValve" showReport="false" showServerInfo="false" />
</Host>
I'm trying to convert this configuration in a spring configuration class with the following code:
@Configuration
public class TomcatConfiguration {
@Bean
public ConfigurableServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addContextCustomizers(TomcatConfiguration::customize);
factory.addEngineValves(new SingleSignOn());
factory.addEngineValves(new ErrorReportValve());
factory.addContextValves(new AuthServletValve());
return factory;
}
private static void customize(Context context) {
context.setRealm(new AuthServletRealm());
context.addConstraint(createSecurityConstraint());
}
private static SecurityConstraint createSecurityConstraint() {
SecurityConstraint securityConstraint = new SecurityConstraint();
SecurityCollection securityCollection = new SecurityCollection();
securityCollection.addPattern("/*");
securityConstraint.addCollection(securityCollection);
return securityConstraint;
}
}
Valves are invoked correctly, but my AuthServletValve is not invoked.
I expect that for every invocation of my Spring Boot API, AuthServletValve is invoked to get the principal. But nothing
专注分享java语言的经验与见解,让所有开发者获益!
评论