Search in sources :

Example 1 with CurrentUser

use of alluxio.security.CurrentUser in project alluxio by Alluxio.

the class AbstractFileSystem method getHadoopSubject.

/**
 * @return hadoop UGI's subject, or a fresh subject if the Hadoop UGI does not exist
 * @throws IOException if there is an exception when accessing the subject in Hadoop UGI
 */
private Subject getHadoopSubject() throws IOException {
    Subject subject = null;
    UserGroupInformation ugi = null;
    try {
        ugi = UserGroupInformation.getCurrentUser();
        subject = getSubjectFromUGI(ugi);
    } catch (Exception e) {
        throw new IOException(String.format("Failed to get Hadoop subject for the Alluxio client. ugi: %s", ugi), e);
    }
    if (subject == null) {
        LOG.warn("Hadoop subject does not exist. Creating a fresh subject for Alluxio client");
        subject = new Subject(false, new HashSet<>(), new HashSet<>(), new HashSet<>());
    }
    if (subject.getPrincipals(CurrentUser.class).isEmpty() && ugi != null) {
        subject.getPrincipals().add(new CurrentUser(ugi.getShortUserName(), mUri.toString()));
    }
    return subject;
}
Also used : CurrentUser(alluxio.security.CurrentUser) IOException(java.io.IOException) Subject(javax.security.auth.Subject) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioException(alluxio.exception.AlluxioException) FileNotFoundException(java.io.FileNotFoundException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) HashSet(java.util.HashSet)

Example 2 with CurrentUser

use of alluxio.security.CurrentUser in project alluxio by Alluxio.

the class ImpersonationIntegrationTest method createHdfsSubject.

private Subject createHdfsSubject() {
    // Create a subject for an hdfs user
    CurrentUser user = new CurrentUser(HDFS_USER);
    Set<Principal> principals = new HashSet<>();
    principals.add(user);
    return new Subject(false, principals, new HashSet<>(), new HashSet<>());
}
Also used : CurrentUser(alluxio.security.CurrentUser) Principal(java.security.Principal) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet)

Aggregations

CurrentUser (alluxio.security.CurrentUser)2 HashSet (java.util.HashSet)2 Subject (javax.security.auth.Subject)2 AlluxioException (alluxio.exception.AlluxioException)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Principal (java.security.Principal)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1