Search in sources :

Example 11 with BaseSecurity

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

the class IdentityIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    int counter = 0;
    BaseSecurity secMgr = BaseSecurityManager.getInstance();
    List<Long> identityKeys = secMgr.loadVisibleIdentityKeys();
    if (isLogDebugEnabled())
        logDebug("Found " + identityKeys.size() + " active identities to index");
    DBFactory.getInstance().commitAndCloseSession();
    for (Long identityKey : identityKeys) {
        try {
            // reload the identity here before indexing it to make sure it has not been deleted in the meantime
            Identity identity = secMgr.loadIdentityByKey(identityKey);
            if (identity == null || (identity.getStatus() >= Identity.STATUS_VISIBLE_LIMIT)) {
                logInfo("doIndex: identity was deleted while we were indexing. The deleted identity was: " + identity);
                continue;
            }
            if (isLogDebugEnabled())
                logDebug("Indexing identity::" + identity.getName() + " and counter::" + counter);
            // Create a search context for this identity. The search context will open the users visiting card in a new tab
            SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
            searchResourceContext.setBusinessControlFor(OresHelper.createOLATResourceableInstance(Identity.class, identity.getKey()));
            searchResourceContext.setParentContextType(TYPE);
            // delegate indexing work to all configured indexers
            for (Indexer indexer : getChildIndexers()) {
                indexer.doIndex(searchResourceContext, identity, indexWriter);
            }
            counter++;
        } catch (Exception ex) {
            logWarn("Exception while indexing identity::" + identityKey + ". Skipping this user, try next one.", ex);
            DBFactory.getInstance().rollbackAndCloseSession();
        }
        DBFactory.getInstance().commitAndCloseSession();
    }
    if (isLogDebugEnabled())
        logDebug("IdentityIndexer finished with counter::" + counter);
}
Also used : OlatFullIndexer(org.olat.search.service.indexer.OlatFullIndexer) Indexer(org.olat.search.service.indexer.Indexer) AbstractHierarchicalIndexer(org.olat.search.service.indexer.AbstractHierarchicalIndexer) SearchResourceContext(org.olat.search.service.SearchResourceContext) Identity(org.olat.core.id.Identity) IOException(java.io.IOException) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 12 with BaseSecurity

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

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 13 with BaseSecurity

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

the class CourseAssessmentWebService method attachAssessableResults.

private void attachAssessableResults(Long courseResourceableId, String nodeKey, Identity requestIdentity, AssessableResultsVO resultsVO) {
    try {
        ICourse course = CourseFactory.openCourseEditSession(courseResourceableId);
        CourseNode node = getParentNode(course, nodeKey);
        if (!(node instanceof AssessableCourseNode)) {
            throw new IllegalArgumentException("The supplied node key does not refer to an AssessableCourseNode");
        }
        BaseSecurity securityManager = BaseSecurityManager.getInstance();
        Identity userIdentity = securityManager.loadIdentityByKey(resultsVO.getIdentityKey());
        // create an identenv with no roles, no attributes, no locale
        IdentityEnvironment ienv = new IdentityEnvironment();
        ienv.setIdentity(userIdentity);
        UserCourseEnvironment userCourseEnvironment = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        // Fetch all score and passed and calculate score accounting for the
        // entire course
        userCourseEnvironment.getScoreAccounting().evaluateAll();
        if (node instanceof IQTESTCourseNode) {
            importTestItems(course, nodeKey, requestIdentity, resultsVO);
        } else {
            AssessableCourseNode assessableNode = (AssessableCourseNode) node;
            // not directly pass this key
            ScoreEvaluation scoreEval = new ScoreEvaluation(resultsVO.getScore(), Boolean.TRUE, Boolean.TRUE, new Long(nodeKey));
            assessableNode.updateUserScoreEvaluation(scoreEval, userCourseEnvironment, requestIdentity, true, Role.coach);
        }
        CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
        CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    } catch (Throwable e) {
        throw new WebApplicationException(e);
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) WebApplicationException(javax.ws.rs.WebApplicationException) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ICourse(org.olat.course.ICourse) BaseSecurity(org.olat.basesecurity.BaseSecurity) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) CourseNode(org.olat.course.nodes.CourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 14 with BaseSecurity

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

the class CourseWebService method addCoach.

/**
 * Add a coach to the course
 * @response.representation.200.doc The user is a coach of the course
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or the user not found
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns 200  if the user is added as coach of the course
 */
@PUT
@Path("tutors/{identityKey}")
public Response addCoach(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    Identity tutor = securityManager.loadIdentityByKey(identityKey, false);
    if (tutor == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = getIdentity(httpRequest);
    UserRequest ureq = getUserRequest(httpRequest);
    // add the author as owner of the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    List<Identity> tutors = Collections.singletonList(tutor);
    IdentitiesAddEvent iae = new IdentitiesAddEvent(tutors);
    rm.addTutors(identity, ureq.getUserSession().getRoles(), iae, repositoryEntry, new MailPackage(false));
    return Response.ok().build();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 15 with BaseSecurity

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

the class CourseWebService method removeAuthor.

/**
 * Remove an owner and author to the course
 * @response.representation.200.doc The user was successfully removed as owner of the course
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or the user not found
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns 200  if the user is removed as owner of the course
 */
@DELETE
@Path("authors/{identityKey}")
public Response removeAuthor(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    Identity author = securityManager.loadIdentityByKey(identityKey, false);
    if (author == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = getIdentity(httpRequest);
    // remove the author as owner of the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    List<Identity> authors = Collections.singletonList(author);
    rm.removeOwners(identity, authors, repositoryEntry, new MailPackage(false));
    return Response.ok().build();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

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