首页 > 解决方案 > 如何使用从 wsdl 生成的 jaxws-wsimport 发送 saml 请求

问题描述

        SecurityTokenService service = new SecurityTokenService();
        SecurityTokenServicePortTypeIssue port = service.getISTSIssue();
        // TODO initialize WS operation arguments here
        RequestSecurityTokenType issueRequest = new RequestSecurityTokenType();

        LifetimeType lifetime = new LifetimeType();

        /*
        * Derive the token creation date and time. Use a GregorianCalendar to establish the current time, then use a DatatypeFactory to map the time data to XML. */
        DatatypeFactory dtFactory = DatatypeFactory.newInstance();
        GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        XMLGregorianCalendar xmlCalendar = dtFactory.newXMLGregorianCalendar(cal);
        AttributedDateTime created = new AttributedDateTime();
        created.setValue(xmlCalendar.toXMLFormat());
        /*
        * Specify a time interval for token expiration (specified in milliseconds).
         */
        AttributedDateTime expires = new AttributedDateTime();
        xmlCalendar.add(dtFactory.newDuration(30 * 60 * 1000));
        expires.setValue(xmlCalendar.toXMLFormat());

        /*
         * Set the created and expires fields in the lifetime object.
         */
        lifetime.setCreated(created);
        lifetime.setExpires(expires);

        /*
        * Set the token request fields.
         */
        issueRequest.setTokenType("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0");
        issueRequest.setRequestType("http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue");
        issueRequest.setLifetime(lifetime);
        RequestSecurityTokenResponseType result = port.issueRST(issueRequest);
        System.out.println("Result = " + result);
    } catch (Exception ex) {
        System.out.println(ex);
    }

请告诉我我做错了什么。这是我在运行此代码 com.sun.xml.internal.ws.fault.ServerSOAPFaultException 后遇到的错误:客户端从服务器收到 SOAP 错误:客户端错误请查看服务器日志以查找有关失败确切原因的更多详细信息。

标签: soapwsdlsaml

解决方案


推荐阅读