I am using EJBs (on JBoss) and Wicket as the UI layer. I added security to my EJB, my security.conf looks like this:
<application-policy name="my-security-domain">
<authentication>
<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required">
<module-option name="usersProperties">META-INF/users.properties</module-option>
<module-option name="rolesProperties">META-INF/roles.properties</module-option>
</login-module>
</authentication>
</application-policy>
In the UI layer, I use PicketBox to authenticate as instructed in the PicketBox Authentication page: http://community.jboss.org/wiki/PicketBoxAuthentication#PicketBox_Authentication_in_a_JBoss_Application_Server_5_environment
My Wicket AuthenticatedWebSession sub-class looks like this:
private Subject subject;
private SecurityContext securityContext;
@Override
public boolean authenticate(String username,
String password)
{
boolean authenticated = false;
securityContext = null;
SecurityFactory.prepare();
try
{
String securityDomainName = "my-security-domain";
String configFile = "META-INF/security.conf";
PicketBoxConfiguration idtrustConfig = new PicketBoxConfiguration();
idtrustConfig.load(configFile);
//Note: This is the most important line where you establish a security context
securityContext = SecurityFactory.establishSecurityContext(securityDomainName);
AuthenticationManager am = securityContext.getAuthenticationManager();
subject = new Subject();
Principal principal = new SimplePrincipal(username);
Object credential = new String(password);
authenticated = am.isValid(principal, credential, subject);
securityContext.getUtil().createSubjectInfo(principal, credential, subject);
//You may make call outs to other components here*/
//DEBUG
for(Principal p : subject.getPrincipals())
{
LOGGER.debug("Principal: " + p.getName());
if(p instanceof Group)
{
Group g = (Group) p;
Enumeration<? extends Principal> members = g.members();
while(members.hasMoreElements())
{
Principal member = members.nextElement();
LOGGER.debug("Group name: " + member.getName());
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return authenticated;
}
So far so good, I can authenticated with the server from the UI. However, any subsequent calls to the secure EJBs from else where in the UI layer will fail with “Invalid User” although I have already authenticated.
I have tested the authentication in a standalone client and it works fine, I can invoke a secure EJB afterwards.
I have also tried the authentication outlined by this post, and the UI still cannot invoke secure EJBs: http://iocanel.blogspot.com/2010/09/karafs-jaas-modules-in-action.html
Any help would be greatly appreciated.
Kind regards,
Linh
A colleague of mnie suggested me to look at the security configuration at the web tier. I solved it with the following configuration:
jboss-web.xml:
web.xml:
Thank you all.
Linh