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

github-actions
2023-09-13 e8fed4af98dd55ec4fa3deff106866507a71e404
commit | author | age
7f7e0c 1 package org.keycloak.protocol.cas.endpoints;
MP 2
fdb9f6 3 import jakarta.ws.rs.core.Context;
JK 4 import jakarta.ws.rs.core.MediaType;
5 import jakarta.ws.rs.core.Request;
6 import jakarta.ws.rs.core.Response;
7f7e0c 7 import org.keycloak.events.EventBuilder;
fdb9f6 8 import org.keycloak.models.RealmModel;
JK 9 import org.keycloak.models.UserSessionModel;
8a5518 10 import org.keycloak.protocol.cas.representations.CASServiceResponse;
352436 11 import org.keycloak.protocol.cas.utils.CASValidationException;
513246 12 import org.keycloak.protocol.cas.utils.ContentTypeHelper;
MP 13 import org.keycloak.protocol.cas.utils.ServiceResponseHelper;
7f7e0c 14
513246 15 import java.util.Map;
7f7e0c 16
MP 17 public class ServiceValidateEndpoint extends ValidateEndpoint {
513246 18     @Context
MP 19     private Request restRequest;
20
7f7e0c 21     public ServiceValidateEndpoint(RealmModel realm, EventBuilder event) {
MP 22         super(realm, event);
23     }
24
25     @Override
26     protected Response successResponse() {
27         UserSessionModel userSession = clientSession.getUserSession();
74023a 28         Map<String, Object> attributes = getUserAttributes();
8a5518 29         CASServiceResponse serviceResponse = ServiceResponseHelper.createSuccess(userSession.getUser().getUsername(), attributes);
513246 30         return prepare(Response.Status.OK, serviceResponse);
7f7e0c 31     }
MP 32
33     @Override
352436 34     protected Response errorResponse(CASValidationException e) {
8a5518 35         CASServiceResponse serviceResponse = ServiceResponseHelper.createFailure(e.getError(), e.getErrorDescription());
352436 36         return prepare(e.getStatus(), serviceResponse);
7f7e0c 37     }
MP 38
8a5518 39     private Response prepare(Response.Status status, CASServiceResponse serviceResponse) {
dee145 40         MediaType responseMediaType = new ContentTypeHelper(request, restRequest, session.getContext().getUri()).selectResponseType();
513246 41         return ServiceResponseHelper.createResponse(status, responseMediaType, serviceResponse);
7f7e0c 42     }
MP 43 }