Search in sources :

Example 1 with BaseSecurity

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

the class PersonalRSSUtil method getPersonalRssLink.

/**
 * Calculates the absolute URL to the users personal rss feed
 * @param ureq
 * @return String
 */
public static String getPersonalRssLink(UserRequest ureq) {
    String token = null;
    Identity identity = ureq.getIdentity();
    BaseSecurity secManager = BaseSecurityManager.getInstance();
    Authentication auth = secManager.findAuthentication(identity, RSS_AUTH_PROVIDER);
    if (auth == null) {
        // no token found - create one
        token = RandomStringUtils.randomAlphanumeric(6);
        auth = secManager.createAndPersistAuthentication(identity, RSS_AUTH_PROVIDER, identity.getName(), token, null);
    } else {
        token = auth.getCredential();
    }
    StringBuilder sb = new StringBuilder();
    return sb.append(PersonalRSSUtil.URI_PERSONAL_CHANNEL).append(ureq.getIdentity().getName()).append("/").append(token).append("/olat.rss").toString();
}
Also used : Authentication(org.olat.basesecurity.Authentication) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 2 with BaseSecurity

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

the class EfficiencyStatementWebService method putEfficiencyStatement.

/**
 * Create a new efficiency statement.
 *
 * @response.representation.200.doc If the statement was persisted
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The identity or the resource cannot be found
 * @param identityKey The owner of the certificate
 * @param resourceKey The primary key of the resource of the repository entry of the course.
 * @return Nothing special
 */
@PUT
@Path("{identityKey}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response putEfficiencyStatement(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, EfficiencyStatementVO efficiencyStatementVO, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity assessedIdentity = baseSecurity.loadIdentityByKey(identityKey);
    if (assessedIdentity == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    EfficiencyStatementManager efficiencyStatementManager = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
    EfficiencyStatement efficiencyStatement = efficiencyStatementManager.getUserEfficiencyStatementByResourceKey(resourceKey, assessedIdentity);
    if (efficiencyStatement != null) {
        return Response.serverError().status(Response.Status.CONFLICT).build();
    }
    Date creationDate = efficiencyStatementVO.getCreationDate();
    Float score = efficiencyStatementVO.getScore();
    Boolean passed = efficiencyStatementVO.getPassed();
    OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
    OLATResource resource = resourceManager.findResourceById(resourceKey);
    if (resource == null) {
        String courseTitle = efficiencyStatementVO.getCourseTitle();
        efficiencyStatementManager.createStandAloneUserEfficiencyStatement(creationDate, score, passed, assessedIdentity, resourceKey, courseTitle);
    } else {
        efficiencyStatementManager.createUserEfficiencyStatement(creationDate, score, passed, assessedIdentity, resource);
    }
    return Response.ok().build();
}
Also used : EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) EfficiencyStatement(org.olat.course.assessment.EfficiencyStatement) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) Date(java.util.Date) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 3 with BaseSecurity

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

the class EfficiencyStatementWebService method getEfficiencyStatement.

@GET
@Path("{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getEfficiencyStatement(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity assessedIdentity = baseSecurity.loadIdentityByKey(identityKey);
    if (assessedIdentity == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    UserEfficiencyStatement efficiencyStatement = CoreSpringFactory.getImpl(EfficiencyStatementManager.class).getUserEfficiencyStatementLightByResource(resourceKey, assessedIdentity);
    if (efficiencyStatement == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    EfficiencyStatementVO statementVO = new EfficiencyStatementVO(efficiencyStatement);
    return Response.ok(statementVO).build();
}
Also used : EfficiencyStatementVO(org.olat.course.assessment.model.EfficiencyStatementVO) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with BaseSecurity

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

the class CertificationWebService method deleteCertificateInfo.

@DELETE
@Path("{identityKey}")
public Response deleteCertificateInfo(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
    BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity identity = baseSecurity.loadIdentityByKey(identityKey);
    if (identity == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", resourceKey);
    OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
    OLATResource resource = resourceManager.findResourceable(courseOres);
    if (resource == null) {
        resource = resourceManager.findResourceById(resourceKey);
    }
    if (resource == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    Certificate certificate = certificatesManager.getLastCertificate(identity, resource.getKey());
    if (certificate == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    certificatesManager.deleteCertificate(certificate);
    return Response.ok().build();
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) CertificatesManager(org.olat.course.certificate.CertificatesManager) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Certificate(org.olat.course.certificate.Certificate) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 5 with BaseSecurity

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

the class CertificationWebService method getCertificateInfo.

@HEAD
@Path("{identityKey}")
@Produces({ "application/pdf" })
public Response getCertificateInfo(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
    BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity identity = baseSecurity.loadIdentityByKey(identityKey);
    if (identity == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", resourceKey);
    OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
    OLATResource resource = resourceManager.findResourceable(courseOres);
    if (resource == null) {
        resource = resourceManager.findResourceById(resourceKey);
    }
    if (resource == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    Certificate certificate = certificatesManager.getLastCertificate(identity, resource.getKey());
    if (certificate == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(certificate);
    if (certificateFile == null || !certificateFile.exists()) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    return Response.ok().build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATResourceable(org.olat.core.id.OLATResourceable) CertificatesManager(org.olat.course.certificate.CertificatesManager) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Certificate(org.olat.course.certificate.Certificate) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) Produces(javax.ws.rs.Produces)

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