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

Pascal Rigaux
2022-11-15 e69c77c0badc32f1001f590553bac62bac29a417
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.*;
7f7e0c 5 import org.keycloak.protocol.ProtocolMapper;
513246 6 import org.keycloak.protocol.cas.mappers.CASAttributeMapper;
8a5518 7 import org.keycloak.protocol.cas.representations.CASServiceResponse;
352436 8 import org.keycloak.protocol.cas.utils.CASValidationException;
513246 9 import org.keycloak.protocol.cas.utils.ContentTypeHelper;
MP 10 import org.keycloak.protocol.cas.utils.ServiceResponseHelper;
7f7e0c 11 import org.keycloak.services.managers.ClientSessionCode;
b8d686 12 import org.keycloak.services.util.DefaultClientSessionContext;
7f7e0c 13
513246 14 import javax.ws.rs.core.*;
MP 15 import java.util.HashMap;
16 import java.util.Map;
7f7e0c 17 import java.util.Set;
MP 18
19 public class ServiceValidateEndpoint extends ValidateEndpoint {
513246 20     @Context
MP 21     private Request restRequest;
22
7f7e0c 23     public ServiceValidateEndpoint(RealmModel realm, EventBuilder event) {
MP 24         super(realm, event);
25     }
26
27     @Override
28     protected Response successResponse() {
29         UserSessionModel userSession = clientSession.getUserSession();
74023a 30         Map<String, Object> attributes = getUserAttributes();
8a5518 31         CASServiceResponse serviceResponse = ServiceResponseHelper.createSuccess(userSession.getUser().getUsername(), attributes);
513246 32         return prepare(Response.Status.OK, serviceResponse);
7f7e0c 33     }
MP 34
35     @Override
352436 36     protected Response errorResponse(CASValidationException e) {
8a5518 37         CASServiceResponse serviceResponse = ServiceResponseHelper.createFailure(e.getError(), e.getErrorDescription());
352436 38         return prepare(e.getStatus(), serviceResponse);
7f7e0c 39     }
MP 40
8a5518 41     private Response prepare(Response.Status status, CASServiceResponse serviceResponse) {
dee145 42         MediaType responseMediaType = new ContentTypeHelper(request, restRequest, session.getContext().getUri()).selectResponseType();
513246 43         return ServiceResponseHelper.createResponse(status, responseMediaType, serviceResponse);
7f7e0c 44     }
MP 45 }