Package org.apache.ws.sandbox.security.trust2

Examples of org.apache.ws.sandbox.security.trust2.SecurityTokenMessage


                // Set the TokenType of the response. To make clients happy we'll return a token of the type they requested
                tokenResponse.setTokenType(tokenRequest.getTokenType());
       
                // Add a Lifetime element to indicate to clients the lifetime of the token we're sending
                // In this case, we're giving the client the lifetime they asked for
                Lifetime lifetime = tokenRequest.getLifetime();
                tokenResponse.setLifetime(lifetime);

                // Check if the request included a custom element named <TestElement>
                // Note that a list of custom elements can be obtained by calling getCustomElements();
                if (tokenRequest.getCustomElement("http://testElementNs.testElementNs", "TestElement") != null) {
View Full Code Here


        // Set the desired Lifetime of the token being requested in this case to 250 seconds
        Date start = new Date();
        Date end = new Date();
        end.setTime(start.getTime() + 250 * 1000);
        tokenRequest.setLifetime(new Lifetime(wssConfig, doc, start, end));

        // Add a custom element of our own creation
        tokenRequest.addCustomElementNS("http://testElementNs.testElementNs", "te:TestElement");

        // Create a SOAP body and set the XML element of the token request (a <RequestSecurityToken> element)
View Full Code Here

        // Set the desired Lifetime of the token being requested in this case to 250 seconds
        Date start = new Date();
        Date end = new Date();
        end.setTime(start.getTime() + 250 * 1000);
        tokenRequest.setLifetime(new Lifetime(wssConfig, doc, start, end));

        // Add a custom element of our own creation
        tokenRequest.addCustomElementNS("http://testElementNs.testElementNs", "te:TestElement");

        // Create a SOAP body and set the XML element of the token request (a <RequestSecurityToken> element)
View Full Code Here

                // Set the TokenType of the response. To make clients happy we'll return a token of the type they requested
                tokenResponse.setTokenType(tokenRequest.getTokenType());
       
                // Add a Lifetime element to indicate to clients the lifetime of the token we're sending
                // In this case, we're giving the client the lifetime they asked for
                Lifetime lifetime = tokenRequest.getLifetime();
                tokenResponse.setLifetime(lifetime);

                // Check if the request included a custom element named <TestElement>
                // Note that a list of custom elements can be obtained by calling getCustomElements();
                if (tokenRequest.getCustomElement("http://testElementNs.testElementNs", "TestElement") != null) {
View Full Code Here

        SOAPEnvelope env = new SOAPEnvelope();
        Document doc = env.getAsDocument();
        WSSConfig wssConfig = WSSConfig.getDefaultWSConfig();

        // Create a new request object passing an XML document for element creation and the RequestType (in this case issue)
        RequestSecurityToken tokenRequest = new RequestSecurityToken(doc, TrustConstants.REQUEST_ISSUE);
   
        // Setting the context and the token type we want to be returned
        tokenRequest.setContext(new URI("http://context.context"));
        tokenRequest.setTokenType(TokenTypes.X509);
   
        // Construct a bunch of username tokens to be used as <Base> and <Supporting> elements
        UsernameToken userToken = new UsernameToken(wssConfig.isPrecisionInMilliSeconds(), doc);
        userToken.setName("bob");
        userToken.setPassword("bobspass");
        tokenRequest.setBase(new SecurityTokenOrReference(userToken));

        UsernameToken user2Token = new UsernameToken(wssConfig.isPrecisionInMilliSeconds(), doc);
        user2Token.setName("joe");
        user2Token.setPassword("bobspass");
        tokenRequest.addSupporting(new SecurityTokenOrReference(user2Token));

        UsernameToken user3Token = new UsernameToken(wssConfig.isPrecisionInMilliSeconds(), doc);
        user3Token.setName("mike");
        user3Token.setPassword("bobspass");
        tokenRequest.addSupporting(new SecurityTokenOrReference(user3Token));

        // Set the desired Lifetime of the token being requested in this case to 250 seconds
        Date start = new Date();
        Date end = new Date();
        end.setTime(start.getTime() + 250 * 1000);
        tokenRequest.setLifetime(new Lifetime(wssConfig, doc, start, end));

        // Add a custom element of our own creation
        tokenRequest.addCustomElementNS("http://testElementNs.testElementNs", "te:TestElement");

        // Create a SOAP body and set the XML element of the token request (a <RequestSecurityToken> element)
        // as its only child
        SOAPBodyElement sbe = new SOAPBodyElement(tokenRequest.getElement());

        // Add the body element to the SOAP envelope
        env.addBodyElement(sbe);

        System.out.println("\n============= Request ==============");
View Full Code Here

        SOAPEnvelope env = new SOAPEnvelope();
        Document doc = env.getAsDocument();
        WSSConfig wssConfig = WSSConfig.getDefaultWSConfig();

        // Create a new request object passing an XML document for element creation and the RequestType (in this case issue)
        RequestSecurityToken tokenRequest = new RequestSecurityToken(doc, TrustConstants.REQUEST_ISSUE);
   
        // Setting the context and the token type we want to be returned
        tokenRequest.setContext(new URI("http://context.context"));
        tokenRequest.setTokenType(TokenTypes.X509);
   
        // Construct a bunch of username tokens to be used as <Base> and <Supporting> elements
        UsernameToken userToken = new UsernameToken(wssConfig, doc);
        userToken.setName("bob");
        userToken.setPassword("bobspass");
        tokenRequest.setBase(new SecurityTokenOrReference(userToken));

        UsernameToken user2Token = new UsernameToken(wssConfig, doc);
        user2Token.setName("joe");
        user2Token.setPassword("bobspass");
        tokenRequest.addSupporting(new SecurityTokenOrReference(user2Token));

        UsernameToken user3Token = new UsernameToken(wssConfig, doc);
        user3Token.setName("mike");
        user3Token.setPassword("bobspass");
        tokenRequest.addSupporting(new SecurityTokenOrReference(user3Token));

        // Set the desired Lifetime of the token being requested in this case to 250 seconds
        Date start = new Date();
        Date end = new Date();
        end.setTime(start.getTime() + 250 * 1000);
        tokenRequest.setLifetime(new Lifetime(wssConfig, doc, start, end));

        // Add a custom element of our own creation
        tokenRequest.addCustomElementNS("http://testElementNs.testElementNs", "te:TestElement");

        // Create a SOAP body and set the XML element of the token request (a <RequestSecurityToken> element)
        // as its only child
        SOAPBodyElement sbe = new SOAPBodyElement(tokenRequest.getElement());

        // Add the body element to the SOAP envelope
        env.addBodyElement(sbe);

        System.out.println("\n============= Request ==============");
View Full Code Here

    public void onStartElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context)
            throws SAXException {

        try {
            tokenRequest = new RequestSecurityToken(context.getCurElement().getAsDOM(), context.getEnvelope().getAsDocument());
            value = tokenRequest;
        } catch (Exception e) {
            throw new SAXException("Exception while processing RequestSecurityToken startElement: " + e.getMessage());
        }
    }
View Full Code Here

                    // or a <SecurityTokenReference> element to a security token found elsewhere
                    requestedToken = new SecurityTokenOrReference(userToken);
                }
       
                // Create our response object, giving it an XML document object to use for element creation, along with our requestedToken object
                RequestSecurityTokenResponse tokenResponse = new RequestSecurityTokenResponse(doc, requestedToken);
       
                // Set the Context of the response, according to WS-Trust, this must be the same as the Context of the request
                tokenResponse.setContext(tokenRequest.getContext());
       
                // Set the TokenType of the response. To make clients happy we'll return a token of the type they requested
                tokenResponse.setTokenType(tokenRequest.getTokenType());
       
                // Add a Lifetime element to indicate to clients the lifetime of the token we're sending
                // In this case, we're giving the client the lifetime they asked for
                Lifetime lifetime = tokenRequest.getLifetime();
                tokenResponse.setLifetime(lifetime);

                // Check if the request included a custom element named <TestElement>
                // Note that a list of custom elements can be obtained by calling getCustomElements();
                if (tokenRequest.getCustomElement("http://testElementNs.testElementNs", "TestElement") != null) {
                    // If it did we'll add our own custom element to the response
                    tokenResponse.addCustomElementNS("http://testElementNs.testElementNs", "te:TestElementResponse");
                }
       
                // Return the response object. If our Axis Serializers are configured correctly, this should automatically get converted to XML
                return tokenResponse;
            }
View Full Code Here

   
        // Find the <RequestSecurityTokenResponse> element the SOAP body should contain
        SOAPBodyElement responseBody = response.getBodyByName(TrustConstants.WST_NS, TrustConstants.RESPONSE_TAG);

        // Construct a Java object from the XML
        RequestSecurityTokenResponse tokenResponse = new RequestSecurityTokenResponse(responseBody.getAsDOM());

        System.out.println("\n------- RequestSecurityTokenResponse object ------------- \n" + tokenResponse);
    }
View Full Code Here

        UsernameToken userToken = new UsernameToken(WSSConfig.getDefaultWSConfig(),doc);
        userToken.setName("bob");
        userToken.setPassword("bobspass");

        RequestSecurityTokenResponse tokenResponse = new RequestSecurityTokenResponse(doc, new SecurityTokenOrReference(userToken));
        tokenResponse.setContext(new URI("http://context.context"));
        tokenResponse.setTokenType(TokenTypes.USERNAME);
   
        /*
        Data data = new Data();
        Data data2 = new Data();
        data.stringMember = "String member";
        data.floatMember = new Float("1.23");
        data.dataMember = data2;
       
        data2.stringMember = "another str member";
        data2.floatMember = new Float("4.56");
        data2.dataMember = null;  // "data;" for loop-test of multi-refs
*/
        RPCParam arg2 = new RPCParam("", "struct", tokenResponse);
        RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[]{arg1, arg2});
        msg.addBodyElement(body);

        try {
            Reader reader = null;

            if (args.length == 0) {
                Writer stringWriter = new StringWriter();
                SerializationContext context = new SerializationContext(stringWriter, msgContext);

                TypeMappingRegistry reg = context.getTypeMappingRegistry();
                TypeMapping tm = (TypeMapping) reg.getTypeMapping(Constants.URI_SOAP11_ENC);
                if (tm == null) {
                    tm = (TypeMapping) reg.createTypeMapping();
                    reg.register(Constants.URI_DEFAULT_SOAP_ENC, tm);
                }
                tm.register(RequestSecurityTokenResponse.class, TrustConstants.RESPONSE_NAME, new RSTResponseSerializerFactory(), new RSTResponseDeserializerFactory());

                msg.output(context);

                String msgString = stringWriter.toString();
                System.out.println("Serialized msg:");
                System.out.println(msgString);

                System.out.println("-------");
                System.out.println("Testing deserialization...");

                reader = new StringReader(msgString);
            } else {
                reader = new FileReader(args[0]);
            }

            DeserializationContext dser = new DeserializationContext(new InputSource(reader), msgContext, org.apache.axis.Message.REQUEST);
            dser.parse();
            SOAPEnvelope env = dser.getEnvelope();
            //System.out.println("********\n" + DOM2Writer.nodeToString(env, true) + "\n********");
           
            RPCElement rpcElem = (RPCElement) env.getFirstBody();
            RPCParam struct = rpcElem.getParam("struct");
            if (struct == null)
                throw new Exception("No <struct> param");

            if (!(struct.getObjectValue() instanceof RequestSecurityTokenResponse)) {
                System.out.println("Not a RST object! ");
                System.out.println(struct.getValue());
                System.exit(1);
            }

            RequestSecurityTokenResponse val = (RequestSecurityTokenResponse) struct.getObjectValue();
            if (val == null)
                throw new Exception("No value for struct param");

            System.out.println(val.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.ws.sandbox.security.trust2.SecurityTokenMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.