This discussion is archived
0 Replies Latest reply: Feb 17, 2013 4:19 AM by 966664 RSS

isUserInRole sometimes returns false

966664 Newbie
Currently Being Moderated
I'm developing my first Jsf, Jaas, JPA, JBoss application and now I have this trouble. I created two security domains in JBoss:

<security-domain name="Database" cache-type="default">
<login-module code="" flag="required">
<module-option name="dsJndiName" value="java:jboss/JaasDS"/>
<module-option name="principalsQuery" value="select password from user where mail=?"/>
<module-option name="rolesQuery" value="select role, 'Roles' from user u where u.mail=?"/>
<security-domain name="Custom" cache-type="default">
<login-module code="demo.SampleLoginModule" flag="required"/>

If I use "Database" domain everything works, while if I use a "Custom" domain I can not set the role to the principal.

My SampleLoginModule

public class SampleLoginModule implements LoginModule {
private String username;
private String password;

private SamplePrincipal userPrincipal;

public boolean login() throws LoginException {
//Here i check the credentials

public boolean commit() throws LoginException {
//Here i add principal to subject


if (!(subject.getPrincipals().contains(userPrincipal)))


public class SamplePrincipal implements Principal {
private String name;

public SamplePrincipal() {

public String getName() {
return name;
public void setName(String name) { = name;

I would add a role to a principal within of the method commit because isUserInRole otherwise return false.

How can I do this?


  • Correct Answers - 10 points
  • Helpful Answers - 5 points