Java Code Examples for io.undertow.util.HeaderValues#getFirst()
The following examples show how to use
io.undertow.util.HeaderValues#getFirst() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseHeaderAttribute.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public String readAttribute(final HttpServerExchange exchange) { HeaderValues header = exchange.getResponseHeaders().get(responseHeader); if (header == null) { return null; } else if(header.size() == 1) { return header.getFirst(); } StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < header.size(); ++i) { if (i != 0) { sb.append(", "); } sb.append(header.get(i)); } sb.append("]"); return sb.toString(); }
Example 2
Source File: RequestHeaderAttribute.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public String readAttribute(final HttpServerExchange exchange) { HeaderValues header = exchange.getRequestHeaders().get(requestHeader); if (header == null) { return null; } else if(header.size() == 1) { return header.getFirst(); } StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < header.size(); ++i) { if (i != 0) { sb.append(", "); } sb.append(header.get(i)); } sb.append("]"); return sb.toString(); }
Example 3
Source File: DatawaveAuthenticationMechanism.java From datawave with Apache License 2.0 | 5 votes |
private String getSingleHeader(HeaderMap headers, String headerName) throws MultipleHeaderException { String value = null; HeaderValues values = (headers == null) ? null : headers.get(headerName); if (values != null) { if (values.size() > 1) throw new MultipleHeaderException(headerName + " was specified multiple times, which is not allowed!"); value = values.getFirst(); } return value; }
Example 4
Source File: TokenManager.java From light-4j with Apache License 2.0 | 5 votes |
/** * get a Jwt with a provided clientRequest, * it will get token based on Jwt.Key (either scope or service_id) * if the user declared both scope and service_id in header, it will get jwt based on scope * @param clientRequest client request * @return Result */ public Result<Jwt> getJwt(ClientRequest clientRequest) { HeaderValues scope = clientRequest.getRequestHeaders().get(ClientConfig.SCOPE); if(scope != null) { String scopeStr = scope.getFirst(); Set<String> scopeSet = new HashSet<>(); scopeSet.addAll(Arrays.asList(scopeStr.split(" "))); return getJwt(new Jwt.Key(scopeSet)); } HeaderValues serviceId = clientRequest.getRequestHeaders().get(ClientConfig.SERVICE_ID); if(serviceId != null) { return getJwt(new Jwt.Key(serviceId.getFirst())); } return getJwt(new Jwt.Key()); }
Example 5
Source File: Oauth2DerefGetHandler.java From light-oauth2 with Apache License 2.0 | 4 votes |
public void handleRequest(HttpServerExchange exchange) throws Exception { // check if client_id and client_secret in header are valid pair. HeaderValues values = exchange.getRequestHeaders().get(AUTHORIZATION); String authHeader; if(values != null) { authHeader = values.getFirst(); } else { setExchangeStatus(exchange, MISSING_AUTHORIZATION_HEADER); processAudit(exchange); return; } if(authHeader == null) { setExchangeStatus(exchange, MISSING_AUTHORIZATION_HEADER); processAudit(exchange); return; } String clientId = authenticate(authHeader); if(clientId != null) { if(logger.isDebugEnabled()) logger.debug("clientId = " + clientId); String token = exchange.getQueryParameters().get("token").getFirst(); if(logger.isDebugEnabled()) logger.debug("token = " + token); Map<String, String> referenceMap = (Map<String, String>) CacheStartupHookProvider.hz.getMap("references").get(token); if(referenceMap == null) { setExchangeStatus(exchange, DEREF_TOKEN_NOT_FOUND, token); processAudit(exchange); return; } String refClientId = referenceMap.get("clientId"); if(refClientId != null && !refClientId.equals(clientId)) { // it is not the right dereference client. setExchangeStatus(exchange, DEREF_CLIENT_NOT_MATCH, clientId); processAudit(exchange); return; } String jwt = referenceMap.get("jwt"); if(jwt == null) { setExchangeStatus(exchange, JWT_TOKEN_NOT_FOUND, token); processAudit(exchange); return; } exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, "application/text"); exchange.getResponseSender().send(jwt); } processAudit(exchange); }