org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException Java Examples
The following examples show how to use
org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LDCmisService.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
private Session validateSession() { if (getSid() == null) return null; try { Session session = SessionManager.get().get(getSid()); if (session == null) throw new CmisPermissionDeniedException("Unexisting session " + getSid()); if (SessionManager.get().getStatus(getSid()) != Session.STATUS_OPEN) throw new CmisPermissionDeniedException("Invalid or Expired Session " + getSid()); SessionManager.get().renew(getSid()); return session; } catch (Throwable t) { log.error(t.getMessage(), t); if (t instanceof CmisBaseException) throw (CmisBaseException) t; else throw new CmisPermissionDeniedException("Invalid session!"); } }
Example #2
Source File: LDCmisService.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
public LDRepository getRepository() { LDRepository repo = null; Session session = validateSession(); if (StringUtils.isEmpty(getCallContext().getRepositoryId())) { /* * The information is not in the request, so fallback to the session */ repo = repositories.get(session.getDictionary().get(ServiceFactory.KEY_REPO_ID)); } else { // Update the last accessed repository repo = repositories.get(getCallContext().getRepositoryId()); session.getDictionary().put(ServiceFactory.KEY_REPO_ID, repo.getId()); } if (repo == null) throw new CmisPermissionDeniedException( "Repository " + getCallContext().getRepositoryId() + " not found !"); return repo; }
Example #3
Source File: LDRepository.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public void cancelCheckOut(String objectId) { debug("cancelCheckOut " + objectId); validatePermission(objectId, null, Permission.WRITE); try { // get the document PersistentObject object = getObject(objectId); if (object == null) throw new CmisObjectNotFoundException(String.format("Object %s not found!", objectId)); if (!(object instanceof Document)) throw new CmisObjectNotFoundException(String.format("Object %s is not a Document!", objectId)); Document doc = (Document) object; if (doc.getStatus() == Document.DOC_CHECKED_OUT && ((getSessionUser().getId() != doc.getLockUserId()) && (!getSessionUser().isMemberOf("admin")))) throw new CmisPermissionDeniedException("You can't change the checkout status on this object!"); // Create the document history event DocumentHistory transaction = new DocumentHistory(); transaction.setSessionId(sid); transaction.setEvent(DocumentEvent.UNLOCKED.toString()); transaction.setComment(""); transaction.setUser(getSessionUser()); documentDao.initialize(doc); doc.setStatus(Document.DOC_UNLOCKED); documentDao.store(doc, transaction); } catch (Throwable t) { catchError(t); } }
Example #4
Source File: LDRepository.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public void checkIn(Holder<String> objectId, Boolean major, ContentStream contentStream, Properties properties, String checkinComment) { //debug("checkin " + objectId); log.debug("checkin {}", objectId); validatePermission(objectId.getValue(), null, Permission.WRITE); try { PersistentObject object = getObject(objectId.getValue()); if (object == null) throw new CmisObjectNotFoundException(String.format("Object %s not found!", objectId.getValue())); if (!(object instanceof Document)) throw new CmisObjectNotFoundException( String.format("Object %s is not a Document!", objectId.getValue())); Document doc = (Document) object; if (doc.getStatus() == Document.DOC_CHECKED_OUT && ((getSessionUser().getId() != doc.getLockUserId()) && (!getSessionUser().isMemberOf("admin")))) { throw new CmisPermissionDeniedException( String.format("You can't do a checkin on object %s!", objectId.getValue())); } DocumentHistory transaction = new DocumentHistory(); transaction.setSessionId(sid); transaction.setEvent(DocumentEvent.CHECKEDIN.toString()); transaction.setUser(getSessionUser()); transaction.setComment(checkinComment); if (properties != null) { updateDocumentMetadata(doc, properties, false); } documentManager.checkin(doc.getId(), contentStream.getStream(), doc.getFileName(), major, null, transaction); } catch (Throwable t) { catchError(t); } }
Example #5
Source File: LDRepository.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
private void validatePermission(String objectId, CallContext context, Permission permission) throws CmisPermissionDeniedException { if (!checkPermission(objectId != null ? getObject(objectId) : null, context, permission)) { CmisPermissionDeniedException exception = new CmisPermissionDeniedException( "Permission " + (permission != null ? permission.getName() : "") + " not granted on " + objectId); if (log.isDebugEnabled()) log.error(exception.getMessage(), exception); throw exception; } }
Example #6
Source File: CMISNodeInfoImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void checkIfUseful(String what) { switch (objecVariant) { case INVALID_ID: throw new CmisInvalidArgumentException(what + " id is invalid: " + objectId); case NOT_EXISTING: throw new CmisObjectNotFoundException(what + " not found: " + objectId); case NOT_A_CMIS_OBJECT: throw new CmisObjectNotFoundException(what + " is not a CMIS object: " + objectId); case PERMISSION_DENIED: throw new CmisPermissionDeniedException("Permission denied!"); } }
Example #7
Source File: AlfrescoCmisExceptionInterceptorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testAuthenticationException() throws Throwable { Exception e = new AuthenticationException("x"); Class<?> toCatch = CmisPermissionDeniedException.class; doMockCall(e, toCatch); doMockCall(new RuntimeException(new RuntimeException(e)), toCatch); }
Example #8
Source File: AlfrescoCmisExceptionInterceptorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testAccessDeniedException() throws Throwable { Exception e = new AccessDeniedException("x"); Class<?> toCatch = CmisPermissionDeniedException.class; doMockCall(e, toCatch); doMockCall(new RuntimeException(new RuntimeException(e)), toCatch); }
Example #9
Source File: LDRepository.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
public ObjectList getContentChanges(Holder<String> changeLogToken, int max) throws CmisPermissionDeniedException { log.debug("getContentChanges {}", changeLogToken.getValue()); if (changeLogToken == null) throw new CmisInvalidArgumentException("Missing change log token holder"); long minDate; try { minDate = Long.parseLong(changeLogToken.getValue()); } catch (NumberFormatException e) { throw new CmisInvalidArgumentException("Invalid change log token"); } ObjectListImpl ol = new ObjectListImpl(); List<ObjectData> odsDocs = getDocumentLastChanges(minDate, max); List<ObjectData> odsFolders = getFolderLastChanges(minDate, max); //put together the 2 lists List<ObjectData> complex = new ArrayList<ObjectData>(); complex.addAll(odsDocs); complex.addAll(odsFolders); // log.debug("Before sort"); // for (ObjectData objectData : complex) { // log.debug("ChangeTime {}", objectData.getChangeEventInfo().getChangeTime().getTime()); // } // sort the content of list complex by date Collections.sort(complex, new Comparator<ObjectData>() { public int compare(ObjectData o1, ObjectData o2) { return o1.getChangeEventInfo().getChangeTime().getTime() .compareTo(o2.getChangeEventInfo().getChangeTime().getTime()); } }); // log.debug("After sort"); // for (ObjectData objectData : complex) { // log.debug("ChangeTime {} {} {} {}", objectData.getChangeEventInfo().getChangeType(), objectData.getId() ,objectData.getChangeEventInfo().getChangeTime().getTime(), objectData.getChangeEventInfo().getChangeTime().getTime().getTime()); // } boolean hasMoreItems = complex.size() > max; if (hasMoreItems) { complex = complex.subList(0, max); } ol.setObjects(complex); Date date = null; if (complex.size() > 0) { //ol.setNumItems(BigInteger.valueOf(complex.size())); ol.setNumItems(BigInteger.valueOf(-1)); //ol.setHasMoreItems(true); ol.setHasMoreItems(Boolean.valueOf(hasMoreItems)); date = ((ObjectData)complex.get(complex.size() -1)).getChangeEventInfo().getChangeTime().getTime(); // log.debug("date {}", date); // log.debug("date.getTime {}", date.getTime()); } else { ol.setHasMoreItems(Boolean.valueOf(false)); ol.setNumItems(BigInteger.ZERO); } String latestChangeLogToken = date == null ? null : String.valueOf(date.getTime()); log.debug("latestChangeLogToken {}", latestChangeLogToken); changeLogToken.setValue(latestChangeLogToken); return ol; }
Example #10
Source File: AlfrescoCmisExceptionInterceptor.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public Object invoke(MethodInvocation mi) throws Throwable { try { return mi.proceed(); } catch (Exception e) { // We dig into the exception to see if there is anything of interest to CMIS Throwable cmisAffecting = ExceptionStackUtil.getCause(e, EXCEPTIONS_OF_INTEREST); if (cmisAffecting == null) { // The exception is not something that CMIS needs to handle in any special way if (e instanceof CmisBaseException) { throw (CmisBaseException) e; } else { throw new CmisRuntimeException(e.getMessage(), e); } } // All other exceptions are carried through with full stacks but treated as the exception of interest else if (cmisAffecting instanceof AuthenticationException) { throw new CmisPermissionDeniedException(cmisAffecting.getMessage(), e); } else if (cmisAffecting instanceof CheckOutCheckInServiceException) { throw new CmisVersioningException("Check out failed: " + cmisAffecting.getMessage(), e); } else if (cmisAffecting instanceof FileExistsException) { throw new CmisContentAlreadyExistsException("An object with this name already exists: " + cmisAffecting.getMessage(), e); } else if (cmisAffecting instanceof IntegrityException) { throw new CmisConstraintException("Constraint violation: " + cmisAffecting.getMessage(), e); } else if (cmisAffecting instanceof AccessDeniedException) { throw new CmisPermissionDeniedException("Permission denied: " + cmisAffecting.getMessage(), e); } else if (cmisAffecting instanceof NodeLockedException) { throw new CmisUpdateConflictException("Update conflict: " + cmisAffecting.getMessage(), e); } else { // We should not get here, so log an error but rethrow to have CMIS handle the original cause logger.error("Exception type not handled correctly: " + e.getClass().getName()); throw new CmisRuntimeException(e.getMessage(), e); } } }