Search in sources :

Example 56 with ClientAccessToken

use of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken in project cxf by apache.

the class JAXRSOAuth2Test method testSAML2BearerAuthenticationInterceptor.

@Test
public void testSAML2BearerAuthenticationInterceptor() throws Exception {
    String address = "https://localhost:" + PORT + "/oauth2-auth/token";
    WebClient wc = createWebClientWithProps(address);
    ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new CustomGrant());
    assertNotNull(at.getTokenKey());
}
Also used : ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 57 with ClientAccessToken

use of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken in project cxf by apache.

the class JAXRSOAuth2Test method testSAML2BearerAuthenticationDirect.

@Test
public void testSAML2BearerAuthenticationDirect() throws Exception {
    String address = "https://localhost:" + PORT + "/oauth2-auth/token";
    WebClient wc = createWebClient(address);
    Crypto crypto = new CryptoLoader().loadCrypto(CRYPTO_RESOURCE_PROPERTIES);
    SelfSignInfo signInfo = new SelfSignInfo(crypto, "alice", "password");
    SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(true);
    samlCallbackHandler.setIssuer("alice");
    String audienceURI = "https://localhost:" + PORT + "/oauth2-auth/token";
    samlCallbackHandler.setAudience(audienceURI);
    SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(samlCallbackHandler, signInfo);
    Document doc = DOMUtils.newDocument();
    Element assertionElement = assertionWrapper.toDOM(doc);
    String assertion = DOM2Writer.nodeToString(assertionElement);
    String encodedAssertion = Base64UrlUtility.encode(assertion);
    Map<String, String> extraParams = new HashMap<>();
    extraParams.put(Constants.CLIENT_AUTH_ASSERTION_TYPE, Constants.CLIENT_AUTH_SAML2_BEARER);
    extraParams.put(Constants.CLIENT_AUTH_ASSERTION_PARAM, encodedAssertion);
    ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new CustomGrant(), extraParams);
    assertNotNull(at.getTokenKey());
}
Also used : SelfSignInfo(org.apache.cxf.rs.security.saml.SAMLUtils.SelfSignInfo) HashMap(java.util.HashMap) 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) SamlCallbackHandler(org.apache.cxf.systest.jaxrs.security.oauth2.common.SamlCallbackHandler) Crypto(org.apache.wss4j.common.crypto.Crypto) Test(org.junit.Test)

Example 58 with ClientAccessToken

use of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken in project cxf by apache.

the class JAXRSOAuth2Test method testTwoWayTLSAuthenticationCustomGrant.

@Test
public void testTwoWayTLSAuthenticationCustomGrant() throws Exception {
    String address = "https://localhost:" + PORT + "/oauth2/token";
    WebClient wc = createWebClient(address);
    ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new CustomGrant());
    assertNotNull(at.getTokenKey());
}
Also used : ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 59 with ClientAccessToken

use of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken in project cxf by apache.

the class JAXRSOAuth2Test method testJWTBearerAuthenticationDirect.

@Test
public void testJWTBearerAuthenticationDirect() throws Exception {
    String address = "https://localhost:" + PORT + "/oauth2-auth-jwt/token";
    WebClient wc = createWebClient(address);
    // Create the JWT Token
    String token = OAuth2TestUtils.createToken("resourceOwner", "alice", address, true, true);
    Map<String, String> extraParams = new HashMap<>();
    extraParams.put(Constants.CLIENT_AUTH_ASSERTION_TYPE, "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
    extraParams.put(Constants.CLIENT_AUTH_ASSERTION_PARAM, token);
    ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new CustomGrant(), extraParams);
    assertNotNull(at.getTokenKey());
}
Also used : HashMap(java.util.HashMap) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 60 with ClientAccessToken

use of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken in project cxf by apache.

the class JAXRSOAuth2Test method testBasicAuthClientCred.

@Test
public void testBasicAuthClientCred() throws Exception {
    String address = "https://localhost:" + PORT + "/oauth2/token";
    WebClient wc = createWebClient(address);
    ClientCredentialsGrant grant = new ClientCredentialsGrant();
    // Pass client_id & client_secret as form properties
    // (instead WebClient can be initialized with username & password)
    grant.setClientId("bob");
    grant.setClientSecret("bobPassword");
    try {
        OAuthClientUtils.getAccessToken(wc, grant);
        fail("Form based authentication is not supported");
    } catch (OAuthServiceException ex) {
        assertEquals(OAuthConstants.UNAUTHORIZED_CLIENT, ex.getError().getError());
    }
    ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer("bob", "bobPassword"), new ClientCredentialsGrant(), true);
    assertNotNull(at.getTokenKey());
}
Also used : Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException) ClientCredentialsGrant(org.apache.cxf.rs.security.oauth2.grants.clientcred.ClientCredentialsGrant) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)80 WebClient (org.apache.cxf.jaxrs.client.WebClient)62 URL (java.net.URL)44 Response (javax.ws.rs.core.Response)30 Form (javax.ws.rs.core.Form)20 Test (org.junit.Test)18 Book (org.apache.cxf.systest.jaxrs.security.Book)10 JwsJwtCompactConsumer (org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer)7 Consumer (org.apache.cxf.rs.security.oauth2.client.Consumer)7 OAuthJSONProvider (org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider)6 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)6 ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)5 JsonMapObjectProvider (org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider)5 TokenIntrospection (org.apache.cxf.rs.security.oauth2.common.TokenIntrospection)5 ClientRegistration (org.apache.cxf.rs.security.oauth2.services.ClientRegistration)5 ClientRegistrationResponse (org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse)5 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Produces (javax.ws.rs.Produces)3 Client (javax.ws.rs.client.Client)3