Search in sources :

Example 1 with GroupDAO

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);
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) InvitationDAO(org.olat.portfolio.manager.InvitationDAO) Date(java.util.Date) UserManager(org.olat.user.UserManager) GroupDAO(org.olat.basesecurity.manager.GroupDAO) Identity(org.olat.core.id.Identity)

Example 2 with GroupDAO

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);
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) InvitationDAO(org.olat.portfolio.manager.InvitationDAO) Date(java.util.Date) UserManager(org.olat.user.UserManager) GroupDAO(org.olat.basesecurity.manager.GroupDAO) Identity(org.olat.core.id.Identity)

Aggregations

Date (java.util.Date)2 GroupDAO (org.olat.basesecurity.manager.GroupDAO)2 Identity (org.olat.core.id.Identity)2 I18nModule (org.olat.core.util.i18n.I18nModule)2 InvitationDAO (org.olat.portfolio.manager.InvitationDAO)2 UserManager (org.olat.user.UserManager)2