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

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


   
        // 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


                    // 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

    public SOAPHandler onStartChild(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context)
            throws SAXException {

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

        UsernameToken userToken = new UsernameToken(WSSConfig.getDefaultWSConfig().isPrecisionInMilliSeconds(),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

        if (!(value instanceof SecurityTokenMessage))
            throw new IOException("Can't serialize a " + value.getClass().getName() + " with a SecurityTokenMessageSerializer.");

        context.setPretty(false);

        SecurityTokenMessage tokenRequest = (SecurityTokenMessage) value;
        try {

            Element element = tokenRequest.getElement();
            if (name.equals(new QName(element.getNamespaceURI(), element.getLocalName()))) {
                AttributesImpl attrs = null;
                if (attributes != null)
                    attrs = new AttributesImpl(attributes);
                else
View Full Code Here

    // object as well.
    public RequestSecurityTokenResponse exchange(RequestSecurityToken tokenRequest) throws AxisFault {
        if (tokenRequest != null) {
            // Check the request type, this service only understands requests for token issue
            if (TrustConstants.REQUEST_ISSUE.equals(tokenRequest.getRequestType())) {
                SecurityTokenOrReference requestedToken = null;
                Document doc = tokenRequest.getDocument();
       
                // Check the token type being requested, this service returns only X509 certs or UsernameTokens
                if (TokenTypes.X509.equals(tokenRequest.getTokenType())) {
                    try {
                        // Construct an arbitrary x509 certificate (certificate content is hard-coded) any x509 request returns the same certificate
                        // A real service would do something more intelligent
                        InputStream inputStream = new ByteArrayInputStream("-----BEGIN CERTIFICATE-----\nMIICTTCCAbagAwIBAgIDC6tXMA0GCSqGSIb3DQEBBAUAMGExCzAJBgNVBAYTAkRFMQ8wDQYDVQQIEwZCYXllcm4xDzANBgNVBAcTBk11bmljaDEPMA0GA1UEChMGQXBhY2hlMQ4wDAYDVQQLEwVXU1M0SjEPMA0GA1UEAxMGV2VybmVyMB4XDTA0MDUxMDA2MjgzMloXDTA0MDUxMDE4MzMzMlowdjELMAkGA1UEBhMCREUxDzANBgNVBAgTBkJheWVybjEPMA0GA1UEBxMGTXVuaWNoMQ8wDQYDVQQKEwZBcGFjaGUxDjAMBgNVBAsTBVdTUzRKMQ8wDQYDVQQDEwZXZXJuZXIxEzARBgNVBAMTCjEzNDU1MDc0NzQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJbir9ayJesk3Yj+L1gDlS8TbtEj5DYLMhIYDA/Ycef2WEQ+pNIPTpeZ27SYEgf8Kmxpt4HHE5WJ8M9wnpB6EDQwi8vIQLTkaemJHGuWH8rbFY4CwFtQKEro63+agiSzbWZkpOFX4RFyX/Y5lOgZcW0q0yhumG2ZdMKViS81gx4BAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAPxYMCzAIoe0/DhT2NPpfl8+3vHV33YIbzlaejoV47KeR9IjPvKNS3PK0Mke3eKgJo/11DplnVpx9inKYaatPT/ZRz0eJ1+oTPe1kRYMDhO/OWCZhvVWQZPA9M8TWrDWJKwa6HlEmsbZGMnoGwEQ+7S3eD9TsqFf83CD+6Yr8wkM=\n-----END CERTIFICATE-----".getBytes());
                        CertificateFactory cf = CertificateFactory.getInstance("X.509");
                        X509Certificate cert = (X509Certificate) cf.generateCertificate(inputStream);
           
                        // Add the cert to a <BinarySecurityToken> element
                        X509Security binaryToken = new X509Security(doc);
                        binaryToken.setX509Certificate(cert);
           
                        // Set the <BinarySecurityToken> as the <RequestedToken> in our response
                        requestedToken = new SecurityTokenOrReference(binaryToken);
                    } catch (Exception e) {
                        throw new AxisFault("Could not create X.509 Security Token: " + e.getMessage());
                    }
                } else if (TokenTypes.USERNAME.equals(tokenRequest.getTokenType())) {
                    // Create an arbitrary, fixed UsernameToken to return if the client requests one
                    // A real security token service would do something more intelligent
                    UsernameToken userToken = new UsernameToken(WSSConfig.getDefaultWSConfig().isPrecisionInMilliSeconds(),doc);
                    userToken.setName("bob");
                    userToken.setPassword("bobspass");
         
                    // Create a new SecurityTokenOrReference object to use for the <RequestedToken> element
                    // As the class name implies SecurityTokenOrReference objects can hold either a real security token element
                    // 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);
       
View Full Code Here

   
        // 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);
 
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();
View Full Code Here

   
        // 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);
 
View Full Code Here

    // object as well.
    public RequestSecurityTokenResponse exchange(RequestSecurityToken tokenRequest) throws AxisFault {
        if (tokenRequest != null) {
            // Check the request type, this service only understands requests for token issue
            if (TrustConstants.REQUEST_ISSUE.equals(tokenRequest.getRequestType())) {
                SecurityTokenOrReference requestedToken = null;
                Document doc = tokenRequest.getDocument();
       
                // Check the token type being requested, this service returns only X509 certs or UsernameTokens
                if (TokenTypes.X509.equals(tokenRequest.getTokenType())) {
                    try {
                        // Construct an arbitrary x509 certificate (certificate content is hard-coded) any x509 request returns the same certificate
                        // A real service would do something more intelligent
                        InputStream inputStream = new ByteArrayInputStream("-----BEGIN CERTIFICATE-----\nMIICTTCCAbagAwIBAgIDC6tXMA0GCSqGSIb3DQEBBAUAMGExCzAJBgNVBAYTAkRFMQ8wDQYDVQQIEwZCYXllcm4xDzANBgNVBAcTBk11bmljaDEPMA0GA1UEChMGQXBhY2hlMQ4wDAYDVQQLEwVXU1M0SjEPMA0GA1UEAxMGV2VybmVyMB4XDTA0MDUxMDA2MjgzMloXDTA0MDUxMDE4MzMzMlowdjELMAkGA1UEBhMCREUxDzANBgNVBAgTBkJheWVybjEPMA0GA1UEBxMGTXVuaWNoMQ8wDQYDVQQKEwZBcGFjaGUxDjAMBgNVBAsTBVdTUzRKMQ8wDQYDVQQDEwZXZXJuZXIxEzARBgNVBAMTCjEzNDU1MDc0NzQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJbir9ayJesk3Yj+L1gDlS8TbtEj5DYLMhIYDA/Ycef2WEQ+pNIPTpeZ27SYEgf8Kmxpt4HHE5WJ8M9wnpB6EDQwi8vIQLTkaemJHGuWH8rbFY4CwFtQKEro63+agiSzbWZkpOFX4RFyX/Y5lOgZcW0q0yhumG2ZdMKViS81gx4BAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAPxYMCzAIoe0/DhT2NPpfl8+3vHV33YIbzlaejoV47KeR9IjPvKNS3PK0Mke3eKgJo/11DplnVpx9inKYaatPT/ZRz0eJ1+oTPe1kRYMDhO/OWCZhvVWQZPA9M8TWrDWJKwa6HlEmsbZGMnoGwEQ+7S3eD9TsqFf83CD+6Yr8wkM=\n-----END CERTIFICATE-----".getBytes());
                        CertificateFactory cf = CertificateFactory.getInstance("X.509");
                        X509Certificate cert = (X509Certificate) cf.generateCertificate(inputStream);
           
                        // Add the cert to a <BinarySecurityToken> element
                        X509Security binaryToken = new X509Security(WSSConfig.getDefaultWSConfig(),doc);
                        binaryToken.setX509Certificate(cert);
           
                        // Set the <BinarySecurityToken> as the <RequestedToken> in our response
                        requestedToken = new SecurityTokenOrReference(binaryToken);
                    } catch (Exception e) {
                        throw new AxisFault("Could not create X.509 Security Token: " + e.getMessage());
                    }
                } else if (TokenTypes.USERNAME.equals(tokenRequest.getTokenType())) {
                    // Create an arbitrary, fixed UsernameToken to return if the client requests one
                    // A real security token service would do something more intelligent
                    UsernameToken userToken = new UsernameToken(WSSConfig.getDefaultWSConfig(),doc);
                    userToken.setName("bob");
                    userToken.setPassword("bobspass");
         
                    // Create a new SecurityTokenOrReference object to use for the <RequestedToken> element
                    // As the class name implies SecurityTokenOrReference objects can hold either a real security token element
                    // 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);
       
View Full Code Here

TOP

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

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.