Skip to content

Commit

Permalink
change 3
Browse files Browse the repository at this point in the history
  • Loading branch information
wsjz committed Jul 16, 2024
1 parent 9514e32 commit e9cb670
Showing 1 changed file with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,25 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.security.PrivilegedExceptionAction;

public class HadoopSimpleAuthenticator implements HadoopAuthenticator {
private static final Logger LOG = LogManager.getLogger(HadoopSimpleAuthenticator.class);
private final SimpleAuthenticationConfig config;
private UserGroupInformation ugi;
private final UserGroupInformation ugi;

public HadoopSimpleAuthenticator(SimpleAuthenticationConfig config) {
this.config = config;
}

@Override
public UserGroupInformation getUGI() {
String hadoopUserName = config.getUsername();
if (hadoopUserName == null) {
hadoopUserName = "hadoop";
config.setUsername(hadoopUserName);
LOG.debug(AuthenticationConfig.HADOOP_USER_NAME + " is unset, use default user: hadoop");
}
try {
// get login user just for simple auth
ugi = UserGroupInformation.getLoginUser();
if (ugi.getUserName().equals(hadoopUserName)) {
return ugi;
}
} catch (IOException e) {
LOG.warn("A SecurityException occurs with simple, do login immediately.", e);
LOG.debug("{} is unset, use default user: hadoop", AuthenticationConfig.HADOOP_USER_NAME);
}
ugi = UserGroupInformation.createRemoteUser(hadoopUserName);
UserGroupInformation.setLoginUser(ugi);
LOG.debug("Login by proxy user, hadoop.username: {}", hadoopUserName);
}

@Override
public UserGroupInformation getUGI() {
return ugi;
}

Expand Down

0 comments on commit e9cb670

Please sign in to comment.