use of org.apache.commons.lang3.BooleanUtils.toBoolean in project cas by apereo.
the class JwtTicketGrantingTicketResourceEntityResponseFactory method build.
@Override
public ResponseEntity<String> build(final TicketGrantingTicket ticketGrantingTicket, final HttpServletRequest request) throws Exception {
var tokenParam = request.getParameter(TokenConstants.PARAMETER_NAME_TOKEN);
if (StringUtils.isBlank(tokenParam)) {
tokenParam = request.getHeader(TokenConstants.PARAMETER_NAME_TOKEN);
}
if (StringUtils.isBlank(tokenParam) || !BooleanUtils.toBoolean(tokenParam)) {
LOGGER.debug("The request indicates that ticket-granting ticket should not be created as a JWT");
return super.build(ticketGrantingTicket, request);
}
val claims = (Map) request.getParameterMap().entrySet().stream().filter(entry -> !IGNORED_PARAMS.contains(entry.getKey())).map(entry -> Pair.of(entry.getKey(), CollectionUtils.toCollection(entry.getValue(), ArrayList.class))).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
val jwt = this.tokenTicketBuilder.build(ticketGrantingTicket, claims);
LOGGER.debug("Generated JWT [{}]", jwt);
val headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
val entity = new ResponseEntity<>(jwt, headers, HttpStatus.CREATED);
LOGGER.debug("Created response entity [{}]", entity);
return entity;
}
Aggregations