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);
}
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;
}
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();
}
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();
}
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();
}
Aggregations