forked from finos/legend-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple authorizer from relational store
- Loading branch information
Showing
6 changed files
with
169 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...engine/plan/execution/authorization/AbstractMiddleTierConnectionCredentialAuthorizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2023 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.finos.legend.engine.plan.execution.authorization; | ||
|
||
import org.finos.legend.engine.shared.core.identity.Identity; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class AbstractMiddleTierConnectionCredentialAuthorizer implements MiddleTierConnectionCredentialAuthorizer | ||
{ | ||
@Override | ||
public CredentialAuthorization evaluate(Identity subject, String credentialVaultReference, PlanExecutionAuthorizerInput.ExecutionMode usageContext, String resourceContext, String policyContext) throws Exception | ||
{ | ||
return this.evaluateImpl(subject, credentialVaultReference, usageContext, resourceContext, policyContext); | ||
} | ||
|
||
public abstract CredentialAuthorization evaluateImpl(Identity subject, String credentialVaultReference, PlanExecutionAuthorizerInput.ExecutionMode usageContext, String resourceContext, String policyContext) throws Exception; | ||
} |
109 changes: 109 additions & 0 deletions
109
.../legend/engine/plan/execution/authorization/MiddleTierConnectionCredentialAuthorizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright 2023 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.finos.legend.engine.plan.execution.authorization; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.eclipse.collections.api.list.ImmutableList; | ||
import org.finos.legend.engine.shared.core.identity.Identity; | ||
|
||
public interface MiddleTierConnectionCredentialAuthorizer | ||
{ | ||
/* | ||
Is 'Alice' allowed to use 'credref1' for interactive development ? | ||
Is 'Alice' allowed to use 'credref1' during a service execution ? | ||
*/ | ||
CredentialAuthorization evaluate(Identity currentUser, String credentialVaultReference, PlanExecutionAuthorizerInput.ExecutionMode usageContext, String resourceContext, String policyContext) throws Exception; | ||
|
||
@JsonPropertyOrder({"status","summary","subject","vaultReference","details"}) | ||
class CredentialAuthorization | ||
{ | ||
public enum Status | ||
{ | ||
ALLOW, | ||
DENY | ||
} | ||
|
||
private Status status; | ||
|
||
private String subject; | ||
|
||
private String vaultReference; | ||
|
||
// details are expected to be JSON serializable | ||
private ImmutableList<Object> details; | ||
|
||
public CredentialAuthorization(String subject, String vaultReference, Status status, ImmutableList<Object> details) | ||
{ | ||
this.subject = subject; | ||
this.vaultReference = vaultReference; | ||
this.status = status; | ||
this.details = details; | ||
} | ||
|
||
public static CredentialAuthorization allow(String subject, String vaultReference, ImmutableList<Object> details) | ||
{ | ||
return new CredentialAuthorization(subject, vaultReference, Status.ALLOW, details); | ||
} | ||
|
||
public static CredentialAuthorization deny(String subject, String vaultReference, ImmutableList<Object> details) | ||
{ | ||
return new CredentialAuthorization(subject, vaultReference, Status.DENY, details); | ||
} | ||
|
||
public Status getStatus() | ||
{ | ||
return status; | ||
} | ||
|
||
@JsonIgnore | ||
public boolean isAllowed() | ||
{ | ||
return this.status.equals(Status.ALLOW); | ||
} | ||
|
||
@JsonIgnore | ||
public boolean isDenied() | ||
{ | ||
return !this.isAllowed(); | ||
} | ||
|
||
public ImmutableList<Object> getDetails() | ||
{ | ||
return details; | ||
} | ||
|
||
public String getSubject() | ||
{ | ||
return subject; | ||
} | ||
|
||
public String getVaultReference() | ||
{ | ||
return vaultReference; | ||
} | ||
|
||
public Object toJSON() throws Exception | ||
{ | ||
return new ObjectMapper().writeValueAsString(this); | ||
} | ||
|
||
public Object toPrettyJSON() throws Exception | ||
{ | ||
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters