Tracing.logWarn("Identity not found for username="+username, ClientManagerImpl.class);
return null;
}
// synchronized: not needed here, since the credentials are only created once for a user (when that user logs in for the very first time).
// And a user will almost! never log in at the very same time from two different machines.
Authentication auth = ManagerFactory.getManager().findAuthentication(identity, PROVIDER_INSTANT_MESSAGING);
InstantMessaging im = InstantMessagingModule.getAdapter();
if (auth == null) { // create new authentication for provider and also a new IM-account
//if account exists on IM server but not on OLAT delete it first
if (im.hasAccount(username)) {
im.deleteAccount(username);
}
String pw = RandomStringUtils.randomAlphanumeric(6);
if (im.createAccount(username, pw,
getFullname(identity), identity.getUser().getProperty(UserConstants.EMAIL, null))) {
auth = ManagerFactory.getManager().createAndPersistAuthentication(identity, PROVIDER_INSTANT_MESSAGING,
identity.getName().toLowerCase(), pw);
Tracing.logAudit("New instant messaging authentication account created for user:" + username, this.getClass());
return auth.getCredential();
} else {
Tracing.logWarn("new instant messaging account creation failed for user: " + username, ClientManagerImpl.class);
return null;
}
}
/**
* this does not decouple IM from the loginprocess, move account recreations in background thread somewhere else
* maybe to the login background thread...
*/
// else {
// //user has IM account credentials on OLAT, check whether account on IM server side exists
// if (!im.hasAccount(username)) {
// boolean success = im.createAccount(username, auth.getCredential(), getFullname(identity), identity.getUser().getProperty(UserConstants.EMAIL, null));
// if (success) {
// Tracing.logAudit("New instant messaging authentication account created for user:" + username, this.getClass());
// } else {
// Tracing.logWarn("new instant messaging account creation failed for user: " + username, ClientManagerImpl.class);
// }
// }
// }
return auth.getCredential();
}