org.camunda.bpm.extension.keycloak.KeycloakContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of camunda-bpm-identity-keycloak Show documentation
Show all versions of camunda-bpm-identity-keycloak Show documentation
A Camunda Identity Provider Plugin for Keycloak
package org.camunda.bpm.extension.keycloak;
import org.camunda.bpm.extension.keycloak.util.ContentType;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
/**
* Keycloak context holding authorization header / access token.
*/
public class KeycloakContext {
private HttpHeaders headers;
private long expiresAt;
String refreshToken;
public KeycloakContext(String accessToken, String tokenType, long expiresInMillis, String refreshToken, String charset) {
headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON + ";charset="+charset);
headers.add(HttpHeaders.AUTHORIZATION, tokenType + " " + accessToken);
expiresAt = System.currentTimeMillis() + expiresInMillis - 2000;
this.refreshToken = refreshToken;
}
/**
* Creates a new HTTP Request entity including the authorization header.
* @return the request entity
*/
public HttpEntity createHttpRequestEntity() {
return new HttpEntity<>(headers);
}
/**
* Whether the access token needs to be refreshed
* @return {@code true} in case a refresh is required
*/
public boolean needsRefresh() {
return System.currentTimeMillis() >= expiresAt;
}
/**
* The refresh token
* @return the refreshToken
*/
public String getRefreshToken() {
return refreshToken;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy