Skip to content
Open
Changes from 1 commit
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 Down Expand Up @@ -116,6 +122,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 @@ -182,6 +190,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 +301,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.GET);
Comment thread
adilburaksen marked this conversation as resolved.
Outdated
OAuthProvider oauthProvider = getProvider(provider);
Optional<OAuthAccessToken> oAuthAccessToken = getAccessToken(provider, credentialId);

Expand Down