Search in sources :

Example 6 with BooleanUtils.toBoolean

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;
}
Also used : lombok.val(lombok.val) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) DefaultTicketGrantingTicketResourceEntityResponseFactory(org.apereo.cas.rest.factory.DefaultTicketGrantingTicketResourceEntityResponseFactory) BooleanUtils(org.apache.commons.lang3.BooleanUtils) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) RestHttpRequestCredentialFactory(org.apereo.cas.rest.factory.RestHttpRequestCredentialFactory) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) ResponseEntity(org.springframework.http.ResponseEntity) TokenConstants(org.apereo.cas.token.TokenConstants) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) TokenTicketBuilder(org.apereo.cas.token.TokenTicketBuilder) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

BooleanUtils (org.apache.commons.lang3.BooleanUtils)5 StringUtils (org.apache.commons.lang3.StringUtils)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Sets (com.google.common.collect.Sets)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 MessageService (org.hisp.dhis.message.MessageService)2 NotificationMessage (org.hisp.dhis.notification.NotificationMessage)2