Search in sources :

Example 6 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.

the class AdvancedPropertySearchForm method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    int c = 0;
    if (userName.getValue().length() > 0) {
        c++;
        BaseSecurity secMgr = BaseSecurityManager.getInstance();
        identity = secMgr.findIdentityByName(userName.getValue());
        if (identity == null) {
            userName.setErrorKey("error.search.form.nousername", null);
            return false;
        }
    }
    if (resourceTypeName.getSelected() > 0)
        c++;
    if (resourceTypeId.getValue().length() > 0)
        c++;
    if (category.getValue().length() > 0)
        c++;
    if (propertyName.getValue().length() > 0)
        c++;
    if (c == 0) {
        showInfo("error.search.form.notempty");
        return false;
    }
    return true;
}
Also used : BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 7 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.

the class QuotaManagerImpl method hasQuotaEditRights.

@Override
public boolean hasQuotaEditRights(Identity identity) {
    BaseSecurity mgr = BaseSecurityManager.getInstance();
    boolean hasQuoaRights = mgr.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_ACCESS, OresHelper.lookupType(GenericQuotaEditController.class));
    return hasQuoaRights;
}
Also used : BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 8 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.

the class UserBulkChangePasswordController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (event == Event.DONE_EVENT) {
        String[] usernames = changePasswordForm.getUsernames();
        String password = changePasswordForm.getPassword();
        boolean autodisc = changePasswordForm.getDisclaimerAccept();
        boolean langGerman = changePasswordForm.getLangGerman();
        BaseSecurity identityManager = BaseSecurityManager.getInstance();
        int c = 0;
        for (String username : usernames) {
            if (username.length() == 0)
                continue;
            try {
                Identity identity = identityManager.findIdentityByName(username);
                if (identity != null) {
                    if (password != null && password.trim().length() > 0) {
                        olatAuthenticationSpi.changePassword(ureq.getIdentity(), identity, password);
                        log.info("changePassword for username: " + username);
                    }
                    if (autodisc) {
                        registrationManager.setHasConfirmedDislaimer(identity);
                        log.info("Disclaimer accepted for username: " + username);
                    }
                    if (langGerman) {
                        identity.getUser().getPreferences().setLanguage("de");
                        UserManager.getInstance().updateUserFromIdentity(identity);
                        log.info("Set language German for username: " + username);
                    }
                    c++;
                } else {
                    log.warn("could find user with username: " + username);
                }
            } catch (Exception e) {
                log.error("Failed to change password/settings for username: " + username, e);
            }
        }
        // notify done
        getWindowControl().setInfo(translate("bulk.psw.done", "" + c));
    // TODO: clear the form
    // changePasswordForm.clearForm(); //???
    }
}
Also used : Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 9 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.

the class InfoMessagesWebService method createEmptyCourse.

/**
 * Creates a new info message
 * @response.representation.200.qname {http://www.example.com}infoMessageVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The info message
 * @response.representation.200.example {@link org.olat.commons.info.restapi.Examples#SAMPLE_INFOMESSAGEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param resName The OLAT Resourceable name
 * @param resId The OLAT Resourceable id
 * @param resSubPath The resource sub path (optional)
 * @param businessPath The business path
 * @param authorKey The identity key of the author
 * @param title The title
 * @param message The message
 * @param request The HTTP request
 * @return It returns the id of the newly info message
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createEmptyCourse(@QueryParam("resName") final String resName, @QueryParam("resId") final Long resId, @QueryParam("resSubPath") String resSubPath, @QueryParam("businessPath") String businessPath, @QueryParam("authorKey") Long authorKey, @QueryParam("title") String title, @QueryParam("message") String message, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    OLATResourceable ores = new OLATResourceable() {

        @Override
        public String getResourceableTypeName() {
            return resName;
        }

        @Override
        public Long getResourceableId() {
            return resId;
        }
    };
    Identity author;
    UserRequest ureq = getUserRequest(request);
    if (authorKey == null) {
        author = ureq.getIdentity();
    } else {
        BaseSecurity securityManager = BaseSecurityManager.getInstance();
        author = securityManager.loadIdentityByKey(authorKey, false);
        if (author == null) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    }
    InfoMessageFrontendManager messageManager = CoreSpringFactory.getImpl(InfoMessageFrontendManager.class);
    InfoMessage msg = messageManager.createInfoMessage(ores, resSubPath, businessPath, author);
    msg.setTitle(title);
    msg.setMessage(message);
    messageManager.sendInfoMessage(msg, null, ureq.getLocale(), ureq.getIdentity(), Collections.<Identity>emptyList());
    InfoMessageVO infoVO = new InfoMessageVO(msg);
    return Response.ok(infoVO).build();
}
Also used : InfoMessageFrontendManager(org.olat.commons.info.InfoMessageFrontendManager) OLATResourceable(org.olat.core.id.OLATResourceable) InfoMessage(org.olat.commons.info.InfoMessage) Identity(org.olat.core.id.Identity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) BaseSecurity(org.olat.basesecurity.BaseSecurity) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 10 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.

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)

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