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

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