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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations