use of org.keycloak.common.util.KeycloakUriBuilder in project keycloak by keycloak.
the class SamlProtocol method artifactRedirect.
/**
* Return an artifact through a redirect message
*
* @param redirectUri the redirect uri to the client
* @param artifact the artifact to send
* @param relayState the current relayState
* @return a redirect Response with the artifact
*/
private Response artifactRedirect(String redirectUri, String artifact, String relayState) {
KeycloakUriBuilder builder = KeycloakUriBuilder.fromUri(redirectUri).replaceQuery(null).queryParam(GeneralConstants.SAML_ARTIFACT_KEY, artifact);
if (relayState != null) {
builder.queryParam(GeneralConstants.RELAY_STATE, relayState);
}
URI uri = builder.build();
return Response.status(302).location(uri).header("Pragma", "no-cache").header("Cache-Control", "no-cache, no-store").build();
}
use of org.keycloak.common.util.KeycloakUriBuilder in project keycloak by keycloak.
the class BaseSAML2BindingBuilder method generateRedirectUri.
public URI generateRedirectUri(String samlParameterName, String redirectUri, Document document) throws ConfigurationException, ProcessingException, IOException {
KeycloakUriBuilder builder = KeycloakUriBuilder.fromUri(redirectUri);
int pos = builder.getQuery() == null ? 0 : builder.getQuery().length();
builder.queryParam(samlParameterName, base64Encoded(document));
if (relayState != null) {
builder.queryParam(GeneralConstants.RELAY_STATE, relayState);
}
if (sign) {
builder.queryParam(GeneralConstants.SAML_SIG_ALG_REQUEST_KEY, signatureAlgorithm.getXmlSignatureMethod());
URI uri = builder.build();
String rawQuery = uri.getRawQuery();
if (pos > 0) {
// just set in the signature the added SAML parameters
rawQuery = rawQuery.substring(pos + 1);
}
Signature signature = signatureAlgorithm.createSignature();
byte[] sig = new byte[0];
try {
signature.initSign(signingKeyPair.getPrivate());
signature.update(rawQuery.getBytes(GeneralConstants.SAML_CHARSET));
sig = signature.sign();
} catch (InvalidKeyException | SignatureException e) {
throw new ProcessingException(e);
}
String encodedSig = RedirectBindingUtil.base64Encode(sig);
builder.queryParam(GeneralConstants.SAML_SIGNATURE_REQUEST_KEY, encodedSig);
}
return builder.build();
}
use of org.keycloak.common.util.KeycloakUriBuilder in project keycloak by keycloak.
the class ResourcesRestServiceTest method getSharedWithMe.
private List<AbstractResourceService.ResourcePermission> getSharedWithMe(String userName, String name, int first, int max, Consumer<SimpleHttp.Response> responseHandler) {
KeycloakUriBuilder uri = KeycloakUriBuilder.fromUri("/shared-with-me");
if (name != null) {
uri.queryParam("name", name);
}
if (first > -1 && max > -1) {
uri.queryParam("first", first);
uri.queryParam("max", max);
}
return doGet(uri.build().toString(), authzClient.obtainAccessToken(userName, "password").getToken(), new TypeReference<List<AbstractResourceService.ResourcePermission>>() {
}, responseHandler);
}
use of org.keycloak.common.util.KeycloakUriBuilder in project keycloak by keycloak.
the class ResourcesRestServiceTest method getMyResources.
private List<Resource> getMyResources(String name, int first, int max) {
KeycloakUriBuilder uri = KeycloakUriBuilder.fromUri("");
if (name != null) {
uri.queryParam("name", name);
}
if (first > -1 && max > -1) {
uri.queryParam("first", first);
uri.queryParam("max", max);
}
return doGet(uri.build().toString(), new TypeReference<List<Resource>>() {
});
}
use of org.keycloak.common.util.KeycloakUriBuilder in project keycloak by keycloak.
the class ServletSamlSessionStore method saveRequest.
@Override
public void saveRequest() {
SavedRequest.trySaveRequest(exchange);
final ServletRequestContext sc = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
HttpSessionImpl session = sc.getCurrentServletContext().getSession(exchange, true);
KeycloakUriBuilder uriBuilder = KeycloakUriBuilder.fromUri(exchange.getRequestURI()).replaceQuery(exchange.getQueryString());
if (!exchange.isHostIncludedInRequestURI())
uriBuilder.scheme(exchange.getRequestScheme()).host(exchange.getHostAndPort());
String uri = uriBuilder.buildAsString();
session.setAttribute(SAML_REDIRECT_URI, uri);
}
Aggregations