use of alluxio.security.authentication.AuthType in project alluxio by Alluxio.
the class LoginUser method login.
/**
* Logs in based on the LoginModules.
*
* @return the login user
* @throws IOException if login fails
*/
private static User login() throws IOException {
AuthType authType = Configuration.getEnum(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.class);
checkSecurityEnabled(authType);
Subject subject = new Subject();
try {
CallbackHandler callbackHandler = null;
if (authType.equals(AuthType.SIMPLE) || authType.equals(AuthType.CUSTOM)) {
callbackHandler = new AppLoginModule.AppCallbackHandler();
}
// Create LoginContext based on authType, corresponding LoginModule should be registered
// under the authType name in LoginModuleConfiguration.
LoginContext loginContext = new LoginContext(authType.getAuthName(), subject, callbackHandler, new LoginModuleConfiguration());
loginContext.login();
} catch (LoginException e) {
throw new IOException("Failed to login: " + e.getMessage(), e);
}
Set<User> userSet = subject.getPrincipals(User.class);
if (userSet.isEmpty()) {
throw new IOException("Failed to login: No Alluxio User is found.");
}
if (userSet.size() > 1) {
StringBuilder msg = new StringBuilder("Failed to login: More than one Alluxio Users are found:");
for (User user : userSet) {
msg.append(" ").append(user.toString());
}
throw new IOException(msg.toString());
}
return userSet.iterator().next();
}
Aggregations