Search in sources :

Example 1 with Saml2BearerGrant

use of org.apache.cxf.rs.security.oauth2.grants.saml.Saml2BearerGrant in project cxf by apache.

the class JAXRSOAuth2Test method testSAML2BearerGrant.

@Test
public void testSAML2BearerGrant() throws Exception {
    String address = "https://localhost:" + PORT + "/oauth2/token";
    WebClient wc = createWebClient(address);
    Crypto crypto = new CryptoLoader().loadCrypto(CRYPTO_RESOURCE_PROPERTIES);
    SelfSignInfo signInfo = new SelfSignInfo(crypto, "alice", "password");
    SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(false);
    String audienceURI = "https://localhost:" + PORT + "/oauth2/token";
    samlCallbackHandler.setAudience(audienceURI);
    SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(samlCallbackHandler, signInfo);
    Document doc = DOMUtils.newDocument();
    Element assertionElement = assertionWrapper.toDOM(doc);
    String assertion = DOM2Writer.nodeToString(assertionElement);
    Saml2BearerGrant grant = new Saml2BearerGrant(assertion);
    ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer("alice", "alice"), grant, false);
    assertNotNull(at.getTokenKey());
}
Also used : SelfSignInfo(org.apache.cxf.rs.security.saml.SAMLUtils.SelfSignInfo) SamlCallbackHandler(org.apache.cxf.systest.jaxrs.security.oauth2.common.SamlCallbackHandler) Crypto(org.apache.wss4j.common.crypto.Crypto) Saml2BearerGrant(org.apache.cxf.rs.security.oauth2.grants.saml.Saml2BearerGrant) Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) CryptoLoader(org.apache.cxf.rs.security.common.CryptoLoader) Element(org.w3c.dom.Element) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) Document(org.w3c.dom.Document) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

WebClient (org.apache.cxf.jaxrs.client.WebClient)1 CryptoLoader (org.apache.cxf.rs.security.common.CryptoLoader)1 Consumer (org.apache.cxf.rs.security.oauth2.client.Consumer)1 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)1 Saml2BearerGrant (org.apache.cxf.rs.security.oauth2.grants.saml.Saml2BearerGrant)1 SelfSignInfo (org.apache.cxf.rs.security.saml.SAMLUtils.SelfSignInfo)1 SamlCallbackHandler (org.apache.cxf.systest.jaxrs.security.oauth2.common.SamlCallbackHandler)1 Crypto (org.apache.wss4j.common.crypto.Crypto)1 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1