Package org.picketlink.identity.federation.core.wstrust.wrappers

Examples of org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityToken


     * @throws Exception if an error occurs while running the test.
     */
    @Test
    public void testInvokeUnknownTokenType() throws Exception {
        // create a simple token request, asking for an "unknown" test token.
        RequestSecurityToken request = this.createRequest("testcontext", WSTrustConstants.ISSUE_REQUEST,
                "http://www.tokens.org/UnknownToken", null);

        Source requestMessage = this.createSourceFromRequest(request);

        // invoke the security token service.
View Full Code Here


     * @throws Exception if an error occurs while running the test.
     */
    @Test
    public void testInvalidIssueRequests() throws Exception {
        // lets create an issue request that container neither an applies-to nor a token type.
        RequestSecurityToken request = this.createRequest("testcontext", WSTrustConstants.ISSUE_REQUEST, null, null);
        Source requestMessage = this.createSourceFromRequest(request);

        // invoke the token service. A WSTrustException should be raised.
        try {
            this.tokenService.invoke(requestMessage);
            fail("An exception should have been raised by the security token service");
        } catch (WebServiceException we) {
            assertNotNull("Unexpected null cause", we.getCause());
            assertTrue("Unexpected cause type", we.getCause() instanceof WSTrustException);
            /*
             * assertEquals("Either AppliesTo or TokenType must be present in a security token request", we.getCause()
             * .getMessage());
             */
        }

        // a request that asks for a public key to be used as proof key will fail if the public key is not available.
        request.setTokenType(URI.create(SAMLUtil.SAML2_TOKEN_TYPE));
        request.setKeyType(URI.create(WSTrustConstants.KEY_TYPE_PUBLIC));
        requestMessage = this.createSourceFromRequest(request);

        try {
            this.tokenService.invoke(requestMessage);
            fail("An exception should have been raised by the security token service");
View Full Code Here

     * @throws Exception if an error occurs while running the test.
     */
    @Test
    public void testInvalidRenewRequests() throws Exception {
        // first create a request that doesn't have a renew target element.
        RequestSecurityToken request = this.createRequest("renewcontext", WSTrustConstants.RENEW_REQUEST,
                SAMLUtil.SAML2_TOKEN_TYPE, null);
        Source requestMessage = this.createSourceFromRequest(request);

        // invoke the token service.
        try {
            this.tokenService.invoke(requestMessage);
            fail("An exception should have been raised by the security token service");
        } catch (WebServiceException we) {
            Throwable t = we.getCause();
            assertNotNull("Unexpected null cause", t);
            assertTrue("Unexpected cause type", t instanceof WSTrustException);
            String msg = t.getMessage();
            if (msg.contains("PL00092: Null Value:renew target") == false)
                throw new RuntimeException("Unexpected exception message");
        }

        // a request with an empty renew target should also result in a failure.
        request.setRenewTarget(new RenewTargetType());
        requestMessage = this.createSourceFromRequest(request);
        try {
            this.tokenService.invoke(requestMessage);
            fail("An exception should have been raised by the security token service");
        } catch (WebServiceException we) {
            Throwable t = we.getCause();
            assertNotNull("Unexpected null cause", t);
            assertTrue("Unexpected cause type", t instanceof ParsingException);
            String msg = t.getMessage();
            if (msg.contains("Unable to parse token request: security token is null") == false)
                throw new RuntimeException("Unexpected exception message");
        }

        // a request to renew an unknown token (i.e. there's no provider can handle the token) should also fail.
        request.getRenewTarget().add(this.createUnknownToken());
        requestMessage = this.createSourceFromRequest(request);
        try {
            this.tokenService.invoke(requestMessage);
            fail("An exception should have been raised by the security token service");
        } catch (WebServiceException we) {
View Full Code Here

     * @throws Exception if an error occurs while running the test.
     */
    @Test
    public void testInvalidValidateRequests() throws Exception {
        // first create a request that doesn't have a validate target element.
        RequestSecurityToken request = this.createRequest("validatecontext", WSTrustConstants.VALIDATE_REQUEST,
                SAMLUtil.SAML2_TOKEN_TYPE, null);
        Source requestMessage = this.createSourceFromRequest(request);

        // invoke the token service.
        try {
            this.tokenService.invoke(requestMessage);
            fail("An exception should have been raised by the security token service");
        } catch (WebServiceException we) {
            Throwable t = we.getCause();
            assertNotNull("Unexpected null cause", t);
            assertTrue("Unexpected cause type", t instanceof WSTrustException);
            String msg = t.getMessage();
            if (msg.contains("request does not have a validate target. Unable to validate token") == false)
                throw new RuntimeException("Unexpected exception message");
        }

        // a request with an empty validate target should also result in a failure.
        request.setValidateTarget(new ValidateTargetType());
        requestMessage = this.createSourceFromRequest(request);
        try {
            this.tokenService.invoke(requestMessage);
            fail("An exception should have been raised by the security token service");
        } catch (WebServiceException we) {
            Throwable t = we.getCause();
            assertNotNull("Unexpected null cause", t);
            assertTrue("Unexpected cause type", t instanceof ParsingException);
            String msg = t.getMessage();
            if (msg.contains("Unable to parse token request: security token is null") == false)
                throw new RuntimeException("Unexpected exception message");
        }

        // a request to validate an unknown token (i.e. there's no provider can handle the token) should also fail.
        request.getValidateTarget().add(this.createUnknownToken());
        requestMessage = this.createSourceFromRequest(request);
        try {
            this.tokenService.invoke(requestMessage);
            Source responseMessage = this.tokenService.invoke(requestMessage);
            RequestSecurityTokenResponseCollection baseResponseColl = (RequestSecurityTokenResponseCollection) new WSTrustParser()
View Full Code Here

     * @throws Exception if an error occurs while running the test.
     */
    @Test
    public void testInvalidCancelRequests() throws Exception {
        // first create a request that doesn't have a cancel target element.
        RequestSecurityToken request = this.createRequest("cancelcontext", WSTrustConstants.CANCEL_REQUEST,
                SAMLUtil.SAML2_TOKEN_TYPE, null);
        Source requestMessage = this.createSourceFromRequest(request);

        // invoke the token service.
        try {
            this.tokenService.invoke(requestMessage);
            fail("An exception should have been raised by the security token service");
        } catch (WebServiceException we) {
            Throwable t = we.getCause();
            assertNotNull("Unexpected null cause", t);
            assertTrue("Unexpected cause type", t instanceof WSTrustException);
            String msg = t.getMessage();
            if (msg.contains("request does not have a cancel target. Unable to cancel token") == false)
                throw new RuntimeException("Unexpected exception message");
        }

        // a request with an empty cancel target should also result in a failure.
        request.setCancelTarget(new CancelTargetType());
        requestMessage = this.createSourceFromRequest(request);
        try {
            this.tokenService.invoke(requestMessage);
            fail("An exception should have been raised by the security token service");
        } catch (WebServiceException we) {
            Throwable t = we.getCause();
            assertNotNull("Unexpected null cause", t);
            assertTrue("Unexpected cause type", t instanceof ParsingException);
            String msg = t.getMessage();
            if (msg.contains("Unable to parse token request: security token is null") == false)
                throw new RuntimeException("Unexpected exception message");
        }

        // a request to cancel an unknown token (i.e. there's no provider can handle the token) should also fail.
        request.getCancelTarget().add(this.createUnknownToken());
        requestMessage = this.createSourceFromRequest(request);
        try {
            this.tokenService.invoke(requestMessage);
            fail("An exception should have been raised by the security token service");
        } catch (WebServiceException we) {
View Full Code Here

        assertNotNull("Request Security Token Collection is null?", requestCollection);

        List<RequestSecurityToken> tokens = requestCollection.getRequestSecurityTokens();
        assertEquals(2, tokens.size());

        RequestSecurityToken rst1 = tokens.get(0);
        assertEquals("validatecontext1", rst1.getContext());
        assertEquals(WSTrustConstants.BATCH_VALIDATE_REQUEST, rst1.getRequestType().toASCIIString());
        assertEquals(WSTrustConstants.RSTR_STATUS_TOKEN_TYPE, rst1.getTokenType().toASCIIString());

        RequestSecurityToken rst2 = tokens.get(1);
        assertEquals("validatecontext2", rst2.getContext());
        assertEquals(WSTrustConstants.BATCH_VALIDATE_REQUEST, rst2.getRequestType().toASCIIString());
        assertEquals(WSTrustConstants.RSTR_STATUS_TOKEN_TYPE, rst2.getTokenType().toASCIIString());

        // Now for the writing part
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WSTrustRequestWriter rstWriter = new WSTrustRequestWriter(baos);
View Full Code Here

     * @param tokenType a {@code String} that represents the requested token type.
     * @param appliesToString a {@code String} that represents the URL of a service provider.
     * @return the constructed {@code RequestSecurityToken} object.
     */
    private RequestSecurityToken createRequest(String context, String requestType, String tokenType, String appliesToString) {
        RequestSecurityToken request = new RequestSecurityToken();
        request.setContext(context);
        request.setRequestType(URI.create(requestType));
        if (tokenType != null)
            request.setTokenType(URI.create(tokenType));
        if (appliesToString != null)
            request.setAppliesTo(WSTrustUtil.createAppliesTo(appliesToString));
        return request;
    }
View Full Code Here

    public void testOnBehalfOfParsing() throws Exception {
        ClassLoader tcl = Thread.currentThread().getContextClassLoader();
        InputStream configStream = tcl.getResourceAsStream("parser/wst/wst-issue-onbehalfof.xml");

        WSTrustParser parser = new WSTrustParser();
        RequestSecurityToken requestToken = (RequestSecurityToken) parser.parse(configStream);

        assertEquals("testcontext", requestToken.getContext());
        assertEquals(WSTrustConstants.ISSUE_REQUEST, requestToken.getRequestType().toASCIIString());

        OnBehalfOfType onBehalfOf = requestToken.getOnBehalfOf();
        List<Object> theList = onBehalfOf.getAny();
        assertNotNull(theList);
        UsernameTokenType userNameToken = (UsernameTokenType) theList.get(0);
        assertEquals("id", userNameToken.getId());
        assertEquals("anotherduke", userNameToken.getUsername().getValue());
View Full Code Here

    public void testWST_ValidateSaml() throws Exception {
        ClassLoader tcl = Thread.currentThread().getContextClassLoader();
        InputStream configStream = tcl.getResourceAsStream("parser/wst/wst-validate-saml.xml");

        WSTrustParser parser = new WSTrustParser();
        RequestSecurityToken rst1 = (RequestSecurityToken) parser.parse(configStream);
        assertEquals("validatecontext", rst1.getContext());
        assertEquals(WSTrustConstants.VALIDATE_REQUEST, rst1.getRequestType().toASCIIString());
        assertEquals(WSTrustConstants.RSTR_STATUS_TOKEN_TYPE, rst1.getTokenType().toASCIIString());

        ValidateTargetType validateTarget = rst1.getValidateTarget();
        Element assertionElement = (Element) validateTarget.getAny().get(0);
        AssertionType assertion = SAMLUtil.fromElement(assertionElement);
        assertEquals("ID_654b6092-c725-40ea-8044-de453b59cb28", assertion.getID());

        // Now for the writing part
View Full Code Here

    public void testPublicCert() throws Exception {
        ClassLoader tcl = Thread.currentThread().getContextClassLoader();
        InputStream configStream = tcl.getResourceAsStream("parser/wst/wst-issue-public-certificate.xml");

        WSTrustParser parser = new WSTrustParser();
        RequestSecurityToken requestToken = (RequestSecurityToken) parser.parse(configStream);

        assertEquals("testcontext", requestToken.getContext());
        assertEquals(WSTrustConstants.ISSUE_REQUEST, requestToken.getRequestType().toASCIIString());

        AppliesTo appliesTo = requestToken.getAppliesTo();
        EndpointReferenceType endpoint = (EndpointReferenceType) appliesTo.getAny().get(0);
        assertEquals("http://services.testcorp.org/provider2", endpoint.getAddress().getValue());

        assertEquals("http://docs.oasis-open.org/ws-sx/ws-trust/200512/PublicKey", requestToken.getKeyType().toASCIIString());

        UseKeyType useKeyType = requestToken.getUseKey();
        Element certEl = (Element) useKeyType.getAny().get(0);

        assertEquals("ds:" + WSTRequestSecurityTokenParser.X509CERTIFICATE, certEl.getTagName());

        // Now for the writing part
View Full Code Here

TOP

Related Classes of org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityToken

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.