當前位置: 首頁>>代碼示例>>Java>>正文


Java AccessDeniedException類代碼示例

本文整理匯總了Java中java.nio.file.AccessDeniedException的典型用法代碼示例。如果您正苦於以下問題:Java AccessDeniedException類的具體用法?Java AccessDeniedException怎麽用?Java AccessDeniedException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AccessDeniedException類屬於java.nio.file包,在下文中一共展示了AccessDeniedException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: prepareErrorList

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
public void prepareErrorList(){
    
    errors.put(new Exception(), Integer.MIN_VALUE);
    errors.put(new NullPointerException(), 10);
    errors.put(new NoSuchFileException("The file could not be found. Sorry for the inconvience"), 20);
    errors.put(new IllegalStateException(), 30);
    errors.put(new FileNotFoundException(), 200);
    errors.put(new AccessDeniedException("The account "+System.getProperty("user.name")+"\nhas not the privileges to do this action."), 40);
    errors.put(new ArrayIndexOutOfBoundsException(),  50);
    errors.put(new UnsupportedOperationException(), 60);
    errors.put(new IOException(), 70);
    errors.put(new MalformedURLException(), 80);
    errors.put(new IllegalArgumentException(), 90);
    
    desc.put(10,"NullPointerException - w którymś momencie w kodzie została napotkana wartość null.");
    desc.put(30,"The value or component has tried to gain illegal state.");
    desc.put(200, "The given file hasn't been found, asure that you gave\nan absolute path and the file exists!");
    desc.put(50, "The index is out of range; it means that the method tried to access the index which is\n"
            + "not in that array.");
    desc.put(60, "Requested operation is not supported at the moment.");
    desc.put(70, "The problem was occured while operating on Input/Output streams.");
    desc.put(90, "The argument given was illegal.");
    desc.put(80, "Given URL is malformed, check\nthat you have write a proper URL address");
}
 
開發者ID:Obsidiam,項目名稱:joanne,代碼行數:25,代碼來源:ErrorLogger.java

示例2: testFileSystemExceptions

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
public void testFileSystemExceptions() throws IOException {
    for (FileSystemException ex : Arrays.asList(new FileSystemException("a", "b", "c"),
        new NoSuchFileException("a", "b", "c"),
        new NotDirectoryException("a"),
        new DirectoryNotEmptyException("a"),
        new AtomicMoveNotSupportedException("a", "b", "c"),
        new FileAlreadyExistsException("a", "b", "c"),
        new AccessDeniedException("a", "b", "c"),
        new FileSystemLoopException("a"))) {

        FileSystemException serialize = serialize(ex);
        assertEquals(serialize.getClass(), ex.getClass());
        assertEquals("a", serialize.getFile());
        if (serialize.getClass() == NotDirectoryException.class ||
            serialize.getClass() == FileSystemLoopException.class ||
            serialize.getClass() == DirectoryNotEmptyException.class) {
            assertNull(serialize.getOtherFile());
            assertNull(serialize.getReason());
        } else {
            assertEquals(serialize.getClass().toString(), "b", serialize.getOtherFile());
            assertEquals(serialize.getClass().toString(), "c", serialize.getReason());
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:ExceptionSerializationTests.java

示例3: getContentStream

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
@Override
public FileContentStream getContentStream(FileHandle handle, String path, String mimeType)
{
	final File file = getFile(handle, path);
	File parent = file.getParentFile();
	while( parent != null )
	{
		if( parent.getName().toUpperCase().equals(SECURE_FOLDER) )
		{
			throw Throwables.propagate(new com.tle.exceptions.AccessDeniedException(
				CurrentLocale.get(KEY_PFX+"error.protectedresource")));
		}
		parent = parent.getParentFile();
	}
	return getContentStream(file, mimeType);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:FileSystemServiceImpl.java

示例4: main

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
public static void main(String[] args) throws Throwable {
    try (FileChannel ch = FileChannel.open(BLK_PATH, READ);
         RandomAccessFile file = new RandomAccessFile(BLK_FNAME, "r")) {

        long size1 = ch.size();
        long size2 = file.length();
        if (size1 != size2) {
            throw new RuntimeException("size differs when retrieved" +
                    " in different ways: " + size1 + " != " + size2);
        }
        System.out.println("OK");

    } catch (NoSuchFileException nsfe) {
        System.err.println("File " + BLK_FNAME + " not found." +
                " Skipping test");
    } catch (AccessDeniedException ade) {
        System.err.println("Access to " + BLK_FNAME + " is denied." +
                " Run test as root.");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:BlockDeviceSize.java

示例5: verifyDirectoryCreatable

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
/**
 * Check whether the current process can create a directory at the specified path. This is useful
 * for providing immediate feedback to an end user that a path they have selected or typed may not
 * be suitable before attempting to create the directory; e.g. in a tooltip.
 *
 * @param path tentative location for directory
 * @throws AccessDeniedException if a directory in the path is not writable
 * @throws NotDirectoryException if a segment of the path is a file
 */
public static void verifyDirectoryCreatable(Path path)
    throws AccessDeniedException, NotDirectoryException {

  for (Path segment = path; segment != null; segment = segment.getParent()) {
    if (Files.exists(segment)) {
      if (Files.isDirectory(segment)) {
        // Can't create a directory if the bottom most currently existing directory in
        // the path is not writable.
        if (!Files.isWritable(segment)) {
          throw new AccessDeniedException(segment + " is not writable");
        }
      } else {
        // Can't create a directory if a non-directory file already exists with that name
        // somewhere in the path.
        throw new NotDirectoryException(segment + " is a file");
      }
      break;
    }
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-plugins-core,代碼行數:30,代碼來源:FilePermissions.java

示例6: throwException

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
private <T> T throwException(String segmentName, Exception e) throws StreamSegmentException {
    if (e instanceof NoSuchFileException || e instanceof FileNotFoundException) {
        throw new StreamSegmentNotExistsException(segmentName);
    }

    if (e instanceof FileAlreadyExistsException) {
        throw new StreamSegmentExistsException(segmentName);
    }

    if (e instanceof IndexOutOfBoundsException) {
        throw new IllegalArgumentException(e.getMessage());
    }

    if (e instanceof AccessControlException
            || e instanceof AccessDeniedException
            || e instanceof NonWritableChannelException) {
        throw new StreamSegmentSealedException(segmentName, e);
    }

    throw Lombok.sneakyThrow(e);
}
 
開發者ID:pravega,項目名稱:pravega,代碼行數:22,代碼來源:FileSystemStorage.java

示例7: testCreateBucketAccessErrors

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
@Test
public void testCreateBucketAccessErrors() throws IOException {
  GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
  GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

  Storage mockStorage = Mockito.mock(Storage.class);
  gcsUtil.setStorageClient(mockStorage);

  Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
  Storage.Buckets.Insert mockStorageInsert = Mockito.mock(Storage.Buckets.Insert.class);

  BackOff mockBackOff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff());
  GoogleJsonResponseException expectedException =
      googleJsonResponseException(HttpStatusCodes.STATUS_CODE_FORBIDDEN,
          "Waves hand mysteriously", "These aren't the buckets you're looking for");

  when(mockStorage.buckets()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.insert(
         any(String.class), any(Bucket.class))).thenReturn(mockStorageInsert);
  when(mockStorageInsert.execute())
      .thenThrow(expectedException);

  thrown.expect(AccessDeniedException.class);

  gcsUtil.createBucket("a", new Bucket(), mockBackOff, new FastNanoClockAndSleeper());
}
 
開發者ID:apache,項目名稱:beam,代碼行數:27,代碼來源:GcsUtilTest.java

示例8: prepareStorageDirectory

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
/**
 * Create the directory returned by {@link #getPath()} if it does not yet exist.
 *
 * @throws IOException
 *             in case the directory cannot be created or exists and is not a directory or
 *             cannot be accessed
 */
protected void prepareStorageDirectory() throws IOException {
    File file = new File(getPath());
    if (!file.exists()) {
        if (!file.mkdirs()) {
            throw new IOException("cannot create directory " + file.getAbsolutePath());
        }
    }

    if (!file.isDirectory()) {
        throw new FileNotFoundException("Defined storage directory isn't a directory: "
                + file.getAbsolutePath());
    } else {
        if (!file.canRead() || !file.canWrite()) {
            throw new AccessDeniedException(file.getAbsolutePath());
        }
        LOGGER.debug("Prepared storage directory: {}", file.getAbsolutePath());
    }
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:26,代碼來源:FilesystemConnector.java

示例9: rename

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
@Override
public boolean rename(final Path src, final Path dst) throws IOException {
	final File srcFile = pathToFile(src);
	final File dstFile = pathToFile(dst);

	final File dstParent = dstFile.getParentFile();

	// Files.move fails if the destination directory doesn't exist
	//noinspection ResultOfMethodCallIgnored -- we don't care if the directory existed or was created
	dstParent.mkdirs();

	try {
		Files.move(srcFile.toPath(), dstFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
		return true;
	}
	catch (NoSuchFileException | AccessDeniedException | DirectoryNotEmptyException | SecurityException ex) {
		// catch the errors that are regular "move failed" exceptions and return false
		return false;
	}
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:21,代碼來源:LocalFileSystem.java

示例10: addStatusNote

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
public void addStatusNote(UUID reservationId,Integer statusCode,NoteModel noteModel) throws Exception{
	String projectGroupCode = SecurityContextUtil.getUserProjectGroup(); 
	
	List<MatchStatus> statusHistory = repositoryFactory.getMatchStatusRepository().findByReservationIdAndStatus(reservationId,statusCode);
	
	if(statusHistory.isEmpty()) throw new AccessDeniedException("Access denide");
	
	StatusNotesEntity note = new StatusNotesEntity();
	note.setNotes(noteModel.getNote());
	note.setStatusId(statusHistory.get(0).getId());
	note.setDateCreated(LocalDateTime.now());
	note.setDateUpdated(LocalDateTime.now());
	note.setProjectGroupCode(projectGroupCode);
	note.setUserId(SecurityContextUtil.getUserAccount().getAccountId());
	note.setClientId(statusHistory.get(0).getClientId());
	note.setClientDedupId(statusHistory.get(0).getClientDedupId());
	repositoryFactory.getStatusNotesRepository().save(note);
}
 
開發者ID:hserv,項目名稱:coordinated-entry,代碼行數:19,代碼來源:MatchReservationsServiceImplV3.java

示例11: getRequest

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
@ApiOperation(
        value = "Get specific acquisition request of file transfer with given id",
        notes = "Privilege level: Consumer of this endpoint must be a member of organization based on valid access token"
)
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "OK",response = RequestDTO.class),
        @ApiResponse(code = 401, message = "Unauthorized"),
        @ApiResponse(code = 403, message = "Can't access this organization."),
        @ApiResponse(code = 500, message = "Internal server error, see logs for details.")
})
@RequestMapping(value = "/{id}", method = GET)
@ResponseBody
public RequestDTO getRequest(@PathVariable String id, HttpServletRequest context)
        throws AccessDeniedException {
    LOGGER.debug("get({})", id);
    Request request = requestStore.get(id).orElseThrow(NoSuchElementException::new);
    RequestDTO toReturn = request.toDto();
    permissionVerifier.throwForbiddenWhenNotAuthorized(context, toReturn);
    return toReturn;
}
 
開發者ID:trustedanalytics,項目名稱:data-acquisition,代碼行數:21,代碼來源:RestDataAcquisitionService.java

示例12: testGetResourceWithAccessDeniedException

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
@Test(expected = AccessDeniedException.class)
   public void testGetResourceWithAccessDeniedException() throws Exception {
// Given
Long id = 5L;
Long enrolmentId = 2L;

// When
doThrow(AccessDeniedException.class).when(facade)
	.getResource(anyLong());

// Then
mockMvc.perform(get("/enrolments/{enrolmentId}/enrolmentsubjects/{id}",
	enrolmentId, id));

verify(facade).getResource(id);
   }
 
開發者ID:ifnul,項目名稱:ums-backend,代碼行數:17,代碼來源:EnrolmentEnrolmentSubjectControllerTest.java

示例13: testGetResourceWithAccessDeniedException

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
@Test(expected = AccessDeniedException.class)
   public void testGetResourceWithAccessDeniedException() throws Exception {
// Given
Long id = 1L;
Long enrolmentId = 2L;

// When
doThrow(AccessDeniedException.class).when(facade)
	.getResource(anyLong());

// Then
mockMvc.perform(get("/enrolments/{enrolmentId}/statuses/{id}",
	enrolmentId, id));

verify(facade).getResource(id);
   }
 
開發者ID:ifnul,項目名稱:ums-backend,代碼行數:17,代碼來源:EnrolmentStatusControllerTest.java

示例14: testGetResourceWithAccessDeniedException

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
@Test(expected = AccessDeniedException.class)
   public void testGetResourceWithAccessDeniedException() throws Exception {
// Given
Long id = 1L;
Long enrolmentId = 2L;

// When
doThrow(AccessDeniedException.class).when(facade)
	.getResource(anyLong());

// Then
mockMvc.perform(get("/enrolments/{enrolmentId}/benefits/{id}",
	enrolmentId, id));

verify(facade).getResource(id);
   }
 
開發者ID:ifnul,項目名稱:ums-backend,代碼行數:17,代碼來源:EnrolmentBenefitControllerTest.java

示例15: testGetResourceWithAccessDeniedException

import java.nio.file.AccessDeniedException; //導入依賴的package包/類
@Test(expected = AccessDeniedException.class)
   public void testGetResourceWithAccessDeniedException() throws Exception {
// Given
Long id = 1L;
Long publicActivityId = 2L;

// When
doThrow(AccessDeniedException.class).when(facade)
	.getResource(anyLong());

// Then
mockMvc.perform(get("/publicactivities/{publicActivityId}/awards/{id}",
	publicActivityId, id));

verify(facade).getResource(id);
   }
 
開發者ID:ifnul,項目名稱:ums-backend,代碼行數:17,代碼來源:PublicActivityAwardControllerTest.java


注:本文中的java.nio.file.AccessDeniedException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。