Search in sources :

Example 61 with BaseSecurity

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

the class CourseWebService method addAuthors.

@PUT
@Path("authors")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addAuthors(UserVO[] authors, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    List<Identity> authorList = loadIdentities(authors);
    Identity identity = getIdentity(httpRequest);
    SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    for (Identity author : authorList) {
        boolean hasBeenAuthor = securityManager.isIdentityInSecurityGroup(author, authorGroup);
        if (!hasBeenAuthor) {
            // not an author already, add this identity to the security group "authors"
            securityManager.addIdentityToSecurityGroup(author, authorGroup);
            log.audit("User::" + identity.getName() + " added system role::" + Constants.GROUP_AUTHORS + " to user::" + author.getName() + " via addAuthor method in course REST API", null);
        }
    }
    // add the author as owner of the course
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authorList);
    RepositoryManager.getInstance().addOwners(identity, identitiesAddedEvent, repositoryEntry, new MailPackage(false));
    return Response.ok().build();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 62 with BaseSecurity

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

the class CourseWebService method removeCoach.

/**
 * Remove a coach from the course
 * @response.representation.200.doc The user was successfully removed as 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 removed as coach of the course
 */
@DELETE
@Path("tutors/{identityKey}")
public Response removeCoach(@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 coach = securityManager.loadIdentityByKey(identityKey, false);
    if (coach == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = getIdentity(httpRequest);
    // remove the user as coach of the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    List<Identity> coaches = Collections.singletonList(coach);
    rm.removeTutors(identity, coaches, 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)

Example 63 with BaseSecurity

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

the class CourseWebService method removeParticipant.

/**
 * Remove a participant from the course
 * @response.representation.200.doc The user was successfully removed as participant 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 participant of the course
 */
@DELETE
@Path("participants/{identityKey}")
public Response removeParticipant(@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 participant = securityManager.loadIdentityByKey(identityKey, false);
    if (participant == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = getIdentity(httpRequest);
    // remove the user as participant of the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    List<Identity> participants = Collections.singletonList(participant);
    rm.removeParticipants(identity, participants, repositoryEntry, new MailPackage(false), 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)

Example 64 with BaseSecurity

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

the class RestSecurityHelper method isAuthorEditor.

public static boolean isAuthorEditor(OLATResourceable resourceable, HttpServletRequest request) {
    try {
        Roles roles = getRoles(request);
        if (roles.isOLATAdmin())
            return true;
        if (roles.isAuthor()) {
            UserRequest ureq = getUserRequest(request);
            Identity identity = ureq.getIdentity();
            BaseSecurity secMgr = BaseSecurityManager.getInstance();
            return secMgr.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_ADMIN, resourceable);
        }
        return false;
    } catch (Exception e) {
        return false;
    }
}
Also used : Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) ParseException(java.text.ParseException) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 65 with BaseSecurity

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

the class UsersSubscriptionManagerImpl method getNewIdentityCreated.

/**
 * The search in the ManagerFactory is date based and not timestamp based.
 * The guest are also removed from the list.
 */
@Override
public List<Identity> getNewIdentityCreated(Date from) {
    if (from == null)
        return Collections.emptyList();
    BaseSecurity manager = BaseSecurityManager.getInstance();
    PermissionOnResourceable[] permissions = { new PermissionOnResourceable(Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GUESTONLY) };
    List<Identity> guests = manager.getIdentitiesByPowerSearch(null, null, true, null, permissions, null, from, null, null, null, Identity.STATUS_VISIBLE_LIMIT);
    List<Identity> identities = manager.getIdentitiesByPowerSearch(null, null, true, null, null, null, from, null, null, null, Identity.STATUS_VISIBLE_LIMIT);
    if (!identities.isEmpty() && !guests.isEmpty()) {
        identities.removeAll(guests);
    }
    for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
        Identity identity = identityIt.next();
        if (identity.getCreationDate().before(from)) {
            identityIt.remove();
        }
    }
    return identities;
}
Also used : Identity(org.olat.core.id.Identity) PermissionOnResourceable(org.olat.basesecurity.PermissionOnResourceable) 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