use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class DefaultAccessEnforcerTest method testAuthEnforceWithEncryptedCredential.
@Test
public void testAuthEnforceWithEncryptedCredential() throws IOException, AccessException, CipherException, GeneralSecurityException {
SConfiguration sConfCopy = enableCredentialEncryption();
TinkCipher cipher = new TinkCipher(sConfCopy);
String cred = cipher.encryptToBase64("credential".getBytes(StandardCharsets.UTF_8), null);
Principal userWithCredEncrypted = new Principal("userFoo", Principal.PrincipalType.USER, null, new Credential(cred, Credential.CredentialType.EXTERNAL_ENCRYPTED));
ControllerWrapper controllerWrapper = createControllerWrapper(CCONF, sConfCopy, null);
AccessController accessController = controllerWrapper.accessController;
DefaultAccessEnforcer accessEnforcer = controllerWrapper.defaultAccessEnforcer;
assertAuthorizationFailure(accessEnforcer, NS, userWithCredEncrypted, StandardPermission.UPDATE);
accessController.grant(Authorizable.fromEntityId(NS), userWithCredEncrypted, ImmutableSet.of(StandardPermission.GET, StandardPermission.UPDATE));
accessEnforcer.enforce(NS, userWithCredEncrypted, StandardPermission.GET);
accessEnforcer.enforce(NS, userWithCredEncrypted, StandardPermission.UPDATE);
// Verify the metrics context was called with correct metrics
verify(controllerWrapper.mockMetricsContext, times(2)).increment(Constants.Metrics.Authorization.EXTENSION_CHECK_SUCCESS_COUNT, 1);
verify(controllerWrapper.mockMetricsContext, times(1)).increment(Constants.Metrics.Authorization.EXTENSION_CHECK_FAILURE_COUNT, 1);
verify(controllerWrapper.mockMetricsContext, times(3)).gauge(eq(Constants.Metrics.Authorization.EXTENSION_CHECK_MILLIS), any(Long.class));
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class DefaultAccessEnforcerTest method testSystemUser.
@Test
public void testSystemUser() throws IOException, AccessException {
CConfiguration cConfCopy = CConfiguration.copy(CCONF);
Principal systemUser = new Principal(UserGroupInformation.getCurrentUser().getShortUserName(), Principal.PrincipalType.USER);
ControllerWrapper controllerWrapper = createControllerWrapper(cConfCopy, SCONF, null);
DefaultAccessEnforcer accessEnforcer = controllerWrapper.defaultAccessEnforcer;
NamespaceId ns1 = new NamespaceId("ns1");
accessEnforcer.enforce(NamespaceId.SYSTEM, systemUser, EnumSet.allOf(StandardPermission.class));
accessEnforcer.enforce(NamespaceId.SYSTEM, systemUser, StandardPermission.GET);
Assert.assertEquals(ImmutableSet.of(NamespaceId.SYSTEM), accessEnforcer.isVisible(ImmutableSet.of(ns1, NamespaceId.SYSTEM), systemUser));
// Verify the metrics context was called with correct metrics
verify(controllerWrapper.mockMetricsContext, times(2)).increment(Constants.Metrics.Authorization.EXTENSION_CHECK_BYPASS_COUNT, 1);
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class InternalAccessEnforcerTest method testInternalAccessEnforceNonInternalTokenType.
@Test(expected = AccessException.class)
public void testInternalAccessEnforceNonInternalTokenType() throws IOException {
NamespaceId ns = new NamespaceId("namespace");
long currentTime = System.currentTimeMillis();
UserIdentity userIdentity = new UserIdentity(SYSTEM_PRINCIPAL, UserIdentity.IdentifierType.EXTERNAL, Collections.emptyList(), currentTime, currentTime + 5 * MINUTE_MILLIS);
String encodedIdentity = Base64.getEncoder().encodeToString(accessTokenCodec.encode(tokenManager.signIdentifier(userIdentity)));
Credential credential = new Credential(encodedIdentity, Credential.CredentialType.INTERNAL);
Principal principal = new Principal(SYSTEM_PRINCIPAL, Principal.PrincipalType.USER, null, credential);
internalAccessEnforcer.enforce(ns, principal, StandardPermission.GET);
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class InternalAccessEnforcerTest method testInternalAccessEnforceOnParentSuccess.
@Test
public void testInternalAccessEnforceOnParentSuccess() throws IOException {
NamespaceId ns = new NamespaceId("namespace");
long currentTime = System.currentTimeMillis();
UserIdentity userIdentity = new UserIdentity(SYSTEM_PRINCIPAL, UserIdentity.IdentifierType.INTERNAL, Collections.emptyList(), currentTime, currentTime + 5 * MINUTE_MILLIS);
String encodedIdentity = Base64.getEncoder().encodeToString(accessTokenCodec.encode(tokenManager.signIdentifier(userIdentity)));
Credential credential = new Credential(encodedIdentity, Credential.CredentialType.INTERNAL);
Principal principal = new Principal(SYSTEM_PRINCIPAL, Principal.PrincipalType.USER, null, credential);
internalAccessEnforcer.enforceOnParent(EntityType.APPLICATION, ns, principal, StandardPermission.GET);
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class InternalAccessEnforcerTest method testInternalAccessEnforceOnParentNonInternalTokenType.
@Test(expected = AccessException.class)
public void testInternalAccessEnforceOnParentNonInternalTokenType() throws IOException {
NamespaceId ns = new NamespaceId("namespace");
long currentTime = System.currentTimeMillis();
UserIdentity userIdentity = new UserIdentity(SYSTEM_PRINCIPAL, UserIdentity.IdentifierType.EXTERNAL, Collections.emptyList(), currentTime, currentTime + 5 * MINUTE_MILLIS);
String encodedIdentity = Base64.getEncoder().encodeToString(accessTokenCodec.encode(tokenManager.signIdentifier(userIdentity)));
Credential credential = new Credential(encodedIdentity, Credential.CredentialType.INTERNAL);
Principal principal = new Principal(SYSTEM_PRINCIPAL, Principal.PrincipalType.USER, null, credential);
internalAccessEnforcer.enforceOnParent(EntityType.APPLICATION, ns, principal, StandardPermission.GET);
}
Aggregations