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

The following examples show how to use javax.security.auth.callback.UnsupportedCallbackException#getCallback() . 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: DatawavePrincipalLoginModule.java    From datawave with Apache License 2.0 5 votes vote down vote up
protected DatawaveCredential getDatawaveCredential() throws LoginException {
    if (trace)
        log.trace("enter: getDatawaveCredential()");
    if (callbackHandler == null) {
        log.error("Error: no CallbackHandler available to collect authentication information");
        throw new LoginException("Error: no CallbackHandler available to collect authentication information");
    }
    NameCallback nc = new NameCallback("Username: ");
    ObjectCallback oc = new ObjectCallback("Credentials: ");
    Callback callbacks[] = {nc, oc};
    try {
        callbackHandler.handle(callbacks);
        
        // We use a custom authentication mechanism to convert the certificate into a DatawaveCredential.
        // The custom authentication mechanism checks the request for the X-ProxiedEntitiesChain/X-ProxiedIssuersChain
        // headers and uses them along with either the certificate subject and issuer DNs or trusted headers
        // (supplied by the load balancer) containing the subject and issuer DNs to construct a list of entities.
        Object tmpCreds = oc.getCredential();
        if (tmpCreds instanceof DatawaveCredential) {
            return (DatawaveCredential) tmpCreds;
        } else {
            String credentialClass = tmpCreds == null ? "null" : tmpCreds.getClass().getName();
            String msg = "Unknown credential class " + credentialClass + " is not a " + DatawaveCredential.class.getName();
            log.warn(msg);
            throw new LoginException(msg);
        }
    } catch (IOException e) {
        log.debug("Failed to invoke callback", e);
        throw new LoginException("Failed to invoke callback: " + e);
    } catch (UnsupportedCallbackException uce) {
        log.debug("CallbackHandler does not support: " + uce.getCallback());
        throw new LoginException("CallbackHandler does not support: " + uce.getCallback());
    } finally {
        if (trace)
            log.trace("exit: getDatawaveCredential()");
    }
}
 
Example 2
Source File: UniversalLoginModule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Called by login() to acquire the username and password strings for authentication. This method does no validation
    * of either.
    *
    * @return String[], [0] = username, [1] = password
    */
   private String[] getUsernameAndPassword() throws LoginException {
if (callbackHandler == null) {
    throw new LoginException("No CallbackHandler available to collect authentication information");
}
NameCallback nc = new NameCallback("User name: ", "guest");
PasswordCallback pc = new PasswordCallback("Password: ", false);
Callback[] callbacks = { nc, pc };
String username = null;
String password = null;
try {
    callbackHandler.handle(callbacks);
    username = nc.getName();
    char[] tmpPassword = pc.getPassword();
    if (tmpPassword != null) {
	credential = new char[tmpPassword.length];
	System.arraycopy(tmpPassword, 0, credential, 0, tmpPassword.length);
	pc.clearPassword();
	password = new String(credential);
    }
} catch (IOException ioe) {
    throw new LoginException(ioe.toString());
} catch (UnsupportedCallbackException uce) {
    throw new LoginException("CallbackHandler does not support: " + uce.getCallback());
}
return new String[] { username, password };
   }
 
Example 3
Source File: TMLoginModule.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/** 
 * Prompt the user for username and password, and verify those.
 */
@Override
public boolean login() throws LoginException {
  log.debug("TMLoginModule: login");
  
  if (callbackHandler == null)
    throw new LoginException("Error: no CallbackHandler available " +
            "to garner authentication information from the user");
  
  // prompt for a user name and password
  NameCallback nameCallback =  new NameCallback("user name: ");
  PasswordCallback passwordCallback = new PasswordCallback("password: ",
          false);
  
  try {
    callbackHandler.handle(new Callback[] {nameCallback, passwordCallback});

    this.username = nameCallback.getName();
    char[] charpassword = passwordCallback.getPassword();
    password = (charpassword == null ? "" : new String(charpassword));
    passwordCallback.clearPassword();
    
  } catch (java.io.IOException ioe) {
    throw new LoginException(ioe.toString());
  } catch (UnsupportedCallbackException uce) {
    throw new LoginException("Error: " + uce.getCallback() +
            " not available to garner authentication information " +
            "from the user");
  }
  // verify the username/password
  loginSucceeded = verifyUsernamePassword(username, password);
  return loginSucceeded;
}