1
我正在開發我的第一個Jsf,Jaas,JPA,JBoss應用程序,現在我遇到了這個問題。我創建了JBoss的兩個安全域:isUserInRole有時會返回false
<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);
}
}
}
MySimplePrincipal
public class SamplePrincipal implements Principal {
private String name;
public SamplePrincipal() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
我的方法中添加一個角色,主要因爲提交否則isUserInRole
返回false
。
我怎樣才能做到這一點?