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

Jacek Kowalski
2023-06-28 bba8bfec21d26bc06fe25a3b2ecb827b80fc0fb1
commit | author | age
7f7e0c 1 package org.keycloak.protocol.cas;
MP 2
3 import org.jboss.resteasy.spi.HttpRequest;
4 import org.jboss.resteasy.spi.ResteasyProviderFactory;
5 import org.keycloak.events.EventBuilder;
6 import org.keycloak.models.KeycloakSession;
7 import org.keycloak.models.RealmModel;
74023a 8 import org.keycloak.protocol.cas.endpoints.*;
7f7e0c 9 import org.keycloak.services.resources.RealmsResource;
MP 10
11 import javax.ws.rs.Path;
513246 12 import javax.ws.rs.core.*;
7f7e0c 13
MP 14 public class CASLoginProtocolService {
58cce9 15     private KeycloakSession session;
7f7e0c 16     private RealmModel realm;
MP 17     private EventBuilder event;
18
19     @Context
20     private HttpHeaders headers;
21
22     @Context
23     private HttpRequest request;
24
58cce9 25     public CASLoginProtocolService(KeycloakSession session, EventBuilder event) {
G 26         this.session = session;
27         this.realm = session.getContext().getRealm();
7f7e0c 28         this.event = event;
MP 29     }
30
31     public static UriBuilder serviceBaseUrl(UriBuilder baseUriBuilder) {
32         return baseUriBuilder.path(RealmsResource.class).path("{realm}/protocol/" + CASLoginProtocol.LOGIN_PROTOCOL);
33     }
34
35     @Path("login")
36     public Object login() {
58cce9 37         AuthorizationEndpoint endpoint = new AuthorizationEndpoint(session, event);
7f7e0c 38         ResteasyProviderFactory.getInstance().injectProperties(endpoint);
MP 39         return endpoint;
40     }
41
42     @Path("logout")
43     public Object logout() {
b88dc3 44         LogoutEndpoint endpoint = new LogoutEndpoint(realm);
7f7e0c 45         ResteasyProviderFactory.getInstance().injectProperties(endpoint);
MP 46         return endpoint;
47     }
48
49     @Path("validate")
50     public Object validate() {
51         ValidateEndpoint endpoint = new ValidateEndpoint(realm, event);
52         ResteasyProviderFactory.getInstance().injectProperties(endpoint);
53         return endpoint;
54     }
55
74023a 56     @Path("samlValidate")
EH 57     public Object validateSaml11() {
58         SamlValidateEndpoint endpoint = new SamlValidateEndpoint(realm, event);
59         ResteasyProviderFactory.getInstance().injectProperties(endpoint);
60         return endpoint;
61     }
62
7f7e0c 63     @Path("serviceValidate")
MP 64     public Object serviceValidate() {
65         ServiceValidateEndpoint endpoint = new ServiceValidateEndpoint(realm, event);
66         ResteasyProviderFactory.getInstance().injectProperties(endpoint);
67         return endpoint;
68     }
69
70     @Path("proxyValidate")
71     public Object proxyValidate() {
5a0869 72         //TODO implement
MP 73         return serviceValidate();
7f7e0c 74     }
MP 75
76     @Path("proxy")
77     public Object proxy() {
5a0869 78         return Response.serverError().entity("Not implemented").build();
7f7e0c 79     }
MP 80
81     @Path("p3/serviceValidate")
82     public Object p3ServiceValidate() {
83         return serviceValidate();
84     }
85
86     @Path("p3/proxyValidate")
87     public Object p3ProxyValidate() {
88         return proxyValidate();
89     }
90 }