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

github-actions
2023-06-28 46a6c57405b58524e4154e8ec1e04db0bf3f7416
commit | author | age
7f7e0c 1 package org.keycloak.protocol.cas.endpoints;
MP 2
3 import org.keycloak.events.EventBuilder;
b8d686 4 import org.keycloak.models.*;
8a5518 5 import org.keycloak.protocol.cas.representations.CASServiceResponse;
352436 6 import org.keycloak.protocol.cas.utils.CASValidationException;
513246 7 import org.keycloak.protocol.cas.utils.ContentTypeHelper;
MP 8 import org.keycloak.protocol.cas.utils.ServiceResponseHelper;
7f7e0c 9
513246 10 import javax.ws.rs.core.*;
MP 11 import java.util.Map;
7f7e0c 12
MP 13 public class ServiceValidateEndpoint extends ValidateEndpoint {
513246 14     @Context
MP 15     private Request restRequest;
16
7f7e0c 17     public ServiceValidateEndpoint(RealmModel realm, EventBuilder event) {
MP 18         super(realm, event);
19     }
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) {
dee145 36         MediaType responseMediaType = new ContentTypeHelper(request, restRequest, session.getContext().getUri()).selectResponseType();
513246 37         return ServiceResponseHelper.createResponse(status, responseMediaType, serviceResponse);
7f7e0c 38     }
MP 39 }