我以前有一些代码在Glassfish上工作,但我想把它移植到WildFly.
但是,我似乎无法让WildFly调用该模块. ServletContextListener按如下方式初始化模块
AuthConfigFactory.getFactory() .registerConfigProvider(new OpenIdConnectModuleConfigProvider(options, null), "HttpServlet", getAppContext(sce), null);
“HttpServlet”不是Glassfish特有的,似乎在https://github.com/wildfly/wildfly/blob/master/undertow/src/main/java/org/wildfly/extension/undertow/security/jaspi/JASPIAuthenticationMechanism.java?source=cc中被引用
Glassfish不需要< logon-config>阻止在web.xml上并将任何变量放在WildFly中不起作用(如预期的那样)
我怀疑的另一个地方是我如何计算应用程序上下文标识符.对于Glassfish,我有
private String getAppContext(final ServletContextEvent sce) {
return sce.getServletContext()
.getVirtualServerName() + " "
+ sce.getServletContext()
.getContextPath();
}
WildFly会有所不同吗?虽然我在https://github.com/rdebusscher/secSpikeWeb/blob/master/src/main/java/org/omnifaces/security/jaspic/core/Jaspic.java#L300也看到过类似的代码
我也尝试过添加到standalone.xml这个块
<security-domain name="jaspi" cache-type="default">
<authentication-jaspi>
<login-module-stack name="dummy">
<login-module code="Dummy" flag="optional"/>
</login-module-stack>
<auth-module code="org.wildfly.extension.undertow.security.jaspi.modules.HTTPSchemeServerAuthModule" flag="required"/>
</authentication-jaspi>
</security-domain>
并设置< default-security-domain value =“jaspi”/>
然而它没有任何效果,并且在模块中放置一个断点并没有显示它也被击中.
另外,在WildFly中我找不到一种方法来执行以下操作,就像我在glassfish-web.xml中那样,但这可能是另一个问题
<security-role-mapping>
<role-name>users</role-name>
<group-name>https://helloworld</group-name>
</security-role-mapping>
代码非常大,但可以找到它的要点
https://github.com/trajano/openid-connect/tree/openid-connect-1.0.1/openid-connect-jaspic-module
和
https://github.com/trajano/openid-connect/tree/openid-connect-1.0.1/openid-connect-jaspic-sample
注意我在应用程序级别上查找它,而不是设置全局服务器JASPI.
最佳答案
“HttpServlet” is not Glassfish specific
这是正确的,AFAIK这是一个标准标识符,可以说明autem模块将在Java EE中注册哪个子系统.但是只有一个其他有效值,而且其中有“肥皂”(不确定).
Could it be different in WildFly?
不,这是一个standard way.
And set
<default-security-domain value="jaspi"/>
recommended方式应该是standalone.xml中的方法:
<security-domain name="jaspitest" cache-type="default">
<authentication-jaspi>
<login-module-stack name="dummy">
<login-module code="Dummy" flag="optional"/>
</login-module-stack>
<auth-module code="Dummy"/>
</authentication-jaspi>
</security-domain>
然后将the following放入WEB-INF / jboss-web.xml:
<jboss-web>
<security-domain>jaspitest</security-domain>
</jboss-web>
这应该足够了.这是我在WildFly 8.2和9.0上使用的,它是Java EE示例项目使用的内容.但是设置默认域也应该像你一样工作,并且你的激活码也足够接近,所以我不确定上面的内容是否会对你的情况产生影响.
或者,有一种JBoss specific programmatic激活JASPIC的方法:
String securityDomain = "other";
IdentityManager identityManager = deploymentInfo.getIdentityManager();
if (identityManager instanceof JAASIdentityManagerImpl) {
try {
Field securityDomainContextField =
JAASIdentityManagerImpl.class.getDeclaredField("securityDomainContext");
securityDomainContextField.setAccessible(true);
SecurityDomainContext securityDomainContext =
(SecurityDomainContext)
securityDomainContextField.get(identityManager);
securityDomain =
securityDomainContext.getAuthenticationManager().getSecurityDomain();
} catch (NoSuchFieldException | SecurityException |
IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
ApplicationPolicy applicationPolicy = new
ApplicationPolicy(securityDomain);
JASPIAuthenticationInfo authenticationInfo = new
JASPIAuthenticationInfo(securityDomain);
applicationPolicy.setAuthenticationInfo(authenticationInfo);
SecurityConfiguration.addApplicationPolicy(applicationPolicy);
deploymentInfo.setJaspiAuthenticationMechanism(new
JASPIAuthenticationMechanism(securityDomain, null));
deploymentInfo.setSecurityContextFactory(new
JASPICSecurityContextFactory(securityDomain));
您需要从io.undertow.servlet.ServletExtension执行该操作
令人遗憾的是,JBoss需要激活JASPIC.但是上面显示的方法之一应该真的有效.我刚刚在WildFly 9.0的股票上验证了它们并在那里工作.正确调用测试SAM的validateRequest方法.