Java Code Examples for javax.security.auth.callback.UnsupportedCallbackException

The following examples show how to use javax.security.auth.callback.UnsupportedCallbackException. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Tomcat8-Source-Read   Source File: JAASMemoryLoginModule.java    License: MIT License 6 votes vote down vote up
private String getCatalinaBase() {
    // Have to get this via a callback as that is the only link we have back
    // to the defining Realm. Can't use the system property as that may not
    // be set/correct in an embedded scenario

    if (callbackHandler == null) {
        return null;
    }

    Callback callbacks[] = new Callback[1];
    callbacks[0] = new TextInputCallback("catalinaBase");

    String result = null;

    try {
        callbackHandler.handle(callbacks);
        result = ((TextInputCallback) callbacks[0]).getText();
    } catch (IOException | UnsupportedCallbackException e) {
        return null;
    }

    return result;
}
 
Example 2
Source Project: micro-integrator   Source File: SecureAxisServiceClient.java    License: Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

        WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[0];
        String id = pwcb.getIdentifer();
        int usage = pwcb.getUsage();

        if (usage == WSPasswordCallback.SIGNATURE || usage == WSPasswordCallback.DECRYPT) {
            // Logic to get the private key password for signture or decryption
            if ("client".equals(id)) {
                pwcb.setPassword("automation");

            } else if ("service".equals(id)) {
                pwcb.setPassword("automation");

            } else if ("wso2carbon".equals(id)) {
                pwcb.setPassword("wso2carbon");

            } else if ("alice".equals(id)) {
                pwcb.setPassword("password");

            } else if ("bob".equals(id)) {
                pwcb.setPassword("password");

            }
        }
    }
 
Example 3
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            ((NameCallback)callback).setName(name);
        }
        else if (callback instanceof PasswordCallback) {
            ((PasswordCallback)callback).setPassword(password.toCharArray());
        }
        else if (jettyCallback(callback)) {
            try {
                jettySetObjectMethod.invoke(callback, password);
            }
            catch (ReflectiveOperationException ex) {
                throw new IOException(ex);
            }
        }
        else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
 
Example 4
Source Project: Bats   Source File: DefaultCallbackHandler.java    License: Apache License 2.0 6 votes vote down vote up
protected void processCallback(Callback callback) throws IOException, UnsupportedCallbackException
{
  if (callback instanceof NameCallback) {
    NameCallback namecb = (NameCallback)callback;
    namecb.setName(context.getValue(SecurityContext.USER_NAME));
  } else if (callback instanceof PasswordCallback) {
    PasswordCallback passcb = (PasswordCallback)callback;
    passcb.setPassword(context.getValue(SecurityContext.PASSWORD));
  } else if (callback instanceof RealmCallback) {
    RealmCallback realmcb = (RealmCallback)callback;
    realmcb.setText(context.getValue(SecurityContext.REALM));
  } else if (callback instanceof TextOutputCallback) {
    TextOutputCallback textcb = (TextOutputCallback)callback;
    if (textcb.getMessageType() == TextOutputCallback.INFORMATION) {
      logger.info(textcb.getMessage());
    } else if (textcb.getMessageType() == TextOutputCallback.WARNING) {
      logger.warn(textcb.getMessage());
    } else if (textcb.getMessageType() == TextOutputCallback.ERROR) {
      logger.error(textcb.getMessage());
    } else {
      logger.debug("Auth message type {}, message {}", textcb.getMessageType(), textcb.getMessage());
    }
  } else {
    throw new UnsupportedCallbackException(callback);
  }
}
 
Example 5
Source Project: cxf   Source File: UsernamePasswordCallback.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Here, we attempt to get the password from the private alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        // System.out.println("**************** Server checking id: "+pc.getIdentifer());

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
            return;
        }
    }

    //
    // Password not found
    //
    throw new IOException();
}
 
Example 6
public void handle(Callback[] callbacks) throws
        UnsupportedCallbackException, IOException {
    for (int i=0; i<callbacks.length; i++) {
        Callback callBack = callbacks[i];

        if (callBack instanceof NameCallback) {
            getAnswer();
            ((NameCallback)callBack).setName(username);
        } else if (callBack instanceof PasswordCallback) {
            getAnswer();
            ((PasswordCallback)callBack).setPassword(password);
            if (password != null) Arrays.fill(password, ' ');
        } else {
            throw new UnsupportedCallbackException(callBack,
                    "Call back not supported");
        }
    }
}
 
Example 7
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(userName);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callback;
            pc.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback");
        }
    }
}
 
Example 8
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback callback : callbacks) {
        if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(userName);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callback;
            pc.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(callback,
                    "Unrecognized Callback");
        }
    }
}
 
Example 9
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(username);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(password.toCharArray());
        } else if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            rcb.setText(rcb.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example 10
protected Subject loginTestUser() throws LoginException, IOException {
    LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback callback : callbacks) {
                if (callback instanceof PasswordCallback) {
                    PasswordCallback passwordCallback = (PasswordCallback) callback;
                    passwordCallback.setPassword(TESTPASS.toCharArray());
                }
                if (callback instanceof NameCallback) {
                    NameCallback nameCallback = (NameCallback) callback;
                    nameCallback.setName(TESTUSER);
                }
            }
        }
    });
    // attempt authentication
    lc.login();
    return lc.getSubject();
}
 
Example 11
Source Project: cxf   Source File: TestUserPasswordLoginModule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean login() throws LoginException {
    NameCallback nameCallback = new NameCallback("User");
    PasswordCallback passwordCallback = new PasswordCallback("Password", false);
    Callback[] callbacks = new Callback[] {nameCallback, passwordCallback};
    try {
        this.callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new LoginException(e.getMessage());
    }
    String userName = nameCallback.getName();
    String password = new String(passwordCallback.getPassword());
    if (!TESTUSER.equals(userName)) {
        throw new LoginException("wrong username");
    }
    if (!TESTPASS.equals(password)) {
        throw new LoginException("wrong password");
    }
    subject.getPrincipals().add(new SimplePrincipal(userName));
    subject.getPrincipals().add(new SimpleGroup(TESTGROUP));
    return true;
}
 
Example 12
Source Project: cxf-fediz   Source File: ClaimsProcessorTest.java    License: Apache License 2.0 6 votes vote down vote up
private String createSamlToken(SamlAssertionWrapper assertion, String alias, boolean sign, String rstr)
    throws IOException, UnsupportedCallbackException, WSSecurityException, SAXException,
    ParserConfigurationException {
    WSPasswordCallback[] cb = {
        new WSPasswordCallback(alias, WSPasswordCallback.SIGNATURE)
    };
    cbPasswordHandler.handle(cb);
    String password = cb[0].getPassword();

    if (sign) {
        assertion.signAssertion(alias, password, crypto, false);
    }
    Document doc = STSUtil.toSOAPPart(rstr);
    Element token = assertion.toDOM(doc);

    Element e = XMLUtils.findElement(doc, "RequestedSecurityToken",
                                                    FederationConstants.WS_TRUST_13_NS);
    if (e == null) {
        e = XMLUtils.findElement(doc, "RequestedSecurityToken",
                                                FederationConstants.WS_TRUST_2005_02_NS);
    }
    e.appendChild(token);
    return DOM2Writer.nodeToString(doc);
}
 
Example 13
Source Project: steady   Source File: SAML1CallbackHandler.java    License: Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof SAMLCallback) {
            SAMLCallback callback = (SAMLCallback) callbacks[i];
            callback.setSamlVersion(SAMLVersion.VERSION_11);
            SubjectBean subjectBean = 
                new SubjectBean(
                    subjectName, subjectQualifier, confirmationMethod
                );
            if (SAML1Constants.CONF_HOLDER_KEY.equals(confirmationMethod)) {
                try {
                    KeyInfoBean keyInfo = createKeyInfo();
                    subjectBean.setKeyInfo(keyInfo);
                } catch (Exception ex) {
                    throw new IOException("Problem creating KeyInfo: " +  ex.getMessage());
                }
            }
            createAndSetStatement(subjectBean, callback);
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example 14
Source Project: steady   Source File: WSSUsernameCallbackHandler.java    License: Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof DelegationCallback) {
            DelegationCallback callback = (DelegationCallback) callbacks[i];
            Message message = callback.getCurrentMessage();
            
            String username = 
                (String)message.getContextualProperty(SecurityConstants.USERNAME);
            if (username != null) {
                Node contentNode = message.getContent(Node.class);
                Document doc = null;
                if (contentNode != null) {
                    doc = contentNode.getOwnerDocument();
                } else {
                    doc = DOMUtils.createDocument();
                }
                UsernameToken usernameToken = createWSSEUsernameToken(username, doc);
                callback.setToken(usernameToken.getElement());
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example 15
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(username);
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(password.toCharArray());
        } else if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            rcb.setText(rcb.getDefaultText());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
 
Example 16
Source Project: cxf-fediz   Source File: LoginHintHomeRealmDiscovery.java    License: Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException,
    UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof HomeRealmCallback) {
            HomeRealmCallback callback = (HomeRealmCallback) callbacks[i];
            final String loginHint = (String)callback.getRequest().getParameter("login_hint");
            if (loginHint == null || loginHint.isEmpty()) {
                LOG.debug("No login_hint found in request to set home realm");
            } else {
                String[] homeRealm = loginHint.split("@");
                if (homeRealm.length == 2) {
                    LOG.debug("Home realm '{}' found in request", StringEscapeUtils.escapeHtml4(homeRealm[1]));
                    callback.setHomeRealm(homeRealm[1]);
                } else {
                    LOG.warn("login_hint is not an email address: {}", StringEscapeUtils.escapeHtml4(loginHint));
                }
            }
        } else {
            LOG.warn("Callback is not an instance of HomeRealmCallback: {}", callbacks[i]);
        }
    }
}
 
Example 17
Source Project: steady   Source File: SAML1CallbackHandler.java    License: Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof SAMLCallback) {
            SAMLCallback callback = (SAMLCallback) callbacks[i];
            callback.setSamlVersion(SAMLVersion.VERSION_11);
            SubjectBean subjectBean = 
                new SubjectBean(
                    subjectName, subjectQualifier, confirmationMethod
                );
            if (SAML1Constants.CONF_HOLDER_KEY.equals(confirmationMethod)) {
                try {
                    KeyInfoBean keyInfo = createKeyInfo();
                    subjectBean.setKeyInfo(keyInfo);
                } catch (Exception ex) {
                    throw new IOException("Problem creating KeyInfo: " +  ex.getMessage());
                }
            }
            createAndSetStatement(subjectBean, callback);
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example 18
Source Project: tomee   Source File: CustomPasswordHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

    if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) {
        // TODO get the password from the users.properties if possible
        pc.setPassword("waterfall");

    } else if (pc.getUsage() == WSPasswordCallback.DECRYPT) {
        pc.setPassword("serverPassword");

    } else if (pc.getUsage() == WSPasswordCallback.SIGNATURE) {
        pc.setPassword("serverPassword");

    }
}
 
Example 19
Source Project: steady   Source File: SAML2CallbackHandler.java    License: Apache License 2.0 6 votes vote down vote up
public void handle(Callback[] callbacks)
    throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof SAMLCallback) {
            SAMLCallback callback = (SAMLCallback) callbacks[i];
            callback.setSamlVersion(SAMLVersion.VERSION_20);
            SubjectBean subjectBean = 
                new SubjectBean(
                    subjectName, subjectQualifier, confirmationMethod
                );
            if (SAML2Constants.CONF_HOLDER_KEY.equals(confirmationMethod)) {
                try {
                    KeyInfoBean keyInfo = createKeyInfo();
                    subjectBean.setKeyInfo(keyInfo);
                } catch (Exception ex) {
                    throw new IOException("Problem creating KeyInfo: " +  ex.getMessage());
                }
            }
            callback.setSubject(subjectBean);
            createAndSetStatement(null, callback);
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
 
Example 20
Source Project: cxf   Source File: KeystorePasswordCallback.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * It attempts to get the password from the private
 * alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];
        if (pc.getUsage() == WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD) {
            pc.setPassword("this-is-a-secret");
        } else {
            String pass = passwords.get(pc.getIdentifier());
            if (pass != null) {
                pc.setPassword(pass);
                return;
            }
            pc.setPassword("password");
        }
    }
}
 
Example 21
Source Project: unitime   Source File: KerberosAuthenticateModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
	iHandler.handle(callbacks);
	if (iRealm != null)
		for (Callback callback : callbacks) {
			if (callback instanceof NameCallback) {
				NameCallback nc = (NameCallback) callback;
				if (nc.getName() != null && !nc.getName().contains("@"))
					nc.setName(nc.getName() + "@" + iRealm);
			}
		}
}
 
Example 22
Source Project: cxf   Source File: UTPasswordCallback.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Here, we attempt to get the password from the private
 * alias/passwords map.
 */
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
            return;
        }
    }
}
 
Example 23
Source Project: steady   Source File: TestPwdCallback.java    License: Apache License 2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];

        String pass = passwords.get(pc.getIdentifier());
        if (pass != null) {
            pc.setPassword(pass);
        }
    }
}
 
Example 24
Source Project: java-dcp-client   Source File: AuthHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Handles the SASL defined callbacks to set user and password (the {@link CallbackHandler} interface).
 */
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
  for (Callback callback : callbacks) {
    if (callback instanceof NameCallback) {
      ((NameCallback) callback).setName(username);
    } else if (callback instanceof PasswordCallback) {
      ((PasswordCallback) callback).setPassword(password.toCharArray());
    } else {
      throw new AuthenticationException("SASLClient requested unsupported callback: " + callback);
    }
  }
}
 
Example 25
Source Project: Bats   Source File: KerberosAuth.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{
  for (Callback callback : callbacks) {
    if (callback instanceof NameCallback) {
      NameCallback nameCallback = (NameCallback)callback;
      nameCallback.setName(principal);
    } else if (callback instanceof PasswordCallback) {
      PasswordCallback passwordCallback = (PasswordCallback)callback;
      passwordCallback.setPassword(password);
    }
  }
}
 
Example 26
Source Project: sakai   Source File: NullCallbackHandler.java    License: Educational Community License v2.0 5 votes vote down vote up
public void handle(Callback[] callbacks) throws IOException,
		UnsupportedCallbackException {
	for (Callback callback: callbacks) {
		throw new UnsupportedCallbackException(callback, "Can't handle any callbacks");
	}

}
 
Example 27
Source Project: peer-os   Source File: ConsoleCallbackHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Handles the callbacks.
 *
 * @param callbacks The callbacks to handle
 *
 * @throws UnsupportedCallbackException If the console is not available or other than PasswordCallback is supplied
 */
@Override
public void handle( Callback[] callbacks ) throws IOException, UnsupportedCallbackException
{
    Console cons = System.console();
    if ( cons == null && password == null )
    {
        throw new UnsupportedCallbackException( callbacks[0], "Console is not available" );
    }
    for ( int i = 0; i < callbacks.length; i++ )
    {
        if ( callbacks[i] instanceof PasswordCallback )
        {
            if ( password == null )
            {
                //It is used instead of cons.readPassword(prompt), because the prompt may contain '%' characters
                ( ( PasswordCallback ) callbacks[i] ).setPassword(
                        cons.readPassword( "%s", ( ( PasswordCallback ) callbacks[i] ).getPrompt() ) );
            }
            else
            {
                ( ( PasswordCallback ) callbacks[i] ).setPassword( password );
            }
        }
        else
        {
            throw new UnsupportedCallbackException( callbacks[i] );
        }
    }
}
 
Example 28
Source Project: tomee   Source File: OpenEJBJaasPasswordAuthenticator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean authenticate(final String username, final String password, final ServerSession session) {
    try {
        final Subject subject = new Subject();
        final LoginContext loginContext = new LoginContext(getDomain(), subject, new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (final Callback callback : callbacks) {
                    if (callback instanceof NameCallback) {
                        ((NameCallback) callback).setName(username);
                    } else if (callback instanceof PasswordCallback) {
                        ((PasswordCallback) callback).setPassword(password.toCharArray());
                    } else {
                        throw new UnsupportedCallbackException(callback);
                    }
                }
            }
        });
        loginContext.login();

        session.setAttribute(USERNAME_KEY, username);
        session.setAttribute(LOGIN_CONTEXT_KEY, loginContext);
        return true;
    } catch (Exception e) {
        LOGGER.debug("can't log using username '" + username + "'", e);
        return false;
    }
}
 
Example 29
public void handle(final Callback[] callbacks)
    throws UnsupportedCallbackException {
    for (final Callback callback : callbacks) {
        if (callback.getClass().equals(NameCallback.class)) {
            ((NameCallback) callback).setName(this.userName);
        } else if (callback.getClass().equals(PasswordCallback.class)) {
            ((PasswordCallback) callback).setPassword(this.password
                .toCharArray());
        } else {
            throw new UnsupportedCallbackException(callback,
                "Unrecognized Callback");
        }
    }
}
 
Example 30
Source Project: openjdk-8-source   Source File: P11KeyStore.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void handle(Callback[] callbacks)
        throws IOException, UnsupportedCallbackException {
    if (!(callbacks[0] instanceof PasswordCallback)) {
        throw new UnsupportedCallbackException(callbacks[0]);
    }
    PasswordCallback pc = (PasswordCallback)callbacks[0];
    pc.setPassword(password);  // this clones the password if not null
}