Get rid of @Context variables in Endpoint classes
| | |
| | | private RealmModel realm; |
| | | private EventBuilder event; |
| | | |
| | | @Context |
| | | private HttpHeaders headers; |
| | | |
| | | @Context |
| | | private HttpRequest request; |
| | | |
| | | public CASLoginProtocolService(KeycloakSession session, EventBuilder event) { |
| | | this.session = session; |
| | | this.realm = session.getContext().getRealm(); |
| | |
| | | |
| | | @Path("logout") |
| | | public Object logout() { |
| | | LogoutEndpoint endpoint = new LogoutEndpoint(realm); |
| | | LogoutEndpoint endpoint = new LogoutEndpoint(session, realm); |
| | | ResteasyProviderFactory.getInstance().injectProperties(endpoint); |
| | | return endpoint; |
| | | } |
| | | |
| | | @Path("validate") |
| | | public Object validate() { |
| | | ValidateEndpoint endpoint = new ValidateEndpoint(realm, event); |
| | | ValidateEndpoint endpoint = new ValidateEndpoint(session, realm, event); |
| | | ResteasyProviderFactory.getInstance().injectProperties(endpoint); |
| | | return endpoint; |
| | | } |
| | | |
| | | @Path("samlValidate") |
| | | public Object validateSaml11() { |
| | | SamlValidateEndpoint endpoint = new SamlValidateEndpoint(realm, event); |
| | | SamlValidateEndpoint endpoint = new SamlValidateEndpoint(session, realm, event); |
| | | ResteasyProviderFactory.getInstance().injectProperties(endpoint); |
| | | return endpoint; |
| | | } |
| | | |
| | | @Path("serviceValidate") |
| | | public Object serviceValidate() { |
| | | ServiceValidateEndpoint endpoint = new ServiceValidateEndpoint(realm, event); |
| | | ServiceValidateEndpoint endpoint = new ServiceValidateEndpoint(session, realm, event); |
| | | ResteasyProviderFactory.getInstance().injectProperties(endpoint); |
| | | return endpoint; |
| | | } |
| | |
| | | |
| | | public abstract class AbstractValidateEndpoint { |
| | | protected final Logger logger = Logger.getLogger(getClass()); |
| | | @Context |
| | | protected KeycloakSession session; |
| | | @Context |
| | | protected ClientConnection clientConnection; |
| | | @Context |
| | | protected HttpRequest request; |
| | | @Context |
| | | protected HttpHeaders headers; |
| | | protected RealmModel realm; |
| | | protected EventBuilder event; |
| | | protected ClientModel client; |
| | | protected AuthenticatedClientSessionModel clientSession; |
| | | |
| | | public AbstractValidateEndpoint(RealmModel realm, EventBuilder event) { |
| | | public AbstractValidateEndpoint(KeycloakSession session, RealmModel realm, EventBuilder event) { |
| | | this.session = session; |
| | | this.realm = realm; |
| | | this.event = event; |
| | | } |
| | | |
| | | protected void checkSsl() { |
| | | if (!session.getContext().getUri().getBaseUri().getScheme().equals("https") && realm.getSslRequired().isRequired(clientConnection)) { |
| | | if (!session.getContext().getUri().getBaseUri().getScheme().equals("https") && realm.getSslRequired().isRequired(session.getContext().getConnection())) { |
| | | throw new CASValidationException(CASErrorCode.INVALID_REQUEST, "HTTPS required", Response.Status.FORBIDDEN); |
| | | } |
| | | } |
| | |
| | | |
| | | import jakarta.ws.rs.GET; |
| | | import jakarta.ws.rs.QueryParam; |
| | | import jakarta.ws.rs.core.Context; |
| | | import jakarta.ws.rs.core.HttpHeaders; |
| | | import jakarta.ws.rs.core.Response; |
| | | import org.jboss.logging.Logger; |
| | | import org.jboss.resteasy.annotations.cache.NoCache; |
| | | import org.jboss.resteasy.spi.HttpRequest; |
| | | import org.keycloak.common.ClientConnection; |
| | | import org.keycloak.models.ClientModel; |
| | | import org.keycloak.models.KeycloakSession; |
| | | import org.keycloak.models.RealmModel; |
| | |
| | | public class LogoutEndpoint { |
| | | private static final Logger logger = Logger.getLogger(LogoutEndpoint.class); |
| | | |
| | | @Context |
| | | private KeycloakSession session; |
| | | |
| | | @Context |
| | | private ClientConnection clientConnection; |
| | | |
| | | @Context |
| | | private HttpRequest request; |
| | | |
| | | @Context |
| | | private HttpHeaders headers; |
| | | |
| | | private RealmModel realm; |
| | | private ClientModel client; |
| | | private String redirectUri; |
| | | |
| | | public LogoutEndpoint(RealmModel realm) { |
| | | public LogoutEndpoint(KeycloakSession session, RealmModel realm) { |
| | | this.session = session; |
| | | this.realm = realm; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | logger.debug("Initiating CAS browser logout"); |
| | | Response response = AuthenticationManager.browserLogout(session, realm, authResult.getSession(), session.getContext().getUri(), clientConnection, headers); |
| | | Response response = AuthenticationManager.browserLogout(session, realm, authResult.getSession(), session.getContext().getUri(), session.getContext().getConnection(), session.getContext().getRequestHeaders()); |
| | | logger.debug("finishing CAS browser logout"); |
| | | return response; |
| | | } |
| | |
| | | import org.keycloak.dom.saml.v1.protocol.SAML11ResponseType; |
| | | import org.keycloak.events.EventBuilder; |
| | | import org.keycloak.events.EventType; |
| | | import org.keycloak.models.KeycloakSession; |
| | | import org.keycloak.models.RealmModel; |
| | | import org.keycloak.models.UserModel; |
| | | import org.keycloak.protocol.cas.CASLoginProtocol; |
| | |
| | | import static org.keycloak.protocol.cas.CASLoginProtocol.TARGET_PARAM; |
| | | |
| | | public class SamlValidateEndpoint extends AbstractValidateEndpoint { |
| | | public SamlValidateEndpoint(RealmModel realm, EventBuilder event) { |
| | | super(realm, event.event(EventType.CODE_TO_TOKEN)); |
| | | public SamlValidateEndpoint(KeycloakSession session, RealmModel realm, EventBuilder event) { |
| | | super(session, realm, event.event(EventType.CODE_TO_TOKEN)); |
| | | } |
| | | |
| | | @POST |
| | |
| | | import jakarta.ws.rs.core.Request; |
| | | import jakarta.ws.rs.core.Response; |
| | | import org.keycloak.events.EventBuilder; |
| | | import org.keycloak.models.KeycloakSession; |
| | | import org.keycloak.models.RealmModel; |
| | | import org.keycloak.models.UserSessionModel; |
| | | import org.keycloak.protocol.cas.representations.CASServiceResponse; |
| | |
| | | import java.util.Map; |
| | | |
| | | public class ServiceValidateEndpoint extends ValidateEndpoint { |
| | | @Context |
| | | private Request restRequest; |
| | | |
| | | public ServiceValidateEndpoint(RealmModel realm, EventBuilder event) { |
| | | super(realm, event); |
| | | public ServiceValidateEndpoint(KeycloakSession session, RealmModel realm, EventBuilder event) { |
| | | super(session, realm, event); |
| | | } |
| | | |
| | | @Override |
| | |
| | | import org.jboss.resteasy.annotations.cache.NoCache; |
| | | import org.keycloak.events.EventBuilder; |
| | | import org.keycloak.events.EventType; |
| | | import org.keycloak.models.KeycloakSession; |
| | | import org.keycloak.models.RealmModel; |
| | | import org.keycloak.protocol.cas.CASLoginProtocol; |
| | | import org.keycloak.protocol.cas.utils.CASValidationException; |
| | |
| | | private static final String RESPONSE_OK = "yes\n"; |
| | | private static final String RESPONSE_FAILED = "no\n"; |
| | | |
| | | public ValidateEndpoint(RealmModel realm, EventBuilder event) { |
| | | super(realm, event); |
| | | public ValidateEndpoint(KeycloakSession session, RealmModel realm, EventBuilder event) { |
| | | super(session, realm, event); |
| | | } |
| | | |
| | | @GET |