Search in sources :

Example 96 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class RepositoryMailing method sendEmail.

public static void sendEmail(Identity ureqIdentity, Identity identity, RepositoryEntry re, Type type, MailPackage mailing) {
    if (mailing != null && !mailing.isSendEmail()) {
        return;
    }
    String email = identity.getUser().getProperty(UserConstants.EMAIL, null);
    String emailAlt = identity.getUser().getProperty(UserConstants.INSTITUTIONALEMAIL, null);
    if (!StringHelper.containsNonWhitespace(email) && !StringHelper.containsNonWhitespace(emailAlt)) {
        return;
    }
    if (mailing == null) {
        BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
        RepositoryModule repositoryModule = CoreSpringFactory.getImpl(RepositoryModule.class);
        Roles ureqRoles = securityManager.getRoles(ureqIdentity);
        if (!repositoryModule.isMandatoryEnrolmentEmail(ureqRoles)) {
            return;
        }
    }
    MailTemplate template = mailing == null ? null : mailing.getTemplate();
    if (mailing == null || mailing.getTemplate() == null) {
        template = getDefaultTemplate(type, re, ureqIdentity);
    }
    MailContext context = mailing == null ? null : mailing.getContext();
    if (context == null) {
        context = new MailContextImpl(null, null, "[RepositoryEntry:" + re.getKey() + "]");
    }
    String metaId = mailing == null ? null : mailing.getUuid();
    MailerResult result = new MailerResult();
    MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
    MailBundle bundle = mailManager.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
    if (bundle != null) {
        mailManager.sendMessage(bundle);
    }
    if (mailing != null) {
        mailing.appendResult(result);
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) MailTemplate(org.olat.core.util.mail.MailTemplate) MailManager(org.olat.core.util.mail.MailManager) Roles(org.olat.core.id.Roles) MailBundle(org.olat.core.util.mail.MailBundle) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 97 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class FeedMediaDispatcher method validAuthentication.

/**
 * Authenticates the identity by token
 *
 * @param identity
 * @param token
 * @return True if authentication is valid
 */
private boolean validAuthentication(Identity identity, String token) {
    boolean valid = false;
    BaseSecurity secMgr = BaseSecurityManager.getInstance();
    Authentication authentication = secMgr.findAuthenticationByAuthusername(identity.getKey().toString(), TOKEN_PROVIDER);
    if (authentication != null && authentication.getCredential().equals(token)) {
        valid = true;
    }
    return valid;
}
Also used : Authentication(org.olat.basesecurity.Authentication) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 98 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class ShibbolethRegistrationController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == migrationForm) {
        if (event == Event.CANCELLED_EVENT) {
            mainContainer.setPage(VELOCITY_ROOT + "/register.html");
        } else if (event == Event.DONE_EVENT) {
            state = STATE_MIGRATED_SHIB_USER;
            mainContainer.setPage(VELOCITY_ROOT + "/disclaimer.html");
        }
    } else if (source == regWithUserPropForm) {
        if (event == Event.CANCELLED_EVENT) {
            mainContainer.setPage(VELOCITY_ROOT + "/register.html");
        } else if (event == Event.DONE_EVENT) {
            state = STATE_NEW_SHIB_USER;
            mainContainer.setPage(VELOCITY_ROOT + "/disclaimer.html");
        }
    } else if (source == regForm) {
        if (event == Event.DONE_EVENT) {
            String choosenLogin = regForm.getLogin();
            BaseSecurity secMgr = BaseSecurityManager.getInstance();
            Identity identity = secMgr.findIdentityByName(choosenLogin);
            if (identity == null) {
                // ok, create new user
                if (isMandatoryUserPropertyMissing()) {
                    regWithUserPropForm = new ShibbolethRegistrationUserPropertiesFrom(ureq, getWindowControl(), shibbolethAttributes);
                    regWithUserPropForm.addControllerListener(this);
                    mainContainer.put("getUserPropsForm", regWithUserPropForm.getInitialComponent());
                    mainContainer.setPage(VELOCITY_ROOT + "/register_user_props.html");
                } else {
                    state = STATE_NEW_SHIB_USER;
                    mainContainer.setPage(VELOCITY_ROOT + "/disclaimer.html");
                }
            } else {
                // offer identity migration, if OLAT provider exists
                Authentication auth = secMgr.findAuthentication(identity, BaseSecurityModule.getDefaultAuthProviderIdentifier());
                if (auth == null) {
                    // no OLAT provider, migration not possible...
                    getWindowControl().setError(translator.translate("sr.error.loginexists", new String[] { WebappHelper.getMailConfig("mailSupport") }));
                } else {
                    // OLAT provider exists, offer migration...
                    migrationForm = new ShibbolethMigrationForm(ureq, getWindowControl(), auth);
                    migrationForm.addControllerListener(this);
                    mainContainer.put("migrationForm", migrationForm.getInitialComponent());
                    mainContainer.setPage(VELOCITY_ROOT + "/migration.html");
                }
            }
        }
    } else if (source == languageChooserController) {
        if (event == Event.DONE_EVENT) {
            // language choosed
            mainContainer.setPage(VELOCITY_ROOT + "/register.html");
            ureq.getUserSession().removeEntry(LocaleNegotiator.NEGOTIATED_LOCALE);
        } else if (event instanceof LanguageChangedEvent) {
            LanguageChangedEvent lcev = (LanguageChangedEvent) event;
            translator.setLocale(lcev.getNewLocale());
            dclController.changeLocale(lcev.getNewLocale());
        }
    } else if (source == dclController) {
        if (event == Event.DONE_EVENT) {
            // disclaimer accepted...
            if (state == STATE_NEW_SHIB_USER) {
                // ...proceed and create user
                String choosenLogin;
                if (regForm == null) {
                    choosenLogin = proposedUsername;
                } else {
                    choosenLogin = regForm.getLogin();
                }
                // check if login has been taken by another user in the meantime...
                BaseSecurity secMgr = BaseSecurityManager.getInstance();
                // check if login has been taken by another user in the meantime...
                Identity identity = secMgr.findIdentityByName(choosenLogin);
                if (identity != null) {
                    getWindowControl().setError(translator.translate("sr.login.meantimetaken"));
                    mainContainer.setPage(VELOCITY_ROOT + "/register.html");
                    state = STATE_UNDEFINED;
                    return;
                }
                String email = shibbolethAttributes.getValueForUserPropertyName(UserConstants.EMAIL);
                if (!UserManager.getInstance().isEmailAllowed(email)) {
                    // error, email already exists. should actually not happen if OLAT Authenticator has
                    // been set after removing shibboleth authenticator
                    getWindowControl().setError(translator.translate("sr.error.emailexists", new String[] { WebappHelper.getMailConfig("mailSupport") }));
                    mainContainer.setPage(VELOCITY_ROOT + "/register.html");
                    state = STATE_UNDEFINED;
                    return;
                }
                identity = shibbolethManager.createUser(choosenLogin, shibbolethUniqueID, locale.getLanguage(), shibbolethAttributes);
                // tell system that this user did accept the disclaimer
                CoreSpringFactory.getImpl(RegistrationManager.class).setHasConfirmedDislaimer(identity);
                doLogin(identity, ureq);
                return;
            } else if (state == STATE_MIGRATED_SHIB_USER) {
                // ...proceed and migrate user
                // create additional authentication
                Authentication auth = migrationForm.getAuthentication();
                Identity authenticationedIdentity = auth.getIdentity();
                BaseSecurity secMgr = BaseSecurityManager.getInstance();
                secMgr.createAndPersistAuthentication(authenticationedIdentity, ShibbolethDispatcher.PROVIDER_SHIB, shibbolethUniqueID, null, null);
                // update user profile
                shibbolethManager.syncUser(authenticationedIdentity, shibbolethAttributes);
                doLogin(authenticationedIdentity, ureq);
                return;
            }
        } else if (event == Event.CANCELLED_EVENT) {
            mainContainer.setPage(VELOCITY_ROOT + "/register.html");
            getWindowControl().setError(translator.translate("sr.error.disclaimer"));
        }
    }
}
Also used : RegistrationManager(org.olat.registration.RegistrationManager) Authentication(org.olat.basesecurity.Authentication) LanguageChangedEvent(org.olat.core.commons.chiefcontrollers.LanguageChangedEvent) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 99 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class JunitTestHelper method createAndPersistIdentityAsAuthor.

/**
 * Create an identity with author permissions
 * @param login
 * @return
 */
public static final Identity createAndPersistIdentityAsAuthor(String login) {
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    Identity identity = securityManager.findIdentityByName(login);
    if (identity != null)
        return identity;
    SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    if (group == null)
        group = securityManager.createAndPersistNamedSecurityGroup(Constants.GROUP_AUTHORS);
    User user = UserManager.getInstance().createUser("first" + login, "last" + login, login + "@" + maildomain);
    identity = securityManager.createAndPersistIdentityAndUser(login, null, user, BaseSecurityModule.getDefaultAuthProviderIdentifier(), login, PWD);
    securityManager.addIdentityToSecurityGroup(identity, group);
    return identity;
}
Also used : User(org.olat.core.id.User) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 100 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class JunitTestHelper method createAndPersistIdentityAsAdmin.

/**
 * Create an identity with admin permissions
 * @param login
 * @return
 */
public static final Identity createAndPersistIdentityAsAdmin(String login) {
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    Identity identity = securityManager.findIdentityByName(login);
    if (identity != null)
        return identity;
    SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
    if (group == null)
        group = securityManager.createAndPersistNamedSecurityGroup(Constants.GROUP_ADMIN);
    User user = UserManager.getInstance().createUser("first" + login, "last" + login, login + "@" + maildomain);
    identity = securityManager.createAndPersistIdentityAndUser(login, null, user, BaseSecurityModule.getDefaultAuthProviderIdentifier(), login, PWD);
    securityManager.addIdentityToSecurityGroup(identity, group);
    return identity;
}
Also used : User(org.olat.core.id.User) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Aggregations

BaseSecurity (org.olat.basesecurity.BaseSecurity)116 Identity (org.olat.core.id.Identity)88 Path (javax.ws.rs.Path)48 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)28 PUT (javax.ws.rs.PUT)24 Produces (javax.ws.rs.Produces)22 SecurityGroup (org.olat.basesecurity.SecurityGroup)20 RepositoryEntry (org.olat.repository.RepositoryEntry)20 DELETE (javax.ws.rs.DELETE)14 Authentication (org.olat.basesecurity.Authentication)14 MailPackage (org.olat.core.util.mail.MailPackage)14 RepositoryManager (org.olat.repository.RepositoryManager)14 Consumes (javax.ws.rs.Consumes)12 WebApplicationException (javax.ws.rs.WebApplicationException)12 CertificatesManager (org.olat.course.certificate.CertificatesManager)10 OLATResource (org.olat.resource.OLATResource)10 OLATResourceManager (org.olat.resource.OLATResourceManager)10 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)8