Search in sources :

Example 1 with AuthType

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();
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) LoginContext(javax.security.auth.login.LoginContext) LoginModuleConfiguration(alluxio.security.login.LoginModuleConfiguration) LoginException(javax.security.auth.login.LoginException) AuthType(alluxio.security.authentication.AuthType) IOException(java.io.IOException) Subject(javax.security.auth.Subject) AppLoginModule(alluxio.security.login.AppLoginModule)

Aggregations

AuthType (alluxio.security.authentication.AuthType)1 AppLoginModule (alluxio.security.login.AppLoginModule)1 LoginModuleConfiguration (alluxio.security.login.LoginModuleConfiguration)1 IOException (java.io.IOException)1 Subject (javax.security.auth.Subject)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 LoginContext (javax.security.auth.login.LoginContext)1 LoginException (javax.security.auth.login.LoginException)1