Search in sources :

Example 21 with BaseSecurity

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

the class RepositoryEntriesResource method getRepositoryEntryResource.

@Path("{repoEntryKey}")
public RepositoryEntryResource getRepositoryEntryResource() {
    RepositoryManager rm = RepositoryManager.getInstance();
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    return new RepositoryEntryResource(rm, repositoryService, securityManager);
}
Also used : RepositoryManager(org.olat.repository.RepositoryManager) BaseSecurity(org.olat.basesecurity.BaseSecurity) RepositoryService(org.olat.repository.RepositoryService) Path(javax.ws.rs.Path)

Example 22 with BaseSecurity

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

the class OpenOLATStatisticsWebService method getUserStatisticsVO.

private UserStatisticsVO getUserStatisticsVO() {
    UserStatisticsVO stats = new UserStatisticsVO();
    BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    // activeUserCount="88" // registered and activated identities, same as in GUI
    long countActiveUsers = securityManager.countIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, null, null, Constants.USERSTATUS_ACTIVE);
    stats.setActiveUserCount(countActiveUsers);
    // active last day
    Calendar lastDay = Calendar.getInstance();
    lastDay.add(Calendar.DATE, -1);
    long activeUserCountDay = securityManager.countUniqueUserLoginsSince(lastDay.getTime());
    stats.setActiveUserCountLastDay(activeUserCountDay);
    // active last week
    Calendar lastWeek = Calendar.getInstance();
    lastWeek.add(Calendar.DATE, -7);
    long activeUserCountWeek = securityManager.countUniqueUserLoginsSince(lastWeek.getTime());
    stats.setActiveUserCountLastWeek(activeUserCountWeek);
    // active last month
    Calendar lastMonth = Calendar.getInstance();
    lastMonth.add(Calendar.MONTH, -1);
    long activeUserCountMonth = securityManager.countUniqueUserLoginsSince(lastMonth.getTime());
    stats.setActiveUserCountLastMonth(activeUserCountMonth);
    // active last 6 month
    Calendar last6Month = Calendar.getInstance();
    last6Month.add(Calendar.MONTH, -6);
    long activeUserCount6Month = securityManager.countUniqueUserLoginsSince(last6Month.getTime());
    stats.setActiveUserCountLast6Month(activeUserCount6Month);
    // externalUserCount="12" // EP invite identities, later maybe also used in courses for MOOCS, external experts etc)
    long invitationsCount = CoreSpringFactory.getImpl(InvitationDAO.class).countInvitations();
    stats.setExternalUserCount(invitationsCount);
    // blockedUserCount="0" // identities in login blocked state
    long blockedUserCount = securityManager.countIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_LOGIN_DENIED);
    stats.setBlockedUserCount(blockedUserCount);
    // deletedUserCount="943" // deleted identities
    long deletedUserCount = securityManager.countIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_DELETED);
    stats.setDeletedUserCount(deletedUserCount);
    // totalUserCount="1043" // Sum of all above
    long countUsers = securityManager.countIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, null, null, null);
    stats.setTotalUserCount(countUsers);
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    long countGroups = bgs.countBusinessGroups(null, null);
    stats.setTotalGroupCount(countGroups);
    return stats;
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) Calendar(java.util.Calendar) InvitationDAO(org.olat.portfolio.manager.InvitationDAO) UserStatisticsVO(org.olat.restapi.system.vo.UserStatisticsVO) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 23 with BaseSecurity

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

the class QuestionPoolWebService method removeAuthor.

/**
 * Remove an author to the question item.
 *
 * @response.representation.200.doc The user was successfully removed as author of the question item
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The question item or the user not found
 * @param itemKey The question item identifier
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns 200  if the user is removed as author of the question item
 */
@DELETE
@Path("{itemKey}/authors/{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response removeAuthor(@PathParam("itemKey") Long itemKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isQuestionPoolManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    QPoolService poolService = CoreSpringFactory.getImpl(QPoolService.class);
    QuestionItem item = poolService.loadItemById(itemKey);
    if (item == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity author = securityManager.loadIdentityByKey(identityKey, false);
    if (author == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<Identity> authors = Collections.singletonList(author);
    List<QuestionItemShort> items = Collections.singletonList(item);
    poolService.removeAuthors(authors, items);
    return Response.ok().build();
}
Also used : QPoolService(org.olat.modules.qpool.QPoolService) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 24 with BaseSecurity

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

the class QuestionPoolWebService method addAuthor.

/**
 * Add an author to the question item.
 *
 * @response.representation.200.doc The user is an author of the question item
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The question item or the user not found
 * @param itemKey The question item identifier
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns 200  if the user is added as author of the question item
 */
@PUT
@Path("{itemKey}/authors/{identityKey}")
public Response addAuthor(@PathParam("itemKey") Long itemKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isQuestionPoolManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    QPoolService poolService = CoreSpringFactory.getImpl(QPoolService.class);
    QuestionItem item = poolService.loadItemById(itemKey);
    if (item == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity author = securityManager.loadIdentityByKey(identityKey, false);
    if (author == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<Identity> authors = Collections.singletonList(author);
    List<QuestionItemShort> items = Collections.singletonList(item);
    poolService.addAuthors(authors, items);
    return Response.ok().build();
}
Also used : QPoolService(org.olat.modules.qpool.QPoolService) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 25 with BaseSecurity

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

the class UserAuthenticationWebService method delete.

/**
 * Deletes an authentication from the system
 * @response.representation.200.doc The authentication successfully deleted
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The identity or the authentication not found
 * @param username The username of the user
 * @param authKey The authentication key identifier
 * @param request The HTTP request
 * @return <code>Response</code> object. The operation status (success or
 *         fail)
 */
@DELETE
@Path("{authKey}")
public Response delete(@PathParam("username") String username, @PathParam("authKey") Long authKey, @Context HttpServletRequest request) {
    if (!isUserManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity baseSecurity = BaseSecurityManager.getInstance();
    Identity identity = baseSecurity.findIdentityByName(username);
    if (identity == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    List<Authentication> authentications = baseSecurity.getAuthentications(identity);
    for (Authentication authentication : authentications) {
        if (authKey.equals(authentication.getKey())) {
            baseSecurity.deleteAuthentication(authentication);
            return Response.ok().build();
        }
    }
    return Response.serverError().status(Status.NOT_FOUND).build();
}
Also used : Authentication(org.olat.basesecurity.Authentication) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) 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