use of org.olat.resource.accesscontrol.AccessResult in project openolat by klemens.
the class CoursesInfosWebService method collect.
private CourseInfoVO collect(final Identity identity, final Roles roles, final RepositoryEntry entry, final Set<Long> forumNotified, final Map<Long, Set<String>> courseNotified) {
CourseInfoVO info = new CourseInfoVO();
info.setRepoEntryKey(entry.getKey());
info.setSoftKey(entry.getSoftkey());
info.setDisplayName(entry.getDisplayname());
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
AccessResult result = acManager.isAccessible(entry, identity, false);
if (result.isAccessible()) {
try {
final ICourse course = CourseFactory.loadCourse(entry);
final List<FolderVO> folders = new ArrayList<FolderVO>();
final List<ForumVO> forums = new ArrayList<ForumVO>();
final IdentityEnvironment ienv = new IdentityEnvironment(identity, roles);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode) node;
folders.add(BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId())));
} else if (node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode) node;
forums.add(ForumCourseNodeWebService.createForumVO(course, forumNode, forumNotified));
}
}
}, new VisibleTreeFilter());
info.setKey(course.getResourceableId());
info.setTitle(course.getCourseTitle());
info.setFolders(folders.toArray(new FolderVO[folders.size()]));
info.setForums(forums.toArray(new ForumVO[forums.size()]));
} catch (Exception e) {
log.error("", e);
}
}
return info;
}
use of org.olat.resource.accesscontrol.AccessResult in project openolat by klemens.
the class CoursesWebService method isCourseAccessible.
public static boolean isCourseAccessible(ICourse course, boolean authorRightsMandatory, HttpServletRequest request) {
if (authorRightsMandatory && !isAuthor(request)) {
return false;
}
Identity identity = getIdentity(request);
RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
AccessResult result = acManager.isAccessible(entry, identity, false);
if (result.isAccessible()) {
return true;
}
return false;
}
use of org.olat.resource.accesscontrol.AccessResult in project openolat by klemens.
the class RepositoryIndexer method checkAccess.
/**
* @see org.olat.search.service.indexer.Indexer#checkAccess(org.olat.core.id.context.ContextEntry, org.olat.core.id.context.BusinessControl, org.olat.core.id.Identity, org.olat.core.id.Roles)
*/
@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
boolean debug = isLogDebugEnabled();
if (debug)
logDebug("checkAccess for businessControl=" + businessControl + " identity=" + identity + " roles=" + roles);
Long repositoryKey = contextEntry.getOLATResourceable().getResourceableId();
RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(repositoryKey);
if (repositoryEntry == null) {
return false;
}
if (roles.isGuestOnly()) {
if (repositoryEntry.getAccess() != RepositoryEntry.ACC_USERS_GUESTS) {
return false;
}
}
boolean isOwner = repositoryManager.isOwnerOfRepositoryEntry(identity, repositoryEntry);
boolean isAllowedToLaunch = false;
if (!isOwner) {
isAllowedToLaunch = repositoryManager.isAllowedToLaunch(identity, roles, repositoryEntry);
if (isAllowedToLaunch) {
List<ContextEntry> entries = businessControl.getEntriesDownTheControls();
if (entries.size() > 1) {
boolean hasAccess = false;
ACService acService = CoreSpringFactory.getImpl(ACService.class);
AccessResult acResult = acService.isAccessible(repositoryEntry, identity, false);
if (acResult.isAccessible()) {
hasAccess = true;
} else if (!acResult.getAvailableMethods().isEmpty()) {
for (OfferAccess offer : acResult.getAvailableMethods()) {
String type = offer.getMethod().getType();
if (type.equals(FreeAccessHandler.METHOD_TYPE) || type.equals(PaypalAccessHandler.METHOD_TYPE)) {
hasAccess = true;
}
}
}
isAllowedToLaunch = hasAccess;
}
}
}
if (debug)
logDebug("isOwner=" + isOwner + " isAllowedToLaunch=" + isAllowedToLaunch);
if (isOwner || isAllowedToLaunch) {
Indexer repositoryEntryIndexer = getRepositoryEntryIndexer(repositoryEntry);
if (debug)
logDebug("repositoryEntryIndexer=" + repositoryEntryIndexer);
if (repositoryEntryIndexer != null) {
return super.checkAccess(contextEntry, businessControl, identity, roles) && repositoryEntryIndexer.checkAccess(contextEntry, businessControl, identity, roles);
}
}
return false;
}
use of org.olat.resource.accesscontrol.AccessResult in project openolat by klemens.
the class TokenAccessController method formOK.
@Override
protected void formOK(UserRequest ureq) {
String token = tokenEl.getValue();
AccessResult result = acService.accessResource(getIdentity(), link, token);
if (result.isAccessible()) {
fireEvent(ureq, AccessEvent.ACCESS_OK_EVENT);
} else {
String msg = translate("invalid.token");
fireEvent(ureq, new AccessEvent(AccessEvent.ACCESS_FAILED, msg));
}
}
use of org.olat.resource.accesscontrol.AccessResult in project openolat by klemens.
the class MainAccessController method doAccessResource.
protected void doAccessResource(UserRequest ureq, OfferAccess link) {
AccessResult result = acService.accessResource(getIdentity(), link, null);
if (result.isAccessible()) {
fireEvent(ureq, AccessEvent.ACCESS_OK_EVENT);
} else {
fireEvent(ureq, new AccessEvent(AccessEvent.ACCESS_FAILED));
showError("error.accesscontrol");
}
}
Aggregations