/** * Retrieves the user name by querying the property of * {@link PropertyKey#SECURITY_LOGIN_USERNAME} through {@link AppCallbackHandler}. * * @return true if user name provided by application is set and not empty * @throws LoginException when the login fails */ @Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[1]; callbacks[0] = new NameCallback("user name: "); try { mCallbackHandler.handle(callbacks); } catch (IOException | UnsupportedCallbackException e) { throw new LoginException(e.getMessage()); } String userName = ((NameCallback) callbacks[0]).getName(); if (!userName.isEmpty()) { mUser = new User(userName); return true; } return false; }
@Override public boolean login() throws LoginException { succeeded = true; if (credentialsInvalidate) { PasswordCallback passwordCallback = new PasswordCallback("Password: ", false); try { callbackHandler.handle(new Callback[]{passwordCallback}); if (passwordCallback.getPassword() != null) { if (debug) { LOG.debug("Guest login failing (credentialsInvalidate=true) on presence of a password"); } succeeded = false; passwordCallback.clearPassword(); }; } catch (IOException ioe) { } catch (UnsupportedCallbackException uce) { } } if (debug) { LOG.debug("Guest login " + succeeded); } return succeeded; }
@Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) { try { NameCallback nameCallback = new NameCallback("name:"); PasswordCallback passwordCallback = new PasswordCallback("password:", false); callbackHandler.handle(new Callback[]{nameCallback, passwordCallback}); subject.getPublicCredentials().add(nameCallback.getName()); subject.getPrivateCredentials().add(new String(passwordCallback.getPassword())); } catch (Exception e) { throw new SaslAuthenticationException("Login initialization failed", e); } } }
public static void makeDynamicPolicyCallback(DynamicPolicyCallback callback, CallbackHandler callbackHandler) throws XWSSecurityException { if (callbackHandler == null) return; try { Callback[] callbacks = new Callback[] { callback }; callbackHandler.handle(callbacks); } catch (UnsupportedCallbackException ex) { //ok to ignore this since not all callback-handlers will implement this } catch (Exception e) { log.log(Level.SEVERE, "WSS0237.failed.DynamicPolicyCallback", e); throw new XWSSecurityException(e); } }
Security.addProvider(p); ks = KeyStore.getInstance("PKCS11",p); pcb = new PasswordCallback("PKCS11 Password: ",false); callbackHandler.handle(new Callback[] {pcb}); ks.load(null,pcb.getPassword()); LOGGER.log(Level.WARNING, "Exception", e); ks = null; if (callbackHandler != null && StringUtils.isNotEmpty(keystorePath)) { try { pcb = new PasswordCallback("Keystore Password: ", false); callbackHandler.handle(new Callback[] { pcb }); ks.load(new FileInputStream(keystorePath), pcb.getPassword()); LOGGER.log(Level.WARNING, "Exception", e); ks = null; LOGGER.log(Level.FINE, "Could get the default KeyManagerFactory for the '" + keyManagerFactoryAlgorithm + "' algorithm", e); kmf.init(ks, pcb.getPassword()); pcb.clearPassword();
NameCallback nameCallback = new NameCallback("Username: "); try { Callback[] cbs = new Callback[] {nameCallback}; _handler.handle(cbs); } catch (Exception e) { log.log(Level.SEVERE, "WSS0216.callbackhandler.handle.exception", new Object[] { "NameCallback"}); throw new RuntimeException(e); return nameCallback.getName();
NameCallback nc = new NameCallback("SASL PLAIN"); nc.setName(parts[1]); PasswordCallback pc = new PasswordCallback("SASL PLAIN", false); pc.setPassword(parts[2].toCharArray()); AuthorizeCallback ac = new AuthorizeCallback(parts[1], parts[0]); cbh.handle(new Callback[]{ nc, pc, ac }); if (ac.isAuthorized()) { authz = ac.getAuthorizedID();
protected Object getCredential() throws LoginException { NameCallback nc = new NameCallback("Alias: "); ObjectCallback oc = new ObjectCallback("Credential: "); Callback[] callbacks = { nc, oc }; try { callbackHandler.handle(callbacks); return oc.getCredential(); } catch (IOException ioe) { LoginException le = new LoginException(); le.initCause(ioe); throw le; } catch (UnsupportedCallbackException uce) { LoginException le = new LoginException(); le.initCause(uce); throw le; } }
@Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("User name"); callbacks[1] = new PasswordCallback("Password", false); try { handler.handle(callbacks); } catch (IOException ioe) { throw (LoginException)new LoginException().initCause(ioe); } catch (UnsupportedCallbackException uce) { throw (LoginException)new LoginException().initCause(uce); } String password; String username = ((NameCallback)callbacks[0]).getName(); if (username == null) return false; if (((PasswordCallback)callbacks[1]).getPassword() != null) password = new String(((PasswordCallback)callbacks[1]).getPassword()); else password=""; // authenticate will throw LoginException // in case of failed authentication authenticate(username, password); user = new UserPrincipal(username); succeeded = true; return true; }
public void updateOtherPartySubject( Subject subject, String username, String password) { CallerPrincipalCallback pvCallback = new CallerPrincipalCallback(subject, username); Callback[] callbacks = new Callback[] { pvCallback }; try { _handler.handle(callbacks); } catch (Exception e) { log.log(Level.SEVERE, "WSS0216.callbackhandler.handle.exception", new Object[] { "CallerPrincipalCallback"}); throw new XWSSecurityRuntimeException(e); } }
private void initKeyPassword() { //NOTE: this is called only when this.keyPwd is non-null // check if this.keyPwd is a CBH try { Class cbh = this.loadClassSilent(this.keyPwd); if (cbh != null) { CallbackHandler hdlr = (CallbackHandler) cbh.newInstance(); javax.security.auth.callback.PasswordCallback pc = new javax.security.auth.callback.PasswordCallback("KeyPassword", false); Callback[] cbs = new Callback[]{pc}; hdlr.handle(cbs); this.keyPassword = ((javax.security.auth.callback.PasswordCallback) cbs[0]).getPassword(); } else { //the user supplied value is a Password for the key alias this.keyPassword = this.keyPwd.toCharArray(); } } catch (java.lang.InstantiationException ex) { log.log(Level.SEVERE, "WSS1528.failed.initialize.key.password", ex); throw new RuntimeException(ex); } catch (java.io.IOException e) { log.log(Level.SEVERE, "WSS1528.failed.initialize.key.password", e); throw new RuntimeException(e); } catch (java.lang.IllegalAccessException ie) { log.log(Level.SEVERE, "WSS1528.failed.initialize.key.password", ie); throw new RuntimeException(ie); } catch (javax.security.auth.callback.UnsupportedCallbackException ue) { log.log(Level.SEVERE, "WSS1528.failed.initialize.key.password", ue); throw new RuntimeException(ue); } }
private void handleUsernameCallback(UsernameCallback cb) throws IOException, UnsupportedCallbackException { if (myUsername != null) { cb.setUsername(myUsername); } else { String username = (String) cb.getRuntimeProperties().get(com.sun.xml.wss.XWSSConstants.USERNAME_PROPERTY); if (username == null) { //the property below is dedprecated for xwss usage username = (String) cb.getRuntimeProperties().get(BindingProvider.USERNAME_PROPERTY); } if (username != null) { cb.setUsername(username); } else if (usernameHandler != null) { Callback[] cbs = null; if (useXWSSCallbacks) { cbs = new Callback[]{cb}; } else { javax.security.auth.callback.NameCallback nc = new javax.security.auth.callback.NameCallback("Username="); cbs = new Callback[]{nc}; } usernameHandler.handle(cbs); cb.setUsername(((javax.security.auth.callback.NameCallback) cbs[0]).getName()); } else { log.log(Level.SEVERE, "WSS1500.invalid.usernameHandler"); throw new UnsupportedCallbackException(null, "Username Handler Not Configured"); } } }
NameCallback nameCallback = new NameCallback("User"); nameCallback.setName(authenticationId); PasswordCallback passwordCallback = new PasswordCallback("Password", false); passwordCallback.setPassword(passwd.toCharArray()); AuthorizeCallback authCallback = new AuthorizeCallback(authenticationId, authorizationId); mHandler.handle(cbList); if (!authCallback.isAuthorized()) { throw new SaslException("AuthorizeCallback authorized failure");
AuthenticationConfiguration configuration = authClient.getAuthenticationConfiguration(uri, authenticationContext, 0, null, null); NameCallback nameCallback = new NameCallback("LDAP principal"); CredentialCallback credentialCallback = new CredentialCallback(PasswordCredential.class, ClearPassword.ALGORITHM_CLEAR); try { authClient.getCallbackHandler(configuration).handle(new Callback[]{nameCallback, credentialCallback}); } catch (Exception e) { throw log.couldNotObtainCredentialWithCause(e); securityPrincipal = nameCallback.getName(); PasswordCredential credential = credentialCallback.getCredential(PasswordCredential.class); if (credential == null) throw log.couldNotObtainCredential();
public <C extends Credential> C getCredential(final Class<C> credentialType, final String algorithmName, final AlgorithmParameterSpec parameterSpec) throws IOException { if (PasswordCredential.class.isAssignableFrom(credentialType) && (algorithmName == null || algorithmName.equals(ClearPassword.ALGORITHM_CLEAR)) && parameterSpec == null) { try { final PasswordCallback passwordCallback = new PasswordCallback("Password", false); callbackHandler.handle(new Callback[] { passwordCallback }); final char[] chars = passwordCallback.getPassword(); return chars == null ? null : credentialType.cast(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, chars))); } catch (UnsupportedCallbackException e) { // fall out and try CredentialCallback } } try { final CredentialCallback credentialCallback = new CredentialCallback(credentialType, algorithmName, parameterSpec); callbackHandler.handle(new Callback[] { credentialCallback }); return credentialCallback.getCredential(credentialType, algorithmName, parameterSpec); } catch (UnsupportedCallbackException e) { // no credentials can be acquired; fall out } return null; } }
NameCallback nameCallback = new NameCallback("username", username); PlainAuthenticateCallback authenticateCallback = new PlainAuthenticateCallback(password.toCharArray()); try { callbackHandler.handle(new Callback[]{nameCallback, authenticateCallback}); } catch (Throwable e) { throw new SaslAuthenticationException("Authentication failed: credentials for user could not be verified", e);
private byte[] getPredigestedSaltedPassword() throws AuthenticationMechanismException { if (realmChoiceCallBack != null) { try { callbackHandler.handle(new Callback[]{ realmChoiceCallBack }); int[] selected = realmChoiceCallBack.getSelectedIndexes(); if (selected == null || selected.length == 0) { callbackHandler.handle(new Callback[]{ realmCallback }); if (realmCallback.getText() != null) realm = realmCallback.getText(); } catch (UnsupportedCallbackException e) { callbackHandler.handle(new Callback[]{ nameCallback }); if ( ! readOnlyRealmUsername) { username = nameCallback.getName(); if (username == null) { throw log.mechNotProvidedUserName(); callbackHandler.handle(new Callback[]{ credentialCallback });
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()); 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];
public void updateOtherPartySubject( final Subject subject, final X509Certificate cert) { Principal principal = cert.getSubjectX500Principal(); AccessController.doPrivileged( new PrivilegedAction() { public Object run() { subject.getPublicCredentials().add(cert); return null; } }); CallerPrincipalCallback pvCallback = new CallerPrincipalCallback(subject,principal); Callback[] callbacks = new Callback[] { pvCallback }; try { _handler.handle(callbacks); } catch (Exception e) { log.log(Level.SEVERE, "WSS0216.callbackhandler.handle.exception", new Object[] { "CallerPrincipalCallback"}); throw new XWSSecurityRuntimeException(e); } }