本文整理汇总了Java中org.jclouds.rest.AuthorizationException类的典型用法代码示例。如果您正苦于以下问题:Java AuthorizationException类的具体用法?Java AuthorizationException怎么用?Java AuthorizationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthorizationException类属于org.jclouds.rest包,在下文中一共展示了AuthorizationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testListFlavors
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
@Test
public void testListFlavors() throws Exception {
List<DeploymentFlavour> flavors = openstackClient.listFlavors(vimInstance);
assertEqualsFlavors(definedFlavor, flavors.get(0));
NovaApi novaApi = mock(NovaApi.class);
PowerMockito.spy(ContextBuilder.class);
ContextBuilder contextBuilder = mock(ContextBuilder.class);
PowerMockito.doReturn(contextBuilder)
.when(ContextBuilder.class, "newBuilder", Mockito.anyString());
when(contextBuilder.endpoint(anyString())).thenReturn(contextBuilder);
when(contextBuilder.credentials(anyString(), anyString())).thenReturn(contextBuilder);
when(contextBuilder.modules(any(Iterable.class))).thenReturn(contextBuilder);
when(contextBuilder.overrides(any(Properties.class))).thenReturn(contextBuilder);
when(contextBuilder.buildApi(NovaApi.class)).thenReturn(novaApi);
FlavorApi flavorApi = mock(FlavorApi.class);
when(novaApi.getFlavorApi(anyString())).thenReturn(flavorApi);
when(flavorApi.listInDetail()).thenReturn(mock(PagedIterable.class));
when(flavorApi.listInDetail().concat()).thenThrow(new AuthorizationException());
exception.expect(VimDriverException.class);
openstackClient.listFlavors(vimInstance);
}
示例2: get
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
@Override
public Set<AssignableLocation> get() {
Set<Host> hosts = new HashSet<>();
try {
if (novaApi.getHostAdministrationApi(availabilityZone.getParent().getId())
.isPresent()) {
hosts.addAll(StreamSupport.stream(
novaApi.getHostAdministrationApi(availabilityZone.getParent().getId()).get()
.list().spliterator(), false)
.filter(host -> host.getService().equals("compute")).filter(
host -> host.getZone().equals(
RegionAndId.fromSlashEncoded(availabilityZone.getId()).getId()))
.collect(Collectors.toList()));
}
} catch (AuthorizationException ignored) {
//if we are not allowed to retrieve the hosts, we ignore them
}
return hosts.stream().map(host -> new HostToJCloudsLocationConverter().apply(host))
.collect(Collectors.toSet());
}
示例3: provideRegionAndNameToImageSupplierCacheLoader
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
@Provides
@Singleton
protected Supplier<CacheLoader<RegionAndName, Image>> provideRegionAndNameToImageSupplierCacheLoader(
final RegionAndIdToImage delegate) {
return Suppliers.<CacheLoader<RegionAndName, Image>>ofInstance(new CacheLoader<RegionAndName, Image>() {
private final AtomicReference<AuthorizationException> authException = Atomics.newReference();
@Override
public Image load(final RegionAndName key) throws Exception {
// raw lookup of an image
Supplier<Image> rawSupplier = new Supplier<Image>() {
@Override public Image get() {
try {
return delegate.load(key);
} catch (ExecutionException e) {
throw Throwables.propagate(e);
}
}
};
return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get();
}
});
}
示例4: testCacheLoaderDoesNotReloadAfterAuthorizationException
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
@Test
public void testCacheLoaderDoesNotReloadAfterAuthorizationException() throws Exception {
AWSEC2ComputeServiceContextModule module = new AWSEC2ComputeServiceContextModule() {
public Supplier<CacheLoader<RegionAndName, Image>> provideRegionAndNameToImageSupplierCacheLoader(RegionAndIdToImage delegate) {
return super.provideRegionAndNameToImageSupplierCacheLoader(delegate);
}
};
RegionAndName regionAndName = new RegionAndName("myregion", "myname");
AuthorizationException authException = new AuthorizationException();
RegionAndIdToImage mockRegionAndIdToImage = createMock(RegionAndIdToImage.class);
expect(mockRegionAndIdToImage.load(regionAndName)).andThrow(authException).once();
replay(mockRegionAndIdToImage);
CacheLoader<RegionAndName, Image> cacheLoader = module.provideRegionAndNameToImageSupplierCacheLoader(mockRegionAndIdToImage).get();
for (int i = 0; i < 2; i++) {
try {
Image image = cacheLoader.load(regionAndName);
fail("Expected Authorization exception, but got " + image);
} catch (AuthorizationException e) {
// success
}
}
}
示例5: getOrganisationIdForAccount
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
@Provides
@Singleton
@Memoized
public final Supplier<String> getOrganisationIdForAccount(
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, DimensionDataCloudControllerApi api) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
new OrganisationIdForAccount(api), seconds, TimeUnit.SECONDS);
}
开发者ID:cloudsoft,项目名称:amp-dimensiondata,代码行数:9,代码来源:DimensionDataCloudControllerComputeServiceContextModule.java
示例6: testListImages
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
@Ignore
@Test
public void testListImages() throws Exception {
List<NFVImage> images = openstackClient.listImages(vimInstance);
assertEqualsImages(definedImage, images.get(0));
//throw exception
GlanceApi glanceApi = mock(GlanceApi.class);
PowerMockito.spy(ContextBuilder.class);
ContextBuilder contextBuilder = mock(ContextBuilder.class);
PowerMockito.doReturn(contextBuilder)
.when(ContextBuilder.class, "newBuilder", Mockito.anyString());
when(contextBuilder.endpoint(anyString())).thenReturn(contextBuilder);
when(contextBuilder.credentials(anyString(), anyString())).thenReturn(contextBuilder);
when(contextBuilder.modules(any(Iterable.class))).thenReturn(contextBuilder);
when(contextBuilder.overrides(any(Properties.class))).thenReturn(contextBuilder);
when(contextBuilder.buildApi(GlanceApi.class)).thenReturn(glanceApi);
ImageApi imageApi = mock(ImageApi.class);
when(glanceApi.getImageApi(anyString())).thenReturn(imageApi);
when(imageApi.listInDetail()).thenReturn(mock(PagedIterable.class));
when(imageApi.listInDetail(any(ListImageOptions.class)))
.thenReturn(mock(PaginatedCollection.class));
when(imageApi.listInDetail().concat()).thenThrow(new AuthorizationException());
when(imageApi.listInDetail(any(ListImageOptions.class)).toList())
.thenThrow(new AuthorizationException());
exception.expect(VimDriverException.class);
images = openstackClient.listImages(vimInstance);
}
示例7: testCreateNetwork
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
@Test
public void testCreateNetwork() throws VimDriverException {
Network network = openstackClient.createNetwork(vimInstance, definedNetwork);
assertEqualsNetworks(definedNetwork, network);
when(org.jclouds.openstack.neutron.v2.domain.Network.CreateNetwork.class)
.thenThrow(new AuthorizationException());
//exception.expect(VimDriverException.class);
openstackClient.createNetwork(vimInstance, definedNetwork);
}
示例8: validateCredentials
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
public static NovaContext validateCredentials(NovaCredentials novaCredentials, ContextBuilder builder)
throws InvalidNovaCredentialsException {
try {
NovaContext context = new NovaContext(novaCredentials, builder);
SecurityGroupApi securityGroupApi = context.getSecurityGroupApi();
securityGroupApi.list();
return context;
} catch (AuthorizationException e) {
throw new InvalidNovaCredentialsException("account-name:" + novaCredentials.getAccountName(), e);
}
}
示例9: validateCredentials
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
/**
*
* @param credentials
* @return
* @throws InvalidCredentialsException
*/
public static GceContext validateCredentials(Credentials credentials) throws InvalidCredentialsException {
try {
GceContext context = new GceContext(credentials);
GoogleComputeEngineApi gceApi = context.getGceApi();
String projectName = gceApi.project().get().name();
context.setProjectName(projectName);
logger.info(String.format("Sucessfully Authenticated to project %s", projectName));
return context;
} catch (AuthorizationException e) {
throw new InvalidCredentialsException("accountid:" + credentials.identity, e);
}
}
示例10: validateCredentials
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
public static Ec2Context validateCredentials(Ec2Credentials credentials) throws InvalidEc2CredentialsException {
try {
if (credentials.getAccessKey().isEmpty() || credentials.getSecretKey().isEmpty()) {
throw new InvalidEc2CredentialsException("Ec2 credentials empty - not entered yet.");
}
Ec2Context cxt = new Ec2Context(credentials);
SecurityGroupApi securityGroupApi = cxt.getSecurityGroupApi();
securityGroupApi.describeSecurityGroupsInRegion(Settings.AWS_REGION_CODE_DEFAULT);
return cxt;
} catch (AuthorizationException e) {
throw new InvalidEc2CredentialsException(e.getMessage() + " - accountid:" + credentials.getAccessKey(), e);
}
}
示例11: validateCredentials
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
private Ec2Context validateCredentials(Ec2Credentials credentials) throws InvalidEc2CredentialsException {
try {
Ec2Context cxt = new Ec2Context(credentials);
SecurityGroupApi securityGroupApi = cxt.getSecurityGroupApi();
securityGroupApi.describeSecurityGroupsInRegion(Settings.PROVIDER_EC2_DEFAULT_REGION);
return cxt;
} catch (AuthorizationException e) {
throw new InvalidEc2CredentialsException("accountid:" + credentials.getAccessKey(), e);
}
}
示例12: supplyNonParsingImageCache
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
@Override
protected Supplier<Set<? extends Image>> supplyNonParsingImageCache(
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Set<? extends Image>> imageSupplier, Injector injector) {
final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key
.get(new TypeLiteral<Supplier<LoadingCache<RegionAndName, ? extends Image>>>() {
}));
return new Supplier<Set<? extends Image>>() {
@Override
public Set<? extends Image> get() {
return ImmutableSet.copyOf(cache.get().asMap().values());
}
};
}
示例13: validateNovaCredentialsTestException
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
@Test(expected = InvalidNovaCredentialsException.class)
public void validateNovaCredentialsTestException() throws InvalidNovaCredentialsException {
when(securityGroupApi.list()).thenThrow(AuthorizationException.class);
NovaContext context = NovaLauncher.validateCredentials(novaCredentials, builder);
}
示例14: handleContainerCreate
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
private static void handleContainerCreate(HttpServletRequest request,
HttpServletResponse response, InputStream is, BlobStore blobStore,
String containerName) throws IOException, S3Exception {
if (containerName.isEmpty()) {
throw new S3Exception(S3ErrorCode.METHOD_NOT_ALLOWED);
}
String contentLengthString = request.getHeader(
HttpHeaders.CONTENT_LENGTH);
if (contentLengthString != null) {
long contentLength;
try {
contentLength = Long.parseLong(contentLengthString);
} catch (NumberFormatException nfe) {
throw new S3Exception(S3ErrorCode.INVALID_ARGUMENT, nfe);
}
if (contentLength < 0) {
throw new S3Exception(S3ErrorCode.INVALID_ARGUMENT);
}
}
String locationString;
try (PushbackInputStream pis = new PushbackInputStream(is)) {
int ch = pis.read();
if (ch == -1) {
// handle empty bodies
locationString = null;
} else {
pis.unread(ch);
CreateBucketRequest cbr = new XmlMapper().readValue(
pis, CreateBucketRequest.class);
locationString = cbr.locationConstraint;
}
}
Location location = null;
if (locationString != null) {
for (Location loc : blobStore.listAssignableLocations()) {
if (loc.getId().equalsIgnoreCase(locationString)) {
location = loc;
break;
}
}
if (location == null) {
throw new S3Exception(S3ErrorCode.INVALID_LOCATION_CONSTRAINT);
}
}
logger.debug("Creating bucket with location: {}", location);
CreateContainerOptions options = new CreateContainerOptions();
String acl = request.getHeader("x-amz-acl");
if ("public-read".equalsIgnoreCase(acl)) {
options.publicRead();
}
boolean created;
try {
created = blobStore.createContainerInLocation(location,
containerName, options);
} catch (AuthorizationException ae) {
if (ae.getCause() instanceof AccessDeniedException) {
throw new S3Exception(S3ErrorCode.ACCESS_DENIED,
"Could not create bucket", ae);
}
throw new S3Exception(S3ErrorCode.BUCKET_ALREADY_EXISTS, ae);
}
if (!created) {
throw new S3Exception(S3ErrorCode.BUCKET_ALREADY_OWNED_BY_YOU,
S3ErrorCode.BUCKET_ALREADY_OWNED_BY_YOU.getMessage(),
null, ImmutableMap.of("BucketName", containerName));
}
response.addHeader(HttpHeaders.LOCATION, "/" + containerName);
}
示例15: cloudLogin
import org.jclouds.rest.AuthorizationException; //导入依赖的package包/类
public String cloudLogin() throws AuthorizationException, NoSuchElementException;