Java Code Examples for javax.security.auth.callback.UnsupportedCallbackException#getMessage()

The following examples show how to use javax.security.auth.callback.UnsupportedCallbackException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExternalCertificateLoginModule.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public boolean login() throws LoginException {
   Callback[] callbacks = new Callback[1];

   callbacks[0] = new CertificateCallback();
   try {
      callbackHandler.handle(callbacks);
   } catch (IOException ioe) {
      throw new LoginException(ioe.getMessage());
   } catch (UnsupportedCallbackException uce) {
      throw new LoginException("Unable to obtain client certificates: " + uce.getMessage());
   }

   X509Certificate[] certificates = ((CertificateCallback) callbacks[0]).getCertificates();
   if (certificates != null && certificates.length > 0 && certificates[0] != null) {
      userName = certificates[0].getSubjectDN().getName();
   }

   logger.debug("Certificates: " + Arrays.toString(certificates) + ", userName: " + userName);
   return userName != null;
}
 
Example 2
Source File: CertificateLoginModule.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Overriding to allow for certificate-based login. Standard JAAS.
 */
@Override
public boolean login() throws LoginException {
   Callback[] callbacks = new Callback[1];

   callbacks[0] = new CertificateCallback();
   try {
      callbackHandler.handle(callbacks);
   } catch (IOException ioe) {
      throw new LoginException(ioe.getMessage());
   } catch (UnsupportedCallbackException uce) {
      throw new LoginException("Unable to obtain client certificates: " + uce.getMessage());
   }
   certificates = ((CertificateCallback) callbacks[0]).getCertificates();

   username = getUserNameForCertificates(certificates);
   if (username == null) {
      throw new FailedLoginException("No user for client certificate: " + getDistinguishedName(certificates));
   }

   if (debug) {
      logger.debug("Certificate for user: " + username);
   }
   return true;
}
 
Example 3
Source File: Krb5LoginModule.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public boolean login() throws LoginException {
   Callback[] callbacks = new Callback[1];

   callbacks[0] = new Krb5Callback();
   try {
      callbackHandler.handle(callbacks);
      principal = ((Krb5Callback)callbacks[0]).getPeerPrincipal();
      if (principal != null) {
         principals.add(principal);
      }
   } catch (IOException ioe) {
      throw new LoginException(ioe.getMessage());
   } catch (UnsupportedCallbackException uce) {
      throw new LoginException(uce.getMessage() + " not available to obtain information from user");
   }
   if (!principals.isEmpty()) {
      loginSucceeded = true;
   }
   logger.debug("login " + principals);
   return loginSucceeded;
}
 
Example 4
Source File: ScriptLoginModule.java    From tomee with Apache License 2.0 6 votes vote down vote up
private UserData getUserData() throws LoginException {
    final Callback[] callbacks = new Callback[2];

    callbacks[0] = new NameCallback("Username: ");
    callbacks[1] = new PasswordCallback("Password: ", false);
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final IOException ioe) {
        throw new LoginException(ioe.getMessage());
    } catch (final UnsupportedCallbackException uce) {
        throw new LoginException(uce.getMessage() + " not available to obtain information from user");
    }

    final String user = ((NameCallback) callbacks[0]).getName();

    char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
    if (tmpPassword == null) {
        tmpPassword = new char[0];
    }

    final String password = new String(tmpPassword);

    return new UserData(user, password);
}
 
Example 5
Source File: ServiceProviderLoginModule.java    From tomee with Apache License 2.0 6 votes vote down vote up
private UserData getUserData() throws LoginException {
    final Callback[] callbacks = new Callback[2];

    callbacks[0] = new NameCallback("Username: ");
    callbacks[1] = new PasswordCallback("Password: ", false);
    try {
        this.callbackHandler.handle(callbacks);
    } catch (final IOException ioe) {
        throw new LoginException(ioe.getMessage());
    } catch (final UnsupportedCallbackException uce) {
        throw new LoginException(uce.getMessage() + " not available to obtain information from user");
    }

    final String user = ((NameCallback) callbacks[0]).getName();

    char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
    if (tmpPassword == null) {
        tmpPassword = new char[0];
    }

    final String password = new String(tmpPassword);

    return new UserData(user, password);
}
 
Example 6
Source File: DummyLoginModule.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean login() throws LoginException {
   Callback[] callbacks = new Callback[2];

   callbacks[0] = new NameCallback("Username: ");
   callbacks[1] = new PasswordCallback("Password: ", false);
   try {
      callbackHandler.handle(callbacks);
   } catch (IOException ioe) {
      throw new LoginException(ioe.getMessage());
   } catch (UnsupportedCallbackException uce) {
      throw new LoginException(uce.getMessage() + " not available to obtain information from user");
   }
   String user = ((NameCallback) callbacks[0]).getName();
   char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
   if (tmpPassword == null) {
      tmpPassword = new char[0];
   }
   if (user == null) {
      throw new FailedLoginException("User is null");
   }
   subject.getPrincipals().add(new RolePrincipal("amq"));
   // String password = users.getProperty(user);

  /*if (password == null) {
     throw new FailedLoginException("User does not exist: " + user);
  }*/

   return true;
}
 
Example 7
Source File: InVMLoginModule.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean login() throws LoginException {
   Callback[] callbacks = new Callback[2];

   callbacks[0] = new NameCallback("Username: ");
   callbacks[1] = new PasswordCallback("Password: ", false);
   try {
      callbackHandler.handle(callbacks);
   } catch (IOException ioe) {
      throw new LoginException(ioe.getMessage());
   } catch (UnsupportedCallbackException uce) {
      throw new LoginException(uce.getMessage() + " not available to obtain information from user");
   }
   user = ((NameCallback) callbacks[0]).getName();
   char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
   if (tmpPassword == null) {
      tmpPassword = new char[0];
   }
   if (user == null) {
      if (configuration.getDefaultUser() == null) {
         throw new FailedLoginException("Both username and defaultUser are null");
      } else {
         user = configuration.getDefaultUser();
      }
   } else {
      String password = configuration.getUser(user) == null ? null : configuration.getUser(user).getPassword();

      if (password == null) {
         throw new FailedLoginException("User does not exist");
      }
      if (!password.equals(new String(tmpPassword))) {
         throw new FailedLoginException("Password does not match");
      }
   }
   loginSucceeded = true;

   logger.debug("login " + user);

   return loginSucceeded;
}
 
Example 8
Source File: SystemLoginModule.java    From peer-os with Apache License 2.0 4 votes vote down vote up
@Override
public boolean login() throws LoginException
{

    // **************************************
    Callback[] callbacks = new Callback[2];
    callbacks[0] = new NameCallback( "Username: " );
    callbacks[1] = new PasswordCallback( "Password: ", false );
    // **************************************

    try
    {
        // **************************************
        callbackHandler.handle( callbacks );
        user = ( ( NameCallback ) callbacks[0] ).getName();

        char[] tmpPassword = ( ( PasswordCallback ) callbacks[1] ).getPassword();
        if ( tmpPassword == null )
        {
            tmpPassword = new char[0];
        }
        String password = new String( tmpPassword );
        // **************************************

        Session userSession = identityManager.authenticateSession( user, password );

        if ( userSession != null )
        {

            User loggedUser = userSession.getUser();
            //******************************************
            principals = new HashSet<>();
            principals.add( new UserPrincipal( user ) );
            //******************************************

            if ( userSession.getSubject() != null ) //restore
            {
                principals.addAll( userSession.getSubject().getPrincipals() );
            }
            else //create new subject
            {

                //******************************************
                List<Role> roles = loggedUser.getRoles();
                for ( Role role : roles )
                {
                    List<Permission> permissions = role.getPermissions();
                    for ( Permission permission : permissions )
                    {
                        List<String> perms = permission.asString();

                        for ( String perm : perms )
                        {
                            principals.add( new RolePrincipal( perm ) );
                        }
                    }
                }
            }

            //******************************************
            subject.getPrincipals().clear();
            subject.getPrincipals().addAll( principals );
            subject.getPrivateCredentials().add( userSession );
            //******************************************
        }
        else
        {
            identityManager.getSecurityController().logEvent( user, password, "Invalid Login" );
            throw new LoginException( "Invalid Login" );
        }
    }
    catch ( IOException ioException )
    {
        throw new LoginException( ioException.getMessage() );
    }
    catch ( UnsupportedCallbackException unsupportedCallbackException )
    {
        throw new LoginException(
                unsupportedCallbackException.getMessage() + " not available to obtain information from user." );
    }
    catch ( Exception e )
    {
        LOGGER.error( e.toString() );
        return false;
    }

    return true;
}
 
Example 9
Source File: PropertiesLoginModule.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public boolean login() throws LoginException {
   Callback[] callbacks = new Callback[2];

   callbacks[0] = new NameCallback("Username: ");
   callbacks[1] = new PasswordCallback("Password: ", false);
   try {
      callbackHandler.handle(callbacks);
   } catch (IOException ioe) {
      throw new LoginException(ioe.getMessage());
   } catch (UnsupportedCallbackException uce) {
      throw new LoginException(uce.getMessage() + " not available to obtain information from user");
   }
   user = ((NameCallback) callbacks[0]).getName();
   char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
   if (tmpPassword == null) {
      tmpPassword = new char[0];
   }
   if (user == null) {
      throw new FailedLoginException("User is null");
   }
   String password = users.getProperty(user);

   if (password == null) {
      throw new FailedLoginException("User does not exist: " + user);
   }

   try {
      hashProcessor = PasswordMaskingUtil.getHashProcessor(password);
   } catch (Exception e) {
      throw new FailedLoginException("Failed to get hash processor");
   }

   if (!hashProcessor.compare(tmpPassword, password)) {
      throw new FailedLoginException("Password does not match for user: " + user);
   }
   loginSucceeded = true;

   if (debug) {
      logger.debug("login " + user);
   }
   return loginSucceeded;
}