私は最初の Jsf、Jaas、JPA、JBoss アプリケーションを開発していますが、この問題が発生しています。JBoss で 2 つのセキュリティ ドメインを作成しました。
<security-domain name="Database" cache-type="default">
<authentication>
<login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" 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=?"/>
</login-module>
</authentication>
</security-domain>
<security-domain name="Custom" cache-type="default">
<authentication>
<login-module code="demo.SampleLoginModule" flag="required"/>
</authentication>
</security-domain>
「データベース」ドメインを使用するとすべてが機能しますが、「カスタム」ドメインを使用するとロールをプリンシパルに設定できません。
私の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
userPrincipal.setName("username");
if (!(subject.getPrincipals().contains(userPrincipal)))
subject.getPrincipals().add(userPrincipal);
}
}
}
MySimpleプリンシパル
public class SamplePrincipal implements Principal {
private String name;
public SamplePrincipal() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
メソッド commit 内のプリンシパルにロールを追加しisUserInRole
ますfalse
。
これどうやってするの?