use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class CodeAuthSupplier method getAuthorization.
public String getAuthorization(AuthorizationPolicy authPolicy, URI currentURI, Message message, String fullHeader) {
if (code != null) {
synchronized (tokenSupplier) {
if (tokenSupplier.getClientAccessToken().getTokenKey() == null) {
WebClient wc = tokenSupplier.createAccessTokenServiceClient();
ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, tokenSupplier.getConsumer(), new AuthorizationCodeGrant(code));
code = null;
tokenSupplier.setClientAccessToken(at);
}
}
}
return tokenSupplier.getAuthorization(authPolicy, currentURI, message, fullHeader);
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class AccessTokenValidatorClient method validateAccessToken.
public AccessTokenValidation validateAccessToken(MessageContext mc, String authScheme, String authSchemeData, MultivaluedMap<String, String> extraProps) throws OAuthServiceException {
WebClient client = WebClient.fromClient(tokenValidatorClient, true);
MultivaluedMap<String, String> props = new MetadataMap<String, String>();
props.putSingle(OAuthConstants.AUTHORIZATION_SCHEME_TYPE, authScheme);
props.putSingle(OAuthConstants.AUTHORIZATION_SCHEME_DATA, authSchemeData);
if (extraProps != null) {
props.putAll(extraProps);
}
try {
return client.post(props, AccessTokenValidation.class);
} catch (WebApplicationException ex) {
throw new OAuthServiceException(ex);
}
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class CustomParameterTest method testCustomParameterToRESTInterface.
@org.junit.Test
public void testCustomParameterToRESTInterface() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CustomParameterTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
String address = "https://localhost:" + STSPORT + "/SecurityTokenServiceREST/token";
WebClient client = WebClient.create(address, busFile.toString());
client.type("application/xml").accept("application/xml");
// Create RequestSecurityToken
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
String namespace = STSUtils.WST_NS_05_12;
writer.writeStartElement("wst", "RequestSecurityToken", namespace);
writer.writeNamespace("wst", namespace);
writer.writeStartElement("wst", "RequestType", namespace);
writer.writeCharacters(namespace + "/Issue");
writer.writeEndElement();
writer.writeStartElement("wst", "TokenType", namespace);
writer.writeCharacters(SAML2_TOKEN_TYPE);
writer.writeEndElement();
writer.writeStartElement("wst", "Claims", namespace);
writer.writeAttribute("Dialect", "http://schemas.xmlsoap.org/ws/2005/05/identity");
writer.writeStartElement("ic", "ClaimType", "http://schemas.xmlsoap.org/ws/2005/05/identity");
writer.writeAttribute("Uri", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role");
writer.writeEndElement();
writer.writeEndElement();
// Add custom content to the RST
writer.writeStartElement("", "realm", "http://cxf.apache.org/custom");
writer.writeCharacters("custom-realm");
writer.writeEndElement();
writer.writeEndElement();
Response response = client.post(new DOMSource(writer.getDocument().getDocumentElement()));
RequestSecurityTokenResponseType securityResponse = response.readEntity(RequestSecurityTokenResponseType.class);
Element assertion = validateSAMLSecurityTokenResponse(securityResponse, true);
assertTrue(DOM2Writer.nodeToString(assertion).contains("admin-user"));
bus.shutdown(true);
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class JAASTest method doubleIt.
private static void doubleIt(String username, String password, String address, boolean authFailureExpected) {
final String configLocation = "org/apache/cxf/systest/sts/jaas/cxf-client.xml";
final int numToDouble = 25;
WebClient client = null;
if (username != null && password != null) {
client = WebClient.create(address, username, password, configLocation);
} else {
client = WebClient.create(address, configLocation);
}
client.type("text/plain").accept("text/plain");
try {
int resp = client.post(numToDouble, Integer.class);
if (authFailureExpected) {
throw new RuntimeException("Exception expected");
}
org.junit.Assert.assertEquals(2 * numToDouble, resp);
} catch (WebApplicationException ex) {
if (!authFailureExpected) {
throw new RuntimeException("Unexpected exception");
}
org.junit.Assert.assertEquals(500, ex.getResponse().getStatus());
}
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class STSRESTTest method testExplicitlyIssueSAML2TokenViaPOST.
@org.junit.Test
public void testExplicitlyIssueSAML2TokenViaPOST() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = STSRESTTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
String address = "https://localhost:" + STSPORT + "/SecurityTokenService/token";
WebClient client = WebClient.create(address, busFile.toString());
client.type("application/xml").accept("application/xml");
client.query("action", "issue");
// Create RequestSecurityToken
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
String namespace = STSUtils.WST_NS_05_12;
writer.writeStartElement("wst", "RequestSecurityToken", namespace);
writer.writeNamespace("wst", namespace);
writer.writeStartElement("wst", "RequestType", namespace);
writer.writeCharacters(namespace + "/Issue");
writer.writeEndElement();
writer.writeStartElement("wst", "TokenType", namespace);
writer.writeCharacters(SAML2_TOKEN_TYPE);
writer.writeEndElement();
writer.writeEndElement();
Response response = client.post(new DOMSource(writer.getDocument().getDocumentElement()));
RequestSecurityTokenResponseType securityResponse = response.readEntity(RequestSecurityTokenResponseType.class);
validateSAMLSecurityTokenResponse(securityResponse, true);
bus.shutdown(true);
}
Aggregations