gpt4 book ai didi

wildfly - 如何在 WildFly 中设置应用程序级 SAM

转载 作者:行者123 更新时间:2023-12-01 03:39:36 27 4
gpt4 key购买 nike

我之前在 Glassfish 上有过一些代码,但我想将它移植到 WildFly。

但是,我似乎无法让 WildFly 调用该模块。 ServletContextListener初始化模块如下

AuthConfigFactory.getFactory()            .registerConfigProvider(new OpenIdConnectModuleConfigProvider(options, null),             "HttpServlet", getAppContext(sce), null);

"HttpServlet" is not Glassfish specific and appears to be referenced in https://github.com/wildfly/wildfly/blob/master/undertow/src/main/java/org/wildfly/extension/undertow/security/jaspi/JASPIAuthenticationMechanism.java?source=cc

Glassfish does not require a <logon-config> block on the web.xml and putting any variant in WildFly does not work (as expected)

The other place I am suspecting is how I calculate the application context identifier. For Glassfish I had

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这个 block
<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 这是一个标准标识符,表示将在 Java EE 中的哪个子系统上注册 auth 模块。但是只有另一个有效值,那就是其中带有“肥皂”的东西(不确定)。

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 followingWEB-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 上验证了它们,它在那里工作。 validateRequest正确调用了测试 SAM 的方法。

关于wildfly - 如何在 WildFly 中设置应用程序级 SAM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31799608/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com