use of javax.ws.rs.core.HttpHeaders in project cxf by apache.
the class HttpHeadersImplTest method testGetDate.
@Test
public void testGetDate() throws Exception {
Message m = createMessage(createHeaders());
HttpHeaders h = new HttpHeadersImpl(m);
List<String> dateValues = h.getRequestHeader("Date");
assertEquals(1, dateValues.size());
assertEquals("Tue, 21 Oct 2008 17:00:00 GMT", dateValues.get(0));
Date d = h.getDate();
String theDateValue = HttpUtils.getHttpDateFormat().format(d);
assertEquals(theDateValue, "Tue, 21 Oct 2008 17:00:00 GMT");
}
use of javax.ws.rs.core.HttpHeaders in project cxf by apache.
the class WadlGenerator method doFilter.
protected void doFilter(ContainerRequestContext context, Message m) {
if (!"GET".equals(m.get(Message.HTTP_REQUEST_METHOD))) {
return;
}
UriInfo ui = context.getUriInfo();
if (!ui.getQueryParameters().containsKey(WADL_QUERY)) {
if (stylesheetReference != null || !docLocationMap.isEmpty()) {
String path = ui.getPath(false);
if (path.startsWith("/") && !path.isEmpty()) {
path = path.substring(1);
}
if (stylesheetReference != null && path.endsWith(".xsl") || docLocationMap.containsKey(path)) {
context.abortWith(getExistingResource(m, ui, path));
}
}
return;
}
if (ignoreRequests) {
context.abortWith(Response.status(404).build());
return;
}
if (allowList != null && !allowList.isEmpty()) {
ServletRequest servletRequest = (ServletRequest) m.getContextualProperty("HTTP.REQUEST");
final String remoteAddress;
if (servletRequest != null) {
remoteAddress = servletRequest.getRemoteAddr();
} else {
remoteAddress = "";
}
boolean foundMatch = false;
for (String addr : allowList) {
if (addr.equals(remoteAddress)) {
foundMatch = true;
break;
}
}
if (!foundMatch) {
context.abortWith(Response.status(404).build());
return;
}
}
HttpHeaders headers = new HttpHeadersImpl(m);
List<MediaType> accepts = headers.getAcceptableMediaTypes();
MediaType type = accepts.contains(WADL_TYPE) ? WADL_TYPE : accepts.contains(MediaType.APPLICATION_JSON_TYPE) ? MediaType.APPLICATION_JSON_TYPE : defaultWadlResponseMediaType;
Response response = getExistingWadl(m, ui, type);
if (response != null) {
context.abortWith(response);
return;
}
boolean isJson = isJson(type);
StringBuilder sbMain = generateWADL(getBaseURI(m, ui), getResourcesList(m, ui), isJson, m, ui);
m.getExchange().put(JAXRSUtils.IGNORE_MESSAGE_WRITERS, !isJson && ignoreMessageWriters);
Response r = Response.ok().type(type).entity(createResponseEntity(m, ui, sbMain.toString(), isJson)).build();
context.abortWith(r);
}
use of javax.ws.rs.core.HttpHeaders in project keycloak by keycloak.
the class UserInfoEndpoint method issueUserInfoPost.
@Path("/")
@POST
@NoCache
public Response issueUserInfoPost() {
// Try header first
HttpHeaders headers = request.getHttpHeaders();
String accessToken = this.appAuthManager.extractAuthorizationHeaderTokenOrReturnNull(headers);
// Fallback to form parameter
if (accessToken == null) {
accessToken = request.getDecodedFormParameters().getFirst("access_token");
}
return issueUserInfo(accessToken);
}
use of javax.ws.rs.core.HttpHeaders in project keycloak by keycloak.
the class AuthenticationManager method browserLogoutAllClients.
private static Response browserLogoutAllClients(UserSessionModel userSession, KeycloakSession session, RealmModel realm, HttpHeaders headers, UriInfo uriInfo, AuthenticationSessionModel logoutAuthSession) {
Map<Boolean, List<AuthenticatedClientSessionModel>> acss = userSession.getAuthenticatedClientSessions().values().stream().filter(clientSession -> !Objects.equals(AuthenticationSessionModel.Action.LOGGED_OUT.name(), clientSession.getAction()) && !Objects.equals(AuthenticationSessionModel.Action.LOGGING_OUT.name(), clientSession.getAction())).filter(clientSession -> clientSession.getProtocol() != null).collect(Collectors.partitioningBy(clientSession -> clientSession.getClient().isFrontchannelLogout()));
final List<AuthenticatedClientSessionModel> backendLogoutSessions = acss.get(false) == null ? Collections.emptyList() : acss.get(false);
backendLogoutSessions.forEach(acs -> backchannelLogoutClientSession(session, realm, acs, logoutAuthSession, uriInfo, headers));
final List<AuthenticatedClientSessionModel> redirectClients = acss.get(true) == null ? Collections.emptyList() : acss.get(true);
for (AuthenticatedClientSessionModel nextRedirectClient : redirectClients) {
Response response = frontchannelLogoutClientSession(session, realm, nextRedirectClient, logoutAuthSession, uriInfo, headers);
if (response != null) {
return response;
}
}
return null;
}
use of javax.ws.rs.core.HttpHeaders in project keycloak by keycloak.
the class DefaultLocaleSelectorProvider method resolveLocale.
@Override
public Locale resolveLocale(RealmModel realm, UserModel user) {
HttpHeaders requestHeaders = session.getContext().getRequestHeaders();
AuthenticationSessionModel session = this.session.getContext().getAuthenticationSession();
if (!realm.isInternationalizationEnabled()) {
return Locale.ENGLISH;
}
Locale userLocale = getUserLocale(realm, session, user, requestHeaders);
if (userLocale != null) {
return userLocale;
}
String realmDefaultLocale = realm.getDefaultLocale();
if (realmDefaultLocale != null) {
return Locale.forLanguageTag(realmDefaultLocale);
}
return Locale.ENGLISH;
}
Aggregations