当前位置: 首页>>代码示例>>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;未经允许,请勿转载。