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

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