Errai Security を使用するユーザー用に、次の CustomAuthenticator があります。
public CustomAuthenticator extends BaseAuthenticator {
@Override
public void authenticate() {
String userId = loginCredentials.getUserId();
String password = loginCredentials.getPassword();
User user = userDAO.fetchUserByName(userId);
if (!BCrypt.checkpw(password, user.getPasswordHash())) {
setStatus(AuthenticationStatus.FAILURE);
} else {
// Add to IDM
IdentityQuery<UserImpl> query
= partitionManager.createIdentityManager().createIdentityQuery(UserImpl.class);
query.setParameter(UserImpl.LOGIN_NAME, user.getUsername());
List<UserImpl> result = query.getResultList();
org.picketlink.idm.model.basic.Role trial = new org.picketlink.idm.model.basic.Role("TRIAL");
if (result.isEmpty()){
UserImpl account = new UserImpl(user);
partitionManager.createIdentityManager().add(account);
partitionManager.createIdentityManager().updateCredential(account, new Password(password));
partitionManager.createIdentityManager().add(trial);
BasicModel.grantRole(partitionManager.createRelationshipManager(), account, trial);
IdentityQuery<UserImpl> q
= partitionManager.createIdentityManager().createIdentityQuery(UserImpl.class);
q.setParameter(UserImpl.LOGIN_NAME, user.getUsername());
UserImpl u = q.getResultList().iterator().next();
setStatus(AuthenticationStatus.SUCCESS);
setAccount(u);
} else {
setStatus(AuthenticationStatus.SUCCESS);
setAccount(result.iterator().next());
}
userEvent.fire(user);
}
}
設定する seAccount アカウントに問題がないことを確認しても、Picketlink 側のリストに Roles が保持されているかどうかはわかりません。呼び出しの応答:
Caller<AuthenticationService> authServiceCaller;
Null ではありませんが、Errai セキュリティ ユーザーが返されました。名前は「ANONYMOUS」、役割は「NOBODY」です。ここで何が起こっているのかわかりません。
アップデート:
このlogin(username, password)
メソッドは正しいユーザーとロールを返しますが、そうでgetUser()
はありません。これが問題です。