use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class InternalAccessEnforcerTest method testInternalAccessIsVisibleSuccess.
@Test
public void testInternalAccessIsVisibleSuccess() throws IOException {
NamespaceId ns = new NamespaceId("namespace");
Set<EntityId> entities = Collections.singleton(ns);
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);
Assert.assertEquals(entities, internalAccessEnforcer.isVisible(entities, principal));
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class InternalAccessEnforcerTest method testInternalAccessEnforceOnParentNullCredential.
@Test(expected = IllegalStateException.class)
public void testInternalAccessEnforceOnParentNullCredential() throws IOException {
NamespaceId ns = new NamespaceId("namespace");
Principal principal = new Principal(SYSTEM_PRINCIPAL, Principal.PrincipalType.USER, null, null);
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 testInternalAccessIsVisibleNonInternalTokenType.
@Test
public void testInternalAccessIsVisibleNonInternalTokenType() throws IOException {
NamespaceId ns = new NamespaceId("namespace");
Set<EntityId> entities = Collections.singleton(ns);
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);
Assert.assertEquals(Collections.emptySet(), internalAccessEnforcer.isVisible(entities, principal));
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class InternalAccessEnforcerTest method testInternalAccessEnforceNullCredential.
@Test(expected = IllegalStateException.class)
public void testInternalAccessEnforceNullCredential() throws IOException {
NamespaceId ns = new NamespaceId("namespace");
Principal principal = new Principal(SYSTEM_PRINCIPAL, Principal.PrincipalType.USER, null, null);
internalAccessEnforcer.enforce(ns, principal, StandardPermission.GET);
}
use of io.cdap.cdap.proto.security.Principal in project cdap by caskdata.
the class DefaultAccessEnforcerTest method testInternalIsVisible.
@Test
public void testInternalIsVisible() throws IOException, AccessException {
Principal userWithInternalCred = new Principal("system", Principal.PrincipalType.USER, null, new Credential("credential", Credential.CredentialType.INTERNAL));
CConfiguration cConfCopy = CConfiguration.copy(CCONF);
cConfCopy.setBoolean(Constants.Security.INTERNAL_AUTH_ENABLED, true);
ControllerWrapper controllerWrapper = createControllerWrapper(cConfCopy, SCONF, new NoOpAccessController());
AccessController accessController = controllerWrapper.accessController;
DefaultAccessEnforcer accessEnforcer = controllerWrapper.defaultAccessEnforcer;
Set<EntityId> namespaces = ImmutableSet.of(NS);
// Make sure that the actual access controller does not have access.
Assert.assertEquals(Collections.emptySet(), accessController.isVisible(namespaces, userWithInternalCred));
// The no-op access enforcer allows all requests through, so this should succeed if it is using the right
// access controller.
Assert.assertEquals(namespaces, accessEnforcer.isVisible(namespaces, userWithInternalCred));
// Verify the metrics context was called with correct metrics
verify(controllerWrapper.mockMetricsContext, times(1)).increment(Constants.Metrics.Authorization.INTERNAL_VISIBILITY_CHECK_COUNT, 1);
}
Aggregations