Search in sources :

Example 61 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project cxf by apache.

the class IssueUnitTest method processToken.

private List<WSSecurityEngineResult> processToken(SecurityToken token) throws Exception {
    RequestData requestData = new RequestData();
    requestData.setDisableBSPEnforcement(true);
    CallbackHandler callbackHandler = new org.apache.cxf.systest.sts.common.CommonCallbackHandler();
    requestData.setCallbackHandler(callbackHandler);
    Crypto crypto = CryptoFactory.getInstance("serviceKeystore.properties");
    requestData.setDecCrypto(crypto);
    requestData.setSigVerCrypto(crypto);
    requestData.setWsDocInfo(new WSDocInfo(token.getToken().getOwnerDocument()));
    Processor processor = new SAMLTokenProcessor();
    return processor.handleToken(token.getToken(), requestData);
}
Also used : WSDocInfo(org.apache.wss4j.dom.WSDocInfo) CommonCallbackHandler(org.apache.cxf.systest.sts.common.CommonCallbackHandler) CallbackHandler(javax.security.auth.callback.CallbackHandler) Crypto(org.apache.wss4j.common.crypto.Crypto) CommonCallbackHandler(org.apache.cxf.systest.sts.common.CommonCallbackHandler) SAMLTokenProcessor(org.apache.wss4j.dom.processor.SAMLTokenProcessor) Processor(org.apache.wss4j.dom.processor.Processor) RequestData(org.apache.wss4j.dom.handler.RequestData) SAMLTokenProcessor(org.apache.wss4j.dom.processor.SAMLTokenProcessor)

Example 62 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project cxf by apache.

the class WSDLGetAuthenticatorInterceptor method doAuthenticate.

public Subject doAuthenticate(final String username, final String password) {
    try {
        Subject subject = new Subject();
        LoginContext loginContext = new LoginContext(getContextName(), subject, new CallbackHandler() {

            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (int i = 0; i < callbacks.length; i++) {
                    if (callbacks[i] instanceof NameCallback) {
                        ((NameCallback) callbacks[i]).setName(username);
                    } else if (callbacks[i] instanceof PasswordCallback) {
                        ((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
                    } else {
                        throw new UnsupportedCallbackException(callbacks[i]);
                    }
                }
            }
        });
        loginContext.login();
        return subject;
    } catch (FailedLoginException e) {
        LOG.log(Level.FINE, "Login failed ", e);
        return null;
    } catch (AccountException e) {
        LOG.log(Level.WARNING, "Account failure ", e);
        return null;
    } catch (GeneralSecurityException e) {
        LOG.log(Level.SEVERE, "General Security Exception ", e);
        return null;
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) LoginContext(javax.security.auth.login.LoginContext) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) FailedLoginException(javax.security.auth.login.FailedLoginException) AccountException(javax.security.auth.login.AccountException) GeneralSecurityException(java.security.GeneralSecurityException) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Subject(javax.security.auth.Subject)

Example 63 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project cxf by apache.

the class STSUnitTest method processToken.

private List<WSSecurityEngineResult> processToken(SecurityToken token) throws Exception {
    RequestData requestData = new RequestData();
    CallbackHandler callbackHandler = new CommonCallbackHandler();
    requestData.setCallbackHandler(callbackHandler);
    Crypto crypto = CryptoFactory.getInstance("clientKeystore.properties", this.getClass().getClassLoader());
    requestData.setSigVerCrypto(crypto);
    requestData.setWsDocInfo(new WSDocInfo(token.getToken().getOwnerDocument()));
    Processor processor = new SAMLTokenProcessor();
    return processor.handleToken(token.getToken(), requestData);
}
Also used : WSDocInfo(org.apache.wss4j.dom.WSDocInfo) CallbackHandler(javax.security.auth.callback.CallbackHandler) Crypto(org.apache.wss4j.common.crypto.Crypto) Processor(org.apache.wss4j.dom.processor.Processor) SAMLTokenProcessor(org.apache.wss4j.dom.processor.SAMLTokenProcessor) RequestData(org.apache.wss4j.dom.handler.RequestData) SAMLTokenProcessor(org.apache.wss4j.dom.processor.SAMLTokenProcessor)

Example 64 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project cxf by apache.

the class STSRESTTest method processToken.

private List<WSSecurityEngineResult> processToken(Element assertionElement) throws Exception {
    RequestData requestData = new RequestData();
    requestData.setDisableBSPEnforcement(true);
    CallbackHandler callbackHandler = new org.apache.cxf.systest.sts.common.CommonCallbackHandler();
    requestData.setCallbackHandler(callbackHandler);
    Crypto crypto = CryptoFactory.getInstance("serviceKeystore.properties");
    requestData.setDecCrypto(crypto);
    requestData.setSigVerCrypto(crypto);
    requestData.setWsDocInfo(new WSDocInfo(assertionElement.getOwnerDocument()));
    Processor processor = new SAMLTokenProcessor();
    return processor.handleToken(assertionElement, requestData);
}
Also used : WSDocInfo(org.apache.wss4j.dom.WSDocInfo) CallbackHandler(javax.security.auth.callback.CallbackHandler) Crypto(org.apache.wss4j.common.crypto.Crypto) SAMLTokenProcessor(org.apache.wss4j.dom.processor.SAMLTokenProcessor) Processor(org.apache.wss4j.dom.processor.Processor) RequestData(org.apache.wss4j.dom.handler.RequestData) SAMLTokenProcessor(org.apache.wss4j.dom.processor.SAMLTokenProcessor)

Example 65 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project cxf by apache.

the class AbstractBindingBuilder method getPassword.

protected String getPassword(String userName, Assertion info, int usage) {
    // Then try to get the password from the given callback handler
    Object o = SecurityUtils.getSecurityPropertyValue(SecurityConstants.CALLBACK_HANDLER, message);
    CallbackHandler handler = null;
    try {
        handler = SecurityUtils.getCallbackHandler(o);
        if (handler == null) {
            // Don't unassert for signature as we might get the password from the crypto properties
            if (usage == WSPasswordCallback.SIGNATURE) {
                LOG.info("No CallbackHandler available to retrieve a password. We will now try the crypto " + "properties file for a private password");
            } else {
                unassertPolicy(info, "No callback handler and no password available");
            }
            return null;
        }
    } catch (Exception ex) {
        // Don't unassert for signature as we might get the password from the crypto properties
        if (usage == WSPasswordCallback.SIGNATURE) {
            LOG.info("No CallbackHandler available to retrieve a password. We will now try the crypto " + "properties file for a private password");
        } else {
            unassertPolicy(info, "No callback handler and no password available");
        }
        return null;
    }
    WSPasswordCallback[] cb = { new WSPasswordCallback(userName, usage) };
    try {
        handler.handle(cb);
    } catch (Exception e) {
        unassertPolicy(info, e);
    }
    // get the password
    return cb[0].getPassword();
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) AttachmentCallbackHandler(org.apache.cxf.ws.security.wss4j.AttachmentCallbackHandler) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) SOAPException(javax.xml.soap.SOAPException) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) XMLStreamException(javax.xml.stream.XMLStreamException) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Aggregations

CallbackHandler (javax.security.auth.callback.CallbackHandler)274 Crypto (org.apache.wss4j.common.crypto.Crypto)82 IOException (java.io.IOException)75 Callback (javax.security.auth.callback.Callback)73 Element (org.w3c.dom.Element)70 Subject (javax.security.auth.Subject)68 PasswordCallback (javax.security.auth.callback.PasswordCallback)63 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)61 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)60 Document (org.w3c.dom.Document)60 LoginContext (javax.security.auth.login.LoginContext)55 NameCallback (javax.security.auth.callback.NameCallback)51 LoginException (javax.security.auth.login.LoginException)44 Principal (java.security.Principal)42 ReceivedToken (org.apache.cxf.sts.request.ReceivedToken)42 TokenValidator (org.apache.cxf.sts.token.validator.TokenValidator)38 SAMLTokenValidator (org.apache.cxf.sts.token.validator.SAMLTokenValidator)36 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)34 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)32