mirror of https://github.com/jacekkow/keycloak-protocol-cas

Jacek Kowalski
2022-03-23 b1ec309effa13b22df969c3835605f6614d00a66
commit | author | age
7f7e0c 1 package org.keycloak.protocol.cas.endpoints;
MP 2
3 import org.jboss.resteasy.annotations.cache.NoCache;
4 import org.keycloak.events.EventBuilder;
5 import org.keycloak.events.EventType;
74023a 6 import org.keycloak.models.RealmModel;
7f7e0c 7 import org.keycloak.protocol.cas.CASLoginProtocol;
352436 8 import org.keycloak.protocol.cas.utils.CASValidationException;
7f7e0c 9
MP 10 import javax.ws.rs.GET;
74023a 11 import javax.ws.rs.core.MediaType;
EH 12 import javax.ws.rs.core.MultivaluedMap;
13 import javax.ws.rs.core.Response;
7f7e0c 14
74023a 15 public class ValidateEndpoint extends AbstractValidateEndpoint {
7f7e0c 16
MP 17     private static final String RESPONSE_OK = "yes\n";
18     private static final String RESPONSE_FAILED = "no\n";
19
20     public ValidateEndpoint(RealmModel realm, EventBuilder event) {
74023a 21         super(realm, event);
7f7e0c 22     }
MP 23
24     @GET
25     @NoCache
26     public Response build() {
dee145 27         MultivaluedMap<String, String> params = session.getContext().getUri().getQueryParameters();
7f7e0c 28         String service = params.getFirst(CASLoginProtocol.SERVICE_PARAM);
MP 29         String ticket = params.getFirst(CASLoginProtocol.TICKET_PARAM);
7124d2 30         boolean renew = params.containsKey(CASLoginProtocol.RENEW_PARAM);
7f7e0c 31
MP 32         event.event(EventType.CODE_TO_TOKEN);
33
34         try {
35             checkSsl();
36             checkRealm();
37             checkClient(service);
38
39             checkTicket(ticket, renew);
40
41             event.success();
42             return successResponse();
352436 43         } catch (CASValidationException e) {
7f7e0c 44             return errorResponse(e);
MP 45         }
46     }
47
48     protected Response successResponse() {
49         return Response.ok(RESPONSE_OK).type(MediaType.TEXT_PLAIN).build();
50     }
51
352436 52     protected Response errorResponse(CASValidationException e) {
MP 53         return Response.status(e.getStatus()).entity(RESPONSE_FAILED).type(MediaType.TEXT_PLAIN).build();
7f7e0c 54     }
MP 55
56 }