use of org.olat.basesecurity.manager.GroupDAO in project OpenOLAT by OpenOLAT.
the class AuthHelper method doInvitationLogin.
public static int doInvitationLogin(String invitationToken, UserRequest ureq, Locale locale) {
InvitationDAO invitationDao = CoreSpringFactory.getImpl(InvitationDAO.class);
boolean hasPolicies = invitationDao.hasInvitations(invitationToken, new Date());
if (!hasPolicies) {
return LOGIN_DENIED;
}
UserManager um = UserManager.getInstance();
BaseSecurity securityManager = BaseSecurityManager.getInstance();
GroupDAO groupDao = CoreSpringFactory.getImpl(GroupDAO.class);
Invitation invitation = invitationDao.findInvitation(invitationToken);
if (invitation == null) {
return LOGIN_DENIED;
}
// check if identity exists
Identity identity = um.findUniqueIdentityByEmail(invitation.getMail());
if (identity != null) {
SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
if (securityManager.isIdentityInSecurityGroup(identity, allUsers)) {
// already a normal olat user, cannot be invited
return LOGIN_DENIED;
} else {
// fxdiff FXOLAT-151: add eventually the identity to the security group
if (!groupDao.hasRole(invitation.getBaseGroup(), identity, GroupRoles.invitee.name())) {
groupDao.addMembershipTwoWay(invitation.getBaseGroup(), identity, GroupRoles.invitee.name());
DBFactory.getInstance().commit();
}
int result = doLogin(identity, BaseSecurityModule.getDefaultAuthProviderIdentifier(), ureq);
// fxdiff FXOLAT-151: double check: problem with the DB, invitee is not marked has such
if (ureq.getUserSession().getRoles().isInvitee()) {
return result;
}
return LOGIN_DENIED;
}
}
Collection<String> supportedLanguages = CoreSpringFactory.getImpl(I18nModule.class).getEnabledLanguageKeys();
if (locale == null || !supportedLanguages.contains(locale.toString())) {
locale = I18nModule.getDefaultLocale();
}
// invitation ok -> create a temporary user
Identity invitee = invitationDao.createIdentityFrom(invitation, locale);
return doLogin(invitee, BaseSecurityModule.getDefaultAuthProviderIdentifier(), ureq);
}
use of org.olat.basesecurity.manager.GroupDAO in project openolat by klemens.
the class AuthHelper method doInvitationLogin.
public static int doInvitationLogin(String invitationToken, UserRequest ureq, Locale locale) {
InvitationDAO invitationDao = CoreSpringFactory.getImpl(InvitationDAO.class);
boolean hasPolicies = invitationDao.hasInvitations(invitationToken, new Date());
if (!hasPolicies) {
return LOGIN_DENIED;
}
UserManager um = UserManager.getInstance();
BaseSecurity securityManager = BaseSecurityManager.getInstance();
GroupDAO groupDao = CoreSpringFactory.getImpl(GroupDAO.class);
Invitation invitation = invitationDao.findInvitation(invitationToken);
if (invitation == null) {
return LOGIN_DENIED;
}
// check if identity exists
Identity identity = um.findUniqueIdentityByEmail(invitation.getMail());
if (identity != null) {
SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
if (securityManager.isIdentityInSecurityGroup(identity, allUsers)) {
// already a normal olat user, cannot be invited
return LOGIN_DENIED;
} else {
// fxdiff FXOLAT-151: add eventually the identity to the security group
if (!groupDao.hasRole(invitation.getBaseGroup(), identity, GroupRoles.invitee.name())) {
groupDao.addMembershipTwoWay(invitation.getBaseGroup(), identity, GroupRoles.invitee.name());
DBFactory.getInstance().commit();
}
int result = doLogin(identity, BaseSecurityModule.getDefaultAuthProviderIdentifier(), ureq);
// fxdiff FXOLAT-151: double check: problem with the DB, invitee is not marked has such
if (ureq.getUserSession().getRoles().isInvitee()) {
return result;
}
return LOGIN_DENIED;
}
}
Collection<String> supportedLanguages = CoreSpringFactory.getImpl(I18nModule.class).getEnabledLanguageKeys();
if (locale == null || !supportedLanguages.contains(locale.toString())) {
locale = I18nModule.getDefaultLocale();
}
// invitation ok -> create a temporary user
Identity invitee = invitationDao.createIdentityFrom(invitation, locale);
return doLogin(invitee, BaseSecurityModule.getDefaultAuthProviderIdentifier(), ureq);
}
Aggregations