我已经为在Wildfly 8.0中运行的web应用程序创建了一个自定义登录模块。下面是模块:
package bmacs.auth;
import java.security.acl.Group;
import javax.security.auth.login.LoginException;
import org.jboss.security.SimpleGroup;
import org.jboss.security.SimplePrincipal;
import org.jboss.security.auth.spi.UsernamePasswordLoginModule;
public class BasicLoginModule extends UsernamePasswordLoginModule
{
@Override
protected String getUsersPassword() throws LoginException
{
System.out.println("custom getUsersPassword");
System.out.format("MyLoginModule: authenticating user '%s'\n",
getUsername());
String password = super.getUsername();
password = password.toUpperCase();
return password;
}
@Override
protected boolean validatePassword(String inputPassword,
String expectedPassword)
{
System.out.println("custom validatePassword");
String encryptedInputPassword = (inputPassword == null) ? null
: inputPassword.toUpperCase();
System.out.format(
"Validating that (encrypted) input psw '%s' equals to (encrypted) '%s'\n"
, encryptedInputPassword, expectedPassword);
return true;
}
@Override
protected Group[] getRoleSets() throws LoginException
{
System.out.println("custom getRoleSets");
SimpleGroup group = new SimpleGroup("Roles");
try {
System.out.println("Search here group for user: "+super.getUsername());
group.addMember(new SimplePrincipal("RoleReportEnrollmentViewer"));
} catch (Exception e) {
throw new LoginException("Failed to create group member for " + group);
}
return new Group[] { group };
}
}这是我添加到standalone.xml的新安全域
<security-domain name="simple-auth" cache-type="default">
<authentication>
<login-module code="bmacs.auth.BasicLoginModule" flag="required" module="login"/>
</authentication>
</security-domain>这是我的web应用程序的jboss-web.xml,它引用了安全域。
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain flushOnSessionInvalidation="true">simple-auth</security-domain>
</jboss-web>当我尝试登录(通过表单身份验证J_SECURITY_CHECK)时,它什么也不做。日志中唯一显示的就是这两行代码,这并没有多大帮助
16:55:09,622 TRACE [org.jboss.security] (default task-9) PBOX000200: Begin isValid, principal: org.wildfly.extension.undertow.security.AccountImpl$AccountPrincipal@c9c352bc, cache entry: null
16:55:09,625 TRACE [org.jboss.security] (default task-9) PBOX000354: Setting security roles ThreadLocal: null我遗漏了什么?自定义登录中的System.out.println语句从不打印任何/未执行的内容。
发布于 2015-06-18 16:01:17
再次检查jboss-web.xml。我认为您必须在xml中设置安全角色。我给你一个可能有帮助的url
https://stackoverflow.com/questions/29726261/form-based-authentication-in-wildfly-with-jsf
如果它对你有效,请告诉我。
致以问候。
发布于 2015-07-06 23:39:36
最近我也遇到了类似的问题。看看这个由我创建的WildFly bug,您可以在其中找到解决方法:WFLY-4761。阅读链接后,如果您需要更多帮助,请与我联系。
编辑:作为对Newd评论的回应,我添加了更多的描述。WildFly 8.2.0中存在一个缺陷,在该缺陷中,登录模块中未经检查的异常会被接受。解决方法是通过修改类org.jboss.security.authentication.JBossCachedAuthenticationManager修补picketbox-Infinispan4.0.21.Final.jar,其中defaultLogin方法实现的第二部分中的运行时错误被LoginException捕获并重新抛出。最初的问题与Infinispan8.0有关,您必须使用旧版本的WildFly -infinispan4.0.20.Final.jar执行相同的操作。请注意,这个问题也可能是由模块依赖项未满足引起的(WildFly模块必须显式声明其依赖项)。
一旦修补了库,模块中的错误就会开始出现在WildFly日志文件中。
发布于 2016-05-18 16:50:45
您必须使用新的身份验证机制:
您必须创建一个实现wildfly接口的新类,并在web.xml登录配置中使用您的新配置...您还可以从wildfly : FormAuthenticationMecanism中签入导入的源代码类form wildfly 9,但在wildfly 8中是相同的
https://stackoverflow.com/questions/30902301
复制相似问题