use of io.cdap.cdap.proto.security.Credential in project cdap by cdapio.
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.Credential in project cdap by cdapio.
the class AuthenticationContextModules method loadRemoteCredentials.
private Credential loadRemoteCredentials(CConfiguration cConf) {
Path secretFile = Paths.get(Constants.Security.Authentication.RUNTIME_TOKEN_FILE);
if (Files.exists(secretFile)) {
try {
String token = new String(Files.readAllBytes(secretFile), StandardCharsets.UTF_8);
return new Credential(token, Credential.CredentialType.INTERNAL);
} catch (IOException e) {
throw new IllegalStateException("Can't read runtime token file", e);
}
}
String token = cConf.get(Constants.Security.Authentication.RUNTIME_TOKEN);
return token == null ? null : new Credential(token, Credential.CredentialType.INTERNAL);
}
use of io.cdap.cdap.proto.security.Credential in project cdap by cdapio.
the class AuthenticationTestContext method actAsPrincipal.
/**
* Sets the principal for this test authentication context.
* @param principal The principal to act as
*/
public static void actAsPrincipal(Principal principal) {
System.setProperty(PRINCIPAL_NAME, principal.getName());
Credential credential = principal.getFullCredential();
if (credential != null) {
System.setProperty(PRINCIPAL_CREDENTIAL_TYPE, credential.getType().name());
System.setProperty(PRINCIPAL_CREDENTIAL_VALUE, credential.getValue());
}
}
use of io.cdap.cdap.proto.security.Credential in project cdap by cdapio.
the class MasterAuthenticationContext method getPrincipal.
@Override
public Principal getPrincipal() {
// When requests come in via rest endpoints, the userId is updated inside SecurityRequestContext, so give that
// precedence.
String userId = SecurityRequestContext.getUserId();
Credential userCredential = SecurityRequestContext.getUserCredential();
// the UserGroupInformation, which will be the user that the master is running as.
if (userId == null) {
try {
userId = UserGroupInformation.getCurrentUser().getShortUserName();
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
return new Principal(userId, Principal.PrincipalType.USER, userCredential);
}
use of io.cdap.cdap.proto.security.Credential in project cdap by cdapio.
the class WorkerAuthenticationContext method getPrincipal.
/**
* Return {@link Principal} associated with current request stored in {@link SecurityRequestContext}.
* Typically, there is always a {@link Principal} as worker normally performs some operations on behalf of
* end user, thus the {@link Principal} should capture the credential of end user. But when there is none,
* use placeholder values to construct the {@link Principal}.
*/
@Override
public Principal getPrincipal() {
// By default, assume the principal comes from a user request and handle accordingly using SecurityRequestContext.
String userId = SecurityRequestContext.getUserId();
Credential userCredential = SecurityRequestContext.getUserCredential();
if (userId != null && userCredential != null) {
return new Principal(userId, Principal.PrincipalType.USER, userCredential);
}
return EMPTY_PRINCIPAL;
}
Aggregations