Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
import io.cdap.cdap.datapipeline.oauth.PutOAuthCredentialRequest;
import io.cdap.cdap.datapipeline.oauth.PutOAuthProviderRequest;
import io.cdap.cdap.datapipeline.oauth.RefreshTokenResponse;
import io.cdap.cdap.proto.element.EntityType;
Comment thread
adilburaksen marked this conversation as resolved.
import io.cdap.cdap.proto.id.NamespaceId;
import io.cdap.cdap.proto.security.StandardPermission;
import io.cdap.cdap.security.spi.authorization.ContextAccessEnforcer;
import io.cdap.common.http.HttpRequest;
import io.cdap.common.http.HttpRequests;
import io.cdap.common.http.HttpResponse;
Expand Down Expand Up @@ -71,11 +75,13 @@ public class OAuthHandler extends AbstractSystemHttpServiceHandler {
.create();

private OAuthStore oauthStore;
private ContextAccessEnforcer contextAccessEnforcer;

@Override
public void initialize(SystemHttpServiceContext context) throws Exception {
super.initialize(context);
this.oauthStore = new OAuthStore(context, context, context.getAdmin());
this.contextAccessEnforcer = context.getContextAccessEnforcer();
Comment thread
adilburaksen marked this conversation as resolved.
}

@GET
Expand All @@ -85,6 +91,8 @@ public void getAuthURL(HttpServiceRequest request, HttpServiceResponder responde
@QueryParam("redirect_uri") String redirectURI,
@QueryParam("redirect_url") String redirectURL) {
try {
contextAccessEnforcer.enforceOnParent(EntityType.SYSTEM_APP_ENTITY, NamespaceId.SYSTEM,
StandardPermission.LIST);
OAuthProvider oauthProvider = getProvider(provider);

String formatURL = "%s";
Expand Down Expand Up @@ -116,6 +124,8 @@ public void putOAuthProvider(HttpServiceRequest request, HttpServiceResponder re
@QueryParam("reuse_client_credentials") @DefaultValue("false")
Boolean reuseClientCredentials) {
try {
contextAccessEnforcer.enforceOnParent(EntityType.SYSTEM_APP_ENTITY, NamespaceId.SYSTEM,
StandardPermission.CREATE);
Comment thread
adilburaksen marked this conversation as resolved.
try {
PutOAuthProviderRequest putOAuthProviderRequest = GSON.fromJson(
StandardCharsets.UTF_8.decode(request.getContent()).toString(),
Expand Down Expand Up @@ -163,6 +173,8 @@ public void putOAuthProvider(HttpServiceRequest request, HttpServiceResponder re
public void deleteOAuthProvider(HttpServiceRequest request, HttpServiceResponder responder,
@PathParam("provider") String oauthProvider) {
try {
contextAccessEnforcer.enforceOnParent(EntityType.SYSTEM_APP_ENTITY, NamespaceId.SYSTEM,
StandardPermission.DELETE);
try {
oauthStore.deleteProvider(oauthProvider);
responder.sendStatus(HttpURLConnection.HTTP_OK);
Expand All @@ -182,6 +194,8 @@ public void putOAuthCredential(HttpServiceRequest request, HttpServiceResponder
@PathParam("provider") String provider,
@PathParam("credential") String credentialId) {
try {
contextAccessEnforcer.enforceOnParent(EntityType.SYSTEM_APP_ENTITY, NamespaceId.SYSTEM,
StandardPermission.CREATE);
Comment thread
adilburaksen marked this conversation as resolved.
PutOAuthCredentialRequest putOAuthCredentialRequest;
try {
putOAuthCredentialRequest = GSON.fromJson(StandardCharsets.UTF_8.decode(request.getContent()).toString(),
Expand Down Expand Up @@ -291,6 +305,8 @@ public void getOAuthCredential(HttpServiceRequest request, HttpServiceResponder
@PathParam("provider") String provider,
@PathParam("credential") String credentialId) {
try {
contextAccessEnforcer.enforceOnParent(EntityType.SYSTEM_APP_ENTITY, NamespaceId.SYSTEM,
StandardPermission.LIST);
OAuthProvider oauthProvider = getProvider(provider);
Optional<OAuthAccessToken> oAuthAccessToken = getAccessToken(provider, credentialId);

Expand Down Expand Up @@ -371,6 +387,8 @@ public void getOAuthCredentialValidity(HttpServiceRequest request, HttpServiceRe
@PathParam("provider") String provider,
@PathParam("credential") String credentialId) {
try {
contextAccessEnforcer.enforceOnParent(EntityType.SYSTEM_APP_ENTITY, NamespaceId.SYSTEM,
StandardPermission.LIST);
OAuthProvider oauthProvider = getProvider(provider);
Optional<OAuthAccessToken> oAuthAccessToken = getAccessToken(provider, credentialId);

Expand Down
Loading