本文整理汇总了Java中org.apache.http.HttpStatus.SC_FORBIDDEN属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus.SC_FORBIDDEN属性的具体用法?Java HttpStatus.SC_FORBIDDEN怎么用?Java HttpStatus.SC_FORBIDDEN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.http.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.SC_FORBIDDEN属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendConnectionErrorMessage
public static void sendConnectionErrorMessage(IDiscordClient client, IChannel channel, String command, @Nullable String message, @NotNull HttpStatusException httpe) throws RateLimitException, DiscordException, MissingPermissionsException {
@NotNull String problem = message != null ? message + "\n" : "";
if (httpe.getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
problem += "Service unavailable, please try again latter.";
} else if (httpe.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
problem += "Acess dennied.";
} else if (httpe.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
problem += "Not Found";
} else {
problem += httpe.getStatusCode() + SPACE + httpe.getMessage();
}
new MessageBuilder(client)
.appendContent("Error during HTTP Connection ", MessageBuilder.Styles.BOLD)
.appendContent("\n")
.appendContent(EventManager.MAIN_COMMAND_NAME, MessageBuilder.Styles.BOLD)
.appendContent(SPACE)
.appendContent(command, MessageBuilder.Styles.BOLD)
.appendContent("\n")
.appendContent(problem, MessageBuilder.Styles.BOLD)
.withChannel(channel)
.send();
}
示例2: map
@Override
public BackgroundException map(final IOException failure) {
final StringBuilder buffer = new StringBuilder();
if(failure instanceof GoogleJsonResponseException) {
final GoogleJsonResponseException error = (GoogleJsonResponseException) failure;
this.append(buffer, error.getDetails().getMessage());
switch(error.getDetails().getCode()) {
case HttpStatus.SC_FORBIDDEN:
final List<GoogleJsonError.ErrorInfo> errors = error.getDetails().getErrors();
for(GoogleJsonError.ErrorInfo info : errors) {
if("usageLimits".equals(info.getDomain())) {
return new RetriableAccessDeniedException(buffer.toString(), Duration.ofSeconds(5), failure);
}
}
break;
}
}
if(failure instanceof HttpResponseException) {
final HttpResponseException response = (HttpResponseException) failure;
this.append(buffer, response.getStatusMessage());
return new HttpResponseExceptionMappingService().map(new org.apache.http.client
.HttpResponseException(response.getStatusCode(), buffer.toString()));
}
return super.map(failure);
}
示例3: isFileExisting
/**
* A method that returns true if a correct s3 URI was provided and false otherwise.
*
* @param uri The provided URI for the file.
* @return a boolean value that shows whether the correct URI was provided
*/
boolean isFileExisting(AmazonS3URI uri) {
boolean exist = true;
try {
aws.getObjectMetadata(uri.getBucket(), uri.getKey());
} catch (AmazonS3Exception e) {
if (e.getStatusCode() == HttpStatus.SC_FORBIDDEN
|| e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
exist = false;
} else {
throw e;
}
}
return exist;
}
示例4: checkBatchResponseBody
/**
* 不正な認証情報を使用してすべてのユーザがread可能なコレクションに対して$batchをした場合処理が受付けられること.
* batchの実行順
* 1.POST(登録)
* 2.GET(一覧取得)
* 3.GET(取得)
* 4.PUT(更新)
* 5.DELETE(削除)
*/
@Test
public final void 不正な認証情報を使用してすべてのユーザがread可能なコレクションに対して$batchをした場合処理が受付けられること() {
// 認証トークン取得
String invalidToken = "invalid token";
// ACL設定
String path = String.format("%s/%s/%s", TEST_CELL1, BOX_NAME, COL_NAME);
DavResourceUtils.setACLPrincipalAll(TEST_CELL1, MASTER_TOKEN, HttpStatus.SC_OK,
path, "<D:read />", "");
// READ→OK WRITE→403
TResponse res = UserDataUtils.batch(TEST_CELL1, BOX_NAME, COL_NAME, BOUNDARY, TEST_BODY,
invalidToken, HttpStatus.SC_ACCEPTED);
// 期待するレスポンスコード
int[] expectedCodes = new int[] {HttpStatus.SC_FORBIDDEN,
HttpStatus.SC_OK,
HttpStatus.SC_NOT_FOUND,
HttpStatus.SC_FORBIDDEN,
HttpStatus.SC_FORBIDDEN };
// レスポンスボディのチェック(ステータス)
checkBatchResponseBody(res, expectedCodes);
}
示例5: map
@Override
public BackgroundException map(final FailedRequestException e) {
final StringBuilder buffer = new StringBuilder();
if(null != e.getError()) {
this.append(buffer, e.getError().getMessage());
}
switch(e.getStatusCode()) {
case HttpStatus.SC_FORBIDDEN:
if(null != e.getError()) {
if(StringUtils.isNotBlank(e.getError().getCode())) {
switch(e.getError().getCode()) {
case "SignatureDoesNotMatch":
return new LoginFailureException(buffer.toString(), e);
case "InvalidAccessKeyId":
return new LoginFailureException(buffer.toString(), e);
case "InvalidClientTokenId":
return new LoginFailureException(buffer.toString(), e);
case "InvalidSecurity":
return new LoginFailureException(buffer.toString(), e);
case "MissingClientTokenId":
return new LoginFailureException(buffer.toString(), e);
case "MissingAuthenticationToken":
return new LoginFailureException(buffer.toString(), e);
}
}
}
}
if(e.getCause() instanceof IOException) {
return new DefaultIOExceptionMappingService().map((IOException) e.getCause());
}
return new HttpResponseExceptionMappingService().map(new HttpResponseException(e.getStatusCode(), buffer.toString()));
}
示例6: map
@Override
public BackgroundException map(final AmazonClientException e) {
final StringBuilder buffer = new StringBuilder();
if(e instanceof AmazonServiceException) {
final AmazonServiceException failure = (AmazonServiceException) e;
this.append(buffer, failure.getErrorMessage());
switch(failure.getStatusCode()) {
case HttpStatus.SC_BAD_REQUEST:
switch(failure.getErrorCode()) {
case "Throttling":
return new RetriableAccessDeniedException(buffer.toString(), e);
case "AccessDeniedException":
return new AccessDeniedException(buffer.toString(), e);
case "UnrecognizedClientException":
return new LoginFailureException(buffer.toString(), e);
}
case HttpStatus.SC_FORBIDDEN:
switch(failure.getErrorCode()) {
case "SignatureDoesNotMatch":
return new LoginFailureException(buffer.toString(), e);
case "InvalidAccessKeyId":
return new LoginFailureException(buffer.toString(), e);
case "InvalidClientTokenId":
return new LoginFailureException(buffer.toString(), e);
case "InvalidSecurity":
return new LoginFailureException(buffer.toString(), e);
case "MissingClientTokenId":
return new LoginFailureException(buffer.toString(), e);
case "MissingAuthenticationToken":
return new LoginFailureException(buffer.toString(), e);
}
}
return new HttpResponseExceptionMappingService().map(new HttpResponseException(failure.getStatusCode(), buffer.toString()));
}
this.append(buffer, e.getMessage());
return this.wrap(e, buffer);
}
示例7: map
public BackgroundException map(final Throwable failure, final StringBuilder buffer, final int statusCode) {
switch(statusCode) {
case HttpStatus.SC_UNAUTHORIZED:
return new LoginFailureException(buffer.toString(), failure);
case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
return new ProxyLoginFailureException(buffer.toString(), failure);
case HttpStatus.SC_FORBIDDEN:
case HttpStatus.SC_NOT_ACCEPTABLE:
return new AccessDeniedException(buffer.toString(), failure);
case HttpStatus.SC_CONFLICT:
return new ConflictException(buffer.toString(), failure);
case HttpStatus.SC_NOT_FOUND:
case HttpStatus.SC_GONE:
case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE:
return new NotfoundException(buffer.toString(), failure);
case HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE:
case HttpStatus.SC_INSUFFICIENT_STORAGE:
case HttpStatus.SC_PAYMENT_REQUIRED:
return new QuotaException(buffer.toString(), failure);
case HttpStatus.SC_UNPROCESSABLE_ENTITY:
case HttpStatus.SC_BAD_REQUEST:
case HttpStatus.SC_REQUEST_URI_TOO_LONG:
case HttpStatus.SC_METHOD_NOT_ALLOWED:
case HttpStatus.SC_NOT_IMPLEMENTED:
return new InteroperabilityException(buffer.toString(), failure);
case HttpStatus.SC_REQUEST_TIMEOUT:
case HttpStatus.SC_GATEWAY_TIMEOUT:
case HttpStatus.SC_BAD_GATEWAY:
return new ConnectionTimeoutException(buffer.toString(), failure);
case HttpStatus.SC_INTERNAL_SERVER_ERROR:
case HttpStatus.SC_SERVICE_UNAVAILABLE:
case 429:
// Too Many Requests. Rate limiting
case 509:
// Bandwidth Limit Exceeded
return new RetriableAccessDeniedException(buffer.toString(), failure);
default:
return new InteroperabilityException(buffer.toString(), failure);
}
}
示例8: handleResponse
@Override
public AuthenticationResponse handleResponse(final HttpResponse response) throws IOException {
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
Charset charset = HTTP.DEF_CONTENT_CHARSET;
ContentType contentType = ContentType.get(response.getEntity());
if(contentType != null) {
if(contentType.getCharset() != null) {
charset = contentType.getCharset();
}
}
try {
final JsonParser parser = new JsonParser();
final JsonObject json = parser.parse(new InputStreamReader(response.getEntity().getContent(), charset)).getAsJsonObject();
final String token = json.getAsJsonPrimitive("token").getAsString();
final String endpoint = json.getAsJsonPrimitive("endpoint").getAsString();
return new AuthenticationResponse(response, token,
Collections.singleton(new Region(null, URI.create(endpoint), null, true)));
}
catch(JsonParseException e) {
throw new IOException(e.getMessage(), e);
}
}
else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED
|| response.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN) {
throw new AuthorizationException(new Response(response));
}
throw new GenericException(new Response(response));
}
示例9: testComponentPermission
private Pair<Boolean, String> testComponentPermission(Xray xrayClient) throws IOException {
try {
Components testComponent = new ComponentsImpl();
testComponent.addComponent("testComponent", "");
xrayClient.summary().component(testComponent);
} catch (HttpResponseException e) {
switch (e.getStatusCode()) {
case HttpStatus.SC_UNAUTHORIZED:
return Pair.of(false, e.getMessage() + ". Please check your credentials.");
case HttpStatus.SC_FORBIDDEN:
return Pair.of(false, e.getMessage() + ". Please make sure that the user has 'View Components' permission in Xray.");
}
}
return Pair.of(true, "");
}
示例10: map
@Override
public BackgroundException map(final B2ApiException e) {
final StringBuilder buffer = new StringBuilder();
this.append(buffer, e.getMessage());
switch(e.getStatus()) {
case HttpStatus.SC_FORBIDDEN:
if("cap_exceeded".equalsIgnoreCase(e.getCode())
|| "storage_cap_exceeded".equalsIgnoreCase(e.getCode())
|| "transaction_cap_exceeded".equalsIgnoreCase(e.getCode())) {// Reached the storage cap that you set
return new QuotaException(buffer.toString(), e);
}
break;
case HttpStatus.SC_BAD_REQUEST:
if("file_not_present".equalsIgnoreCase(e.getCode())) {
return new NotfoundException(buffer.toString(), e);
}
if("bad_bucket_id".equalsIgnoreCase(e.getCode())) {
return new NotfoundException(buffer.toString(), e);
}
if("cap_exceeded".equalsIgnoreCase(e.getCode())) {// Reached the storage cap that you set
return new QuotaException(buffer.toString(), e);
}
if("too_many_buckets".equalsIgnoreCase(e.getCode())) {// Reached the storage cap that you set
return new QuotaException(buffer.toString(), e);
}
if("bad_request".equalsIgnoreCase(e.getCode())) {
if("sha1 did not match data received".equalsIgnoreCase(e.getMessage())) {
return new ChecksumException(buffer.toString(), e);
}
}
break;
case HttpStatus.SC_UNAUTHORIZED:
if("expired_auth_token".equalsIgnoreCase(e.getCode())) {
return new ExpiredTokenException(buffer.toString(), e);
}
break;
default:
if(e.getRetry() != null) {
// Too Many Requests (429)
return new RetriableAccessDeniedException(buffer.toString(), Duration.ofSeconds(e.getRetry()), e);
}
break;
}
return new HttpResponseExceptionMappingService().map(new HttpResponseException(e.getStatus(), buffer.toString()));
}
示例11: map
@Override
public BackgroundException map(final ServiceException e) {
if(e.getCause() instanceof ServiceException) {
return this.map((ServiceException) e.getCause());
}
final StringBuilder buffer = new StringBuilder();
if(StringUtils.isNotBlank(e.getErrorMessage())) {
// S3 protocol message parsed from XML
this.append(buffer, StringEscapeUtils.unescapeXml(e.getErrorMessage()));
}
else {
this.append(buffer, e.getResponseStatus());
this.append(buffer, e.getMessage());
}
switch(e.getResponseCode()) {
case HttpStatus.SC_FORBIDDEN:
if(StringUtils.isNotBlank(e.getErrorCode())) {
switch(e.getErrorCode()) {
case "SignatureDoesNotMatch":
case "InvalidAccessKeyId":
case "InvalidClientTokenId":
case "InvalidSecurity":
case "MissingClientTokenId":
case "MissingAuthenticationToken":
return new LoginFailureException(buffer.toString(), e);
}
}
case HttpStatus.SC_BAD_REQUEST:
if(StringUtils.isNotBlank(e.getErrorCode())) {
switch(e.getErrorCode()) {
case "RequestTimeout":
return new ConnectionTimeoutException(buffer.toString(), e);
}
}
}
if(e.getCause() instanceof IOException) {
return new DefaultIOExceptionMappingService().map((IOException) e.getCause());
}
if(e.getCause() instanceof SAXException) {
return new InteroperabilityException(buffer.toString(), e);
}
return new HttpResponseExceptionMappingService().map(new HttpResponseException(e.getResponseCode(), buffer.toString()));
}
示例12: NotAllowedException
public NotAllowedException(String s) {
super(HttpStatus.SC_FORBIDDEN, "M_FORBIDDEN", s);
}
示例13: accountAuth
/**
* Boxレベル$batchでのACLアクセス制御の確認.
* batchの実行順
* 1.POST(登録)
* 2.GET(一覧取得)
* 3.GET(取得)
* 4.PUT(更新)
* 5.DELETE(削除)
*/
@Test
public final void 正しい認証情報を使用して権限が無いコレクションに対して$batchをした場合403エラーとなること() {
// 認証トークン取得
String[] tokens = accountAuth();
// ACL設定
DavResourceUtils.setACL(TEST_CELL1, MASTER_TOKEN, HttpStatus.SC_OK, COL_NAME, ACL_AUTH_TEST_FILE, BOX_NAME, "");
// Privilege設定なし→$batchリクエストが403
TResponse res1 = UserDataUtils.batch(TEST_CELL1, BOX_NAME, COL_NAME, BOUNDARY, TEST_BODY,
tokens[NO_PRIVILEGE], HttpStatus.SC_FORBIDDEN);
AuthTestCommon.checkAuthenticateHeaderNotExists(res1);
// READのみ→POST/PUT/DELETEが403
// READの確認のため1件登録
String body2 = START_BOUNDARY + retrievePostBody("Supplier", "testAutuBatch1")
+ END_BOUNDARY;
UserDataUtils.batch(TEST_CELL1, BOX_NAME, COL_NAME, BOUNDARY, body2, MASTER_TOKEN, -1);
TResponse res2 = UserDataUtils.batch(TEST_CELL1, BOX_NAME, COL_NAME, BOUNDARY, TEST_BODY,
tokens[READ], -1);
// 期待するレスポンスコード
int[] expectedCodes2 = new int[] {HttpStatus.SC_FORBIDDEN,
HttpStatus.SC_OK,
HttpStatus.SC_OK,
HttpStatus.SC_FORBIDDEN,
HttpStatus.SC_FORBIDDEN };
// レスポンスボディのチェック(ステータス)
checkBatchResponseBody(res2, expectedCodes2);
// テスト用の1件削除
String body3 = START_BOUNDARY + retrieveDeleteBody("Supplier('testAutuBatch1')")
+ END_BOUNDARY;
UserDataUtils.batch(TEST_CELL1, BOX_NAME, COL_NAME, BOUNDARY, body3, MASTER_TOKEN, -1);
// WRITEのみ→GETが403
TResponse res3 = UserDataUtils.batch(TEST_CELL1, BOX_NAME, COL_NAME, BOUNDARY, TEST_BODY,
tokens[WRITE], HttpStatus.SC_ACCEPTED);
// 期待するレスポンスコード
int[] expectedCodes3 = new int[] {HttpStatus.SC_CREATED,
HttpStatus.SC_FORBIDDEN,
HttpStatus.SC_FORBIDDEN,
HttpStatus.SC_NO_CONTENT,
HttpStatus.SC_NO_CONTENT };
// レスポンスボディのチェック(ステータス)
checkBatchResponseBody(res3, expectedCodes3);
// $batchで受け付けない権限のみ→$batchリクエストが403
TResponse res4 = UserDataUtils.batch(TEST_CELL1, BOX_NAME, COL_NAME, BOUNDARY, TEST_BODY,
tokens[EXEC], HttpStatus.SC_FORBIDDEN);
AuthTestCommon.checkAuthenticateHeaderNotExists(res4);
}