Example usage for javax.xml.ws BindingProvider USERNAME_PROPERTY

List of usage examples for javax.xml.ws BindingProvider USERNAME_PROPERTY

Introduction

In this page you can find the example usage for javax.xml.ws BindingProvider USERNAME_PROPERTY.

Prototype

String USERNAME_PROPERTY

To view the source code for javax.xml.ws BindingProvider USERNAME_PROPERTY.

Click Source Link

Document

Standard property: User name for authentication.

Usage

From source file:Main.java

public static void setBasicHttpAuth(Object wsProxy, String username, String password) {
    javax.xml.ws.BindingProvider bp = (javax.xml.ws.BindingProvider) wsProxy /*port*/;
    Map<String, Object> context = bp.getRequestContext();
    context.put(BindingProvider.USERNAME_PROPERTY, username);
    context.put(BindingProvider.PASSWORD_PROPERTY, password);
}

From source file:com.fredhopper.core.connector.query.service.DefaultFasWebserviceFactory.java

private FASWebService createFasWebService() {
    final URL wsdlURL = getFredhopperWsdlUrl();
    final FASWebServiceService serviceService = new FASWebServiceService(wsdlURL, FH_SERVICE_QNAME);
    final FASWebService fasService = serviceService.getFASWebService();

    final Map<String, Object> rc = ((BindingProvider) fasService).getRequestContext();
    rc.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceUrl);
    rc.put(BindingProvider.USERNAME_PROPERTY, serviceUsername);
    rc.put(BindingProvider.PASSWORD_PROPERTY, servicePassword);
    LOG.info("Created FASWebService for url:" + serviceUrl + " serviceUsername:" + serviceUsername);
    return fasService;
}

From source file:whitelabel.cloud.wsclient.WebServiceAuthenticator.java

public void authenticateBasic(final Dispatch<SOAPMessage> dispatch, final String username,
        final String password) throws WsAuthenticationException {

    if (dispatch == null) {
        LOG.error(" SoapMessage dispatcher not defined");
        throw new WsAuthenticationException("SOAP_DISPATCHER_NOT_DEFINED");
    }/*from   w ww .j a v a2s  .  c o  m*/
    if (username == null || password == null || username.trim().length() == 0
            || password.trim().length() == 0) {
        LOG.error("Username: " + username + " password: " + password + " - invalid parameters");
        throw new WsAuthenticationException("INVALID_PARAMETERS");
    }
    dispatch.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
    dispatch.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
}

From source file:org.cloudml.connectors.FlexiantConnector.java

@SuppressWarnings("restriction")
public FlexiantConnector(String endPoint, String login, String secretKey) throws MalformedURLException {
    this.endpoint = endPoint;
    System.setProperty("jsse.enableSNIExtension", "false");

    journal.log(Level.INFO, ">> Connecting to Flexiant ...");

    URL url = ClassLoader.getSystemClassLoader().getResource("UserAdmin.wsdl");

    // Get the UserAPI
    UserAPI api = new UserAPI(url, new QName("http://extility.flexiant.net", "UserAPI"));

    // and set the service port on the service
    service = api.getUserServicePort();//from ww  w.j a  va2  s.  co m

    // Get the binding provider
    BindingProvider portBP = (BindingProvider) service;

    // and set the service endpoint
    portBP.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);

    journal.log(Level.INFO, ">> Authenticating ...");
    // and the caller's authentication details and password
    portBP.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, login);
    portBP.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, secretKey);

}

From source file:at.tfr.securefs.client.SecurefsFileServiceClient.java

public void run() {
    DateTime start = new DateTime();
    try {//from w w  w  . j av a2  s .c o  m
        FileService svc = new FileService(new URL(fileServiceUrl));
        BindingProvider binding = (BindingProvider) svc.getFileServicePort();
        binding.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
        binding.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);

        for (Path path : files) {

            if (write) {
                if (!path.toFile().exists()) {
                    System.err.println(Thread.currentThread() + ": NoSuchFile: " + path + " currentWorkdir="
                            + Paths.get("./").toAbsolutePath());
                    continue;
                }

                System.out.println(Thread.currentThread() + ": Sending file: " + start + " : " + path);
                svc.getFileServicePort().write(path.toString(),
                        IOUtils.toByteArray(Files.newInputStream(path)));
            }

            Path out = path.resolveSibling(
                    path.getFileName() + (asyncTest ? "." + Thread.currentThread().getId() : "") + ".out");

            if (read) {
                System.out.println(Thread.currentThread() + ": Reading file: " + new DateTime() + " : " + out);
                if (out.getParent() != null) {
                    Files.createDirectories(out.getParent());
                }

                byte[] arr = svc.getFileServicePort().read(path.toString());
                IOUtils.write(arr, Files.newOutputStream(out));
            }

            if (write && read) {
                long inputChk = FileUtils.checksumCRC32(path.toFile());
                long outputChk = FileUtils.checksumCRC32(out.toFile());
                if (inputChk != outputChk) {
                    throw new IOException(Thread.currentThread()
                            + ": Checksum Failed: failure to write/read: in=" + path + ", out=" + out);
                }
                System.out.println(Thread.currentThread() + ": Checked Checksums: " + new DateTime() + " : "
                        + inputChk + " / " + outputChk);
            }

            if (delete) {
                boolean deleted = svc.getFileServicePort().delete(path.toString());
                if (!deleted) {
                    throw new IOException(
                            Thread.currentThread() + ": Delete Failed: failure to delete: in=" + path);
                } else {
                    System.out.println(Thread.currentThread() + ": Deleted File: in=" + path);
                }
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException(t);
    }
}

From source file:it.govpay.ejb.ndp.util.wsclient.NodoPerPa.java

public PagamentiTelematiciRPT configuraClient(String azione) {
    PagamentiTelematiciRPT port = service.getPagamentiTelematiciRPTPort();

    if (ishttpBasicEnabled) {
        ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, httpBasicUser);
        ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, httpBasicPassword);
    }//from   www .ja  v  a 2  s. co m

    if (isSslEnabled) {
        ((BindingProvider) port).getRequestContext().put(
                "com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory",
                sslContext.getSocketFactory());
    }

    String urlString = url.toExternalForm();
    if (this.isConnettoreServizioRPTAzioneInUrl) {
        if (!urlString.endsWith("/"))
            urlString = urlString.concat("/");
        ((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                urlString.concat(azione));
    } else {
        ((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, urlString);
    }
    return port;
}

From source file:org.apache.cxf.systest.http_jetty.JettyDigestAuthTest.java

private HTTPConduit setupClient(boolean async) throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class);
    BindingProvider bp = (BindingProvider) greeter;
    ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor());
    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS);
    HTTPConduit cond = (HTTPConduit) ClientProxy.getClient(greeter).getConduit();
    HTTPClientPolicy client = new HTTPClientPolicy();
    cond.setClient(client);//from w ww .jav a2 s .c  o  m
    if (async) {
        if (cond instanceof AsyncHTTPConduit) {
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd");
            bp.getRequestContext().put(Credentials.class.getName(), creds);
            bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
            client.setAutoRedirect(true);
        } else {
            fail("Not an async conduit");
        }
    } else {
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
        cond.setAuthSupplier(new DigestAuthSupplier());
    }

    ClientProxy.getClient(greeter).getOutInterceptors()
            .add(new AbstractPhaseInterceptor<Message>(Phase.PRE_STREAM_ENDING) {

                public void handleMessage(Message message) throws Fault {
                    Map<String, ?> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
                    if (headers.containsKey("Proxy-Authorization")) {
                        throw new RuntimeException("Should not have Proxy-Authorization");
                    }
                }
            });
    client.setAllowChunking(false);
    return cond;
}

From source file:org.apache.cxf.systest.http_undertow.UndertowDigestAuthTest.java

private HTTPConduit setupClient(boolean async) throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class);
    BindingProvider bp = (BindingProvider) greeter;
    ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor());
    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS);
    HTTPConduit cond = (HTTPConduit) ClientProxy.getClient(greeter).getConduit();
    HTTPClientPolicy client = new HTTPClientPolicy();
    client.setConnectionTimeout(600000);
    client.setReceiveTimeout(600000);/*  w w w .  j  ava2  s  .  c om*/
    cond.setClient(client);
    if (async) {
        if (cond instanceof AsyncHTTPConduit) {
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd");
            bp.getRequestContext().put(Credentials.class.getName(), creds);
            bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
            client.setAutoRedirect(true);
        } else {
            fail("Not an async conduit");
        }
    } else {
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
        cond.setAuthSupplier(new DigestAuthSupplier());
    }

    ClientProxy.getClient(greeter).getOutInterceptors()
            .add(new AbstractPhaseInterceptor<Message>(Phase.PRE_STREAM_ENDING) {

                public void handleMessage(Message message) throws Fault {
                    Map<String, ?> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
                    if (headers.containsKey("Proxy-Authorization")) {
                        throw new RuntimeException("Should not have Proxy-Authorization");
                    }
                }
            });
    client.setAllowChunking(false);
    return cond;
}

From source file:com.mirth.connect.connectors.ws.WebServiceMessageDispatcher.java

private void processMessage(MessageObject mo) throws Exception {
    /*//  ww  w .  jav a  2s .c  o m
     * Initialize the dispatch object if it hasn't been initialized yet, or
     * create a new one if the connector properties have changed due to
     * variables.
     */
    createDispatch(mo);

    SOAPBinding soapBinding = (SOAPBinding) dispatch.getBinding();

    if (connector.isDispatcherUseAuthentication()) {
        dispatch.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, currentUsername);
        dispatch.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, currentPassword);
        logger.debug("Using authentication: username=" + currentUsername + ", password length="
                + currentPassword.length());
    }

    // See: http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528
    String soapAction = replacer.replaceValues(connector.getDispatcherSoapAction(), mo);

    if (StringUtils.isNotEmpty(soapAction)) {
        dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, soapAction);
    }

    // build the message
    logger.debug("Creating SOAP envelope.");
    String content = replacer.replaceValues(connector.getDispatcherEnvelope(), mo);
    Source source = new StreamSource(new StringReader(content));
    SOAPMessage message = soapBinding.getMessageFactory().createMessage();
    message.getSOAPPart().setContent(source);

    if (connector.isDispatcherUseMtom()) {
        soapBinding.setMTOMEnabled(true);

        List<String> attachmentIds = connector.getDispatcherAttachmentNames();
        List<String> attachmentContents = connector.getDispatcherAttachmentContents();
        List<String> attachmentTypes = connector.getDispatcherAttachmentTypes();

        for (int i = 0; i < attachmentIds.size(); i++) {
            String attachmentContentId = replacer.replaceValues(attachmentIds.get(i), mo);
            String attachmentContentType = replacer.replaceValues(attachmentTypes.get(i), mo);
            String attachmentContent = replacer.replaceValues(attachmentContents.get(i), mo);

            AttachmentPart attachment = message.createAttachmentPart();
            attachment.setBase64Content(new ByteArrayInputStream(attachmentContent.getBytes("UTF-8")),
                    attachmentContentType);
            attachment.setContentId(attachmentContentId);
            message.addAttachmentPart(attachment);
        }
    }

    message.saveChanges();

    // make the call
    String response = null;
    if (connector.isDispatcherOneWay()) {
        logger.debug("Invoking one way service...");
        dispatch.invokeOneWay(message);
        response = "Invoked one way operation successfully.";
    } else {
        logger.debug("Invoking web service...");
        SOAPMessage result = dispatch.invoke(message);
        response = sourceToXmlString(result.getSOAPPart().getContent());
    }
    logger.debug("Finished invoking web service, got result.");

    // process the result
    messageObjectController.setSuccess(mo, response, null);

    // send to reply channel
    if (connector.getDispatcherReplyChannelId() != null
            && !connector.getDispatcherReplyChannelId().equals("sink")) {
        new VMRouter().routeMessageByChannelId(connector.getDispatcherReplyChannelId(), response, true);
    }
}

From source file:net.bpelunit.framework.control.deploy.activevos9.ActiveVOSAdministrativeFunctions.java

private void setBasicAuthenticationForBindingProvider(Object port, String username, String password) {
    Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext();
    requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
    requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
}