@Override public OAuthConfig forRequest(HttpRequest input) { return OAuthConfig.create(scopes.forRequest(input), audience, resource); } }
@Override public OAuthConfig forRequest(HttpRequest input) { return OAuthConfig.create(scopes.forRequest(input), audience, resource); } }
@Override public HttpRequest filter(HttpRequest request) throws HttpException { List<String> configuredScopes = scopes.forRequest(request); ClientSecret client = ClientSecret.create( credentialsSupplier.get().identity, credentialsSupplier.get().credential, resource == null ? "" : resource, configuredScopes.isEmpty() ? null : ON_SPACE.join(configuredScopes) ); Token token = tokenCache.getUnchecked(client); String authorization = String.format("%s %s", token.tokenType(), token.accessToken()); return request.toBuilder().addHeader("Authorization", authorization).build(); } }
@Override public HttpRequest filter(HttpRequest request) throws HttpException { List<String> configuredScopes = scopes.forRequest(request); ClientSecret client = ClientSecret.create( credentialsSupplier.get().identity, credentialsSupplier.get().credential, resource == null ? "" : resource, configuredScopes.isEmpty() ? null : ON_SPACE.join(configuredScopes) ); Token token = tokenCache.getUnchecked(client); String authorization = String.format("%s %s", token.tokenType(), token.accessToken()); return request.toBuilder().addHeader("Authorization", authorization).build(); } }
/** If the path contains or ends with {@code /acl} or {@code /defaultObjectAcl}, it needs full-control. */ @Override public List<String> forRequest(HttpRequest input) { String path = input.getEndpoint().getPath(); if (path.endsWith("/acl") || path.endsWith("/defaultObjectAcl") // || path.contains("/acl/") || path.contains("/defaultObjectAcl/")) { return fullControlScopes(); } else if (input.getMethod().equalsIgnoreCase("PUT") || input.getMethod().equalsIgnoreCase("PATCH")) { return fullControlScopes(); } return readOrWriteScopes().forRequest(input); }
/** If the path contains or ends with {@code /acl} or {@code /defaultObjectAcl}, it needs full-control. */ @Override public List<String> forRequest(HttpRequest input) { String path = input.getEndpoint().getPath(); if (path.endsWith("/acl") || path.endsWith("/defaultObjectAcl") // || path.contains("/acl/") || path.contains("/defaultObjectAcl/")) { return fullControlScopes(); } else if (input.getMethod().equalsIgnoreCase("PUT") || input.getMethod().equalsIgnoreCase("PATCH")) { return fullControlScopes(); } return readOrWriteScopes().forRequest(input); }
/** If the path contains or ends with {@code /acl} or {@code /defaultObjectAcl}, it needs full-control. */ @Override public List<String> forRequest(HttpRequest input) { String path = input.getEndpoint().getPath(); if (path.endsWith("/acl") || path.endsWith("/defaultObjectAcl") // || path.contains("/acl/") || path.contains("/defaultObjectAcl/")) { return fullControlScopes(); } else if (input.getMethod().equalsIgnoreCase("PUT") || input.getMethod().equalsIgnoreCase("PATCH")) { return fullControlScopes(); } return readOrWriteScopes().forRequest(input); }
@Override public HttpRequest filter(HttpRequest request) throws HttpException { List<String> configuredScopes = scopes.forRequest(request); ClientCredentialsClaims claims = ClientCredentialsClaims.create( // credentialsSupplier.get().identity, // iss credentialsSupplier.get().identity, // sub audience, // aud -1, // placeholder exp for the cache -1, // placeholder nbf for the cache null // placeholder jti for the cache ); ClientCredentialsAuthArgs authArgs = ClientCredentialsAuthArgs.create( credentialsSupplier.get().identity, claims, resource == null ? "" : resource, configuredScopes.isEmpty() ? null : ON_SPACE.join(configuredScopes) ); Token token = tokenCache.getUnchecked(authArgs); String authorization = String.format("%s %s", token.tokenType(), token.accessToken()); return request.toBuilder().addHeader("Authorization", authorization).build(); } }
@Override public HttpRequest filter(HttpRequest request) throws HttpException { List<String> configuredScopes = scopes.forRequest(request); ClientCredentialsClaims claims = ClientCredentialsClaims.create( // credentialsSupplier.get().identity, // iss credentialsSupplier.get().identity, // sub audience, // aud -1, // placeholder exp for the cache -1, // placeholder nbf for the cache null // placeholder jti for the cache ); ClientCredentialsAuthArgs authArgs = ClientCredentialsAuthArgs.create( credentialsSupplier.get().identity, claims, resource == null ? "" : resource, configuredScopes.isEmpty() ? null : ON_SPACE.join(configuredScopes) ); Token token = tokenCache.getUnchecked(authArgs); String authorization = String.format("%s %s", token.tokenType(), token.accessToken()); return request.toBuilder().addHeader("Authorization", authorization).build(); } }
@Override public HttpRequest filter(HttpRequest request) throws HttpException { long now = currentTimeSeconds(); Claims claims = Claims.create( // credentialsSupplier.get().identity, // iss ON_COMMA.join(scopes.forRequest(request)), // scope audience, // aud -1, // placeholder exp for the cache -1 // placeholder iat for the cache ); final TokenCacheKey tokenCacheKey = TokenCacheKey.create(claims, now); Token token = tokenCache.getUnchecked(tokenCacheKey); String authorization = String.format("%s %s", token.tokenType(), token.accessToken()); return request.toBuilder().addHeader("Authorization", authorization).build(); }
@Override public HttpRequest filter(HttpRequest request) throws HttpException { long now = currentTimeSeconds(); Claims claims = Claims.create( // credentialsSupplier.get().identity, // iss ON_COMMA.join(scopes.forRequest(request)), // scope audience, // aud -1, // placeholder exp for the cache -1 // placeholder iat for the cache ); final TokenCacheKey tokenCacheKey = TokenCacheKey.create(claims, now); Token token = tokenCache.getUnchecked(tokenCacheKey); String authorization = String.format("%s %s", token.tokenType(), token.accessToken()); return request.toBuilder().addHeader("Authorization", authorization).build(); }
@Override public OAuthConfig forRequest(HttpRequest input) { OAuthResource customResource = null; if (input instanceof GeneratedHttpRequest) { GeneratedHttpRequest request = (GeneratedHttpRequest) input; customResource = request.getInvocation().getInvokable().getAnnotation(OAuthResource.class); if (customResource == null) { customResource = request.getInvocation().getInvokable().getDeclaringClass() .getAnnotation(OAuthResource.class); } } String oauthResource = customResource == null ? resource : (isChinaEndpoint ? customResource.chinaEndpoint() : customResource.value()); return OAuthConfig.create(scopes.forRequest(input), audience, oauthResource); } }