Java Code Examples for javax.security.auth.callback.PasswordCallback#getPassword()

The following examples show how to use javax.security.auth.callback.PasswordCallback#getPassword() . 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: SimpleServerAuthModule.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected boolean validate(Subject clientSubject, MessageInfo messageInfo) throws AuthException
{
 //Construct Callbacks
   NameCallback nc = new NameCallback("Dummy");
   PasswordCallback pc = new PasswordCallback("B" , true);
   try
   {
      this.callbackHandler.handle(new Callback[]{nc,pc});
      String userName = nc.getName();
      String pwd = new String(pc.getPassword());
      
      //Check the options
      if(!(userName.equals(options.get("principal"))
            && (pwd.equals(options.get("pass")))))
      {
         return false;
      }
            
   }
   catch (Exception e)
   {
      throw new AuthException(e.getLocalizedMessage());
   } 
   return true;
}
 
Example 2
Source File: QuarkusDirContextFactory.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public DirContext obtainDirContext(CallbackHandler handler, ReferralMode mode) throws NamingException {
    NameCallback nameCallback = new NameCallback("Principal Name");
    PasswordCallback passwordCallback = new PasswordCallback("Password", false);

    try {
        handler.handle(new Callback[] { nameCallback, passwordCallback });
    } catch (Exception e) {
        throw new RuntimeException("Could not obtain credential", e);
        //            throw log.couldNotObtainCredentialWithCause(e);
    }

    String securityPrincipal = nameCallback.getName();

    if (securityPrincipal == null) {
        throw new RuntimeException("Could not obtain principal");
        //            throw log.couldNotObtainPrincipal();
    }

    char[] securityCredential = passwordCallback.getPassword();

    if (securityCredential == null) {
        throw new RuntimeException("Could not obtain credential");
        //            throw log.couldNotObtainCredential();
    }

    return createDirContext(securityPrincipal, securityCredential, mode);
}
 
Example 3
Source File: KeyStoreLoginModule.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void saveKeyPass(PasswordCallback c) {
    privateKeyPassword = c.getPassword();
    if (privateKeyPassword == null || privateKeyPassword.length == 0) {
        /*
         * Use keystore password if no private key password is
         * specified.
         */
        privateKeyPassword = keyStorePassword;
    }
    c.clearPassword();
}
 
Example 4
Source File: KeyStoreLoginModule.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void saveStorePass(PasswordCallback c) {
    keyStorePassword = c.getPassword();
    if (keyStorePassword == null) {
        /* Treat a NULL password as an empty password */
        keyStorePassword = new char[0];
    }
    c.clearPassword();
}
 
Example 5
Source File: TestLoginModule.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@Override
public boolean login() throws LoginException {
    NameCallback userNameCallback = new NameCallback("userName");
    PasswordCallback passwordCallback = new PasswordCallback("password", false);
    Callback[] callbacks = { userNameCallback, passwordCallback };
    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new AuthException("Error while handling callback ", e);
    }
    String userName = userNameCallback.getName();
    char[] password = passwordCallback.getPassword();
    return Arrays.equals(password, usersMap.get(userName));
}
 
Example 6
Source File: KeyStoreLoginModule.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void saveKeyPass(PasswordCallback c) {
    privateKeyPassword = c.getPassword();
    if (privateKeyPassword == null || privateKeyPassword.length == 0) {
        /*
         * Use keystore password if no private key password is
         * specified.
         */
        privateKeyPassword = keyStorePassword;
    }
    c.clearPassword();
}
 
Example 7
Source File: KeyStoreLoginModule.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void saveKeyPass(PasswordCallback c) {
    privateKeyPassword = c.getPassword();
    if (privateKeyPassword == null || privateKeyPassword.length == 0) {
        /*
         * Use keystore password if no private key password is
         * specified.
         */
        privateKeyPassword = keyStorePassword;
    }
    c.clearPassword();
}
 
Example 8
Source File: KeyStoreLoginModule.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void saveKeyPass(PasswordCallback c) {
    privateKeyPassword = c.getPassword();
    if (privateKeyPassword == null || privateKeyPassword.length == 0) {
        /*
         * Use keystore password if no private key password is
         * specified.
         */
        privateKeyPassword = keyStorePassword;
    }
    c.clearPassword();
}
 
Example 9
Source File: KeyStoreLoginModule.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void saveStorePass(PasswordCallback c) {
    keyStorePassword = c.getPassword();
    if (keyStorePassword == null) {
        /* Treat a NULL password as an empty password */
        keyStorePassword = new char[0];
    }
    c.clearPassword();
}
 
Example 10
Source File: KeyStoreLoginModule.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private void saveStorePass(PasswordCallback c) {
    keyStorePassword = c.getPassword();
    if (keyStorePassword == null) {
        /* Treat a NULL password as an empty password */
        keyStorePassword = new char[0];
    }
    c.clearPassword();
}
 
Example 11
Source File: KeyStoreLoginModule.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private void saveKeyPass(PasswordCallback c) {
    privateKeyPassword = c.getPassword();
    if (privateKeyPassword == null || privateKeyPassword.length == 0) {
        /*
         * Use keystore password if no private key password is
         * specified.
         */
        privateKeyPassword = keyStorePassword;
    }
    c.clearPassword();
}
 
Example 12
Source File: KeyStoreLoginModule.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private void saveStorePass(PasswordCallback c) {
    keyStorePassword = c.getPassword();
    if (keyStorePassword == null) {
        /* Treat a NULL password as an empty password */
        keyStorePassword = new char[0];
    }
    c.clearPassword();
}
 
Example 13
Source File: KeyStoreLoginModule.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void saveKeyPass(PasswordCallback c) {
    privateKeyPassword = c.getPassword();
    if (privateKeyPassword == null || privateKeyPassword.length == 0) {
        /*
         * Use keystore password if no private key password is
         * specified.
         */
        privateKeyPassword = keyStorePassword;
    }
    c.clearPassword();
}
 
Example 14
Source File: KeyStoreLoginModule.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void saveStorePass(PasswordCallback c) {
    keyStorePassword = c.getPassword();
    if (keyStorePassword == null) {
        /* Treat a NULL password as an empty password */
        keyStorePassword = new char[0];
    }
    c.clearPassword();
}
 
Example 15
Source File: KeyStoreLoginModule.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void saveKeyPass(PasswordCallback c) {
    privateKeyPassword = c.getPassword();
    if (privateKeyPassword == null || privateKeyPassword.length == 0) {
        /*
         * Use keystore password if no private key password is
         * specified.
         */
        privateKeyPassword = keyStorePassword;
    }
    c.clearPassword();
}
 
Example 16
Source File: KeyStoreLoginModule.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void saveStorePass(PasswordCallback c) {
    keyStorePassword = c.getPassword();
    if (keyStorePassword == null) {
        /* Treat a NULL password as an empty password */
        keyStorePassword = new char[0];
    }
    c.clearPassword();
}
 
Example 17
Source File: KeyStoreLoginModule.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void saveKeyPass(PasswordCallback c) {
    privateKeyPassword = c.getPassword();
    if (privateKeyPassword == null || privateKeyPassword.length == 0) {
        /*
         * Use keystore password if no private key password is
         * specified.
         */
        privateKeyPassword = keyStorePassword;
    }
    c.clearPassword();
}
 
Example 18
Source File: KeyStoreLoginModule.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void saveStorePass(PasswordCallback c) {
    keyStorePassword = c.getPassword();
    if (keyStorePassword == null) {
        /* Treat a NULL password as an empty password */
        keyStorePassword = new char[0];
    }
    c.clearPassword();
}
 
Example 19
Source File: KeyStoreLoginModule.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private void saveKeyPass(PasswordCallback c) {
    privateKeyPassword = c.getPassword();
    if (privateKeyPassword == null || privateKeyPassword.length == 0) {
        /*
         * Use keystore password if no private key password is
         * specified.
         */
        privateKeyPassword = keyStorePassword;
    }
    c.clearPassword();
}
 
Example 20
Source File: AltClientLoginModule.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Method to authenticate a Subject (phase 1).
 */
public boolean login() throws LoginException
{
   // If useFirstPass is true, look for the shared password
   if( useFirstPass == true )
   {
         return true;
   }

  /* There is no password sharing or we are the first login module. Get
      the username and password from the callback hander.
   */
   if (callbackHandler == null)
      throw PicketBoxMessages.MESSAGES.noCallbackHandlerAvailable();

   PasswordCallback pc = new PasswordCallback(PicketBoxMessages.MESSAGES.enterPasswordMessage(), false);
   NameCallback nc = new NameCallback(PicketBoxMessages.MESSAGES.enterUsernameMessage(), "guest");
   Callback[] callbacks = {nc, pc};
   try
   {
      char[] tmpPassword;
      
      callbackHandler.handle(callbacks);
      username = nc.getName();
      tmpPassword = pc.getPassword();
      if (tmpPassword != null)
      {
         password = new char[tmpPassword.length];
         System.arraycopy(tmpPassword, 0, password, 0, tmpPassword.length);
         pc.clearPassword();
      }
   }
   catch (java.io.IOException ioe)
   {
      throw new LoginException(ioe.toString());
   }
   catch (UnsupportedCallbackException uce)
   {
      LoginException le = new LoginException(uce.getLocalizedMessage());
      le.initCause(uce);
      throw le;
   }
   return true;
}