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