【发布时间】:2016-02-20 20:33:00
【问题描述】:
基于这个Jaspic Example,我为ServerAuthModule编写了以下validateRequest方法:
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject,
Subject serviceSubject) throws AuthException {
boolean authenticated = false;
final HttpServletRequest request =
(HttpServletRequest) messageInfo.getRequestMessage();
final String token = request.getParameter("token");
TokenPrincipal principal = (TokenPrincipal) request.getUserPrincipal();
Callback[] callbacks = new Callback[] {
new CallerPrincipalCallback(clientSubject, (TokenPrincipal) null) };
if (principal != null) {
callbacks = new Callback[] {
new CallerPrincipalCallback(clientSubject, principal) };
authenticated = true;
} else {
if (token != null && token.length() == Constants.tokenLength) {
try {
principal = fetchUser(token);
} catch (final Exception e) {
throw (AuthException) new AuthException().initCause(e);
}
callbacks = new Callback[]
{
new CallerPrincipalCallback(clientSubject, principal),
new GroupPrincipalCallback(clientSubject,
new String[] { "aRole" })
};
messageInfo.getMap().put("javax.servlet.http.registerSession", "TRUE");
authenticated = true;
}
}
if (authenticated) {
try {
handler.handle(callbacks);
} catch (final Exception e) {
throw (AuthException) new AuthException().initCause(e);
}
return SUCCESS;
}
return AuthStatus.SEND_FAILURE;
}
这按预期工作,对于带有@RolesAllowed("aRole") 的 ejb 的第一次调用,但对于下一次调用,这根本不起作用。 Wildfly 通过以下错误消息否认它:
ERROR [org.jboss.as.ejb3.invocation] (default task-4) WFLYEJB0034: EJB Invocation
failed on component TestEJB for method public java.lang.String
com.jaspic.security.TestEJB.getPrincipalName():
javax.ejb.EJBAccessException: WFLYSEC0027: Invalid User
如果我猜对了,错误发生在:
org.jboss.as.security.service.SimpleSecurityManagerline 367 的wilfly 的源代码,由于line 405,其中credential 被选中,但似乎是null。
这在 Wildfly 8/9/10CR 中似乎是相同的(其他版本未测试)。
再次,我不确定,如果我做错了,或者这是同一个错误 https://issues.jboss.org/browse/WFLY-4626 ?这是一个错误,还是预期的行为?
【问题讨论】:
标签: java session ejb wildfly jaspic