├── src ├── main │ ├── resources │ │ ├── theme │ │ │ └── keycloak-extended │ │ │ │ └── admin │ │ │ │ ├── theme.properties │ │ │ │ ├── messages │ │ │ │ └── admin-messages_en.properties │ │ │ │ └── resources │ │ │ │ └── partials │ │ │ │ └── realm-identity-provider-cas.html │ │ └── META-INF │ │ │ ├── keycloak-themes.json │ │ │ └── services │ │ │ ├── org.keycloak.broker.provider.IdentityProviderFactory │ │ │ └── org.keycloak.broker.provider.IdentityProviderMapper │ ├── docker │ │ └── Dockerfile │ └── java │ │ └── io │ │ └── github │ │ └── johnjcool │ │ └── keycloak │ │ └── broker │ │ └── cas │ │ ├── model │ │ ├── Code.java │ │ ├── Failure.java │ │ ├── ServiceResponse.java │ │ └── Success.java │ │ ├── jaxb │ │ ├── ServiceResponseJaxbContextResolver.java │ │ ├── AttributesAdapter.java │ │ ├── ServiceResponseJaxbProvider.java │ │ └── AttributesWrapper.java │ │ ├── CasIdentityProviderFactory.java │ │ ├── CasIdentityProviderConfig.java │ │ ├── util │ │ └── UrlHelper.java │ │ ├── mappers │ │ ├── AbstractAttributeMapper.java │ │ ├── AttributeToRoleMapper.java │ │ └── UserAttributeMapper.java │ │ └── CasIdentityProvider.java └── test │ ├── resources │ ├── test-without-attributes.xml │ └── test-with-attributes.xml │ └── java │ └── io │ └── github │ └── johnjcool │ └── keycloak │ └── broker │ └── cas │ ├── mappers │ └── AbstractAttributeMapperTest.java │ └── model │ └── ServiceResponseTest.java ├── docs └── resources │ ├── 26-09-2018 19-40-25.png │ ├── 26-09-2018 20-05-47.png │ ├── 26-09-2018 20-05-59.png │ ├── 26-09-2018 20-06-21.png │ ├── 26-09-2018 20-06-34.png │ ├── 26-09-2018 20-07-15.png │ ├── 26-09-2018 20-07-44.png │ ├── 26-09-2018 20-08-04.png │ ├── 26-09-2018 20-08-54.png │ ├── 26-09-2018 20-09-49.png │ ├── 26-09-2018 20-10-05.png │ └── 26-09-2018 20-10-23.png ├── .gitignore ├── .travis └── settings.xml ├── .travis.yml ├── README.md ├── pom.xml └── LICENSE.md /src/main/resources/theme/keycloak-extended/admin/theme.properties: -------------------------------------------------------------------------------- 1 | parent=keycloak -------------------------------------------------------------------------------- /docs/resources/26-09-2018 19-40-25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 19-40-25.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-05-47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-05-47.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-05-59.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-05-59.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-06-21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-06-21.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-06-34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-06-34.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-07-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-07-15.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-07-44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-07-44.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-08-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-08-04.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-08-54.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-08-54.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-09-49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-09-49.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-10-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-10-05.png -------------------------------------------------------------------------------- /docs/resources/26-09-2018 20-10-23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnjcool/keycloak-cas-services/HEAD/docs/resources/26-09-2018 20-10-23.png -------------------------------------------------------------------------------- /src/main/resources/META-INF/keycloak-themes.json: -------------------------------------------------------------------------------- 1 | { 2 | "themes": [{ 3 | "name" : "keycloak-extended", 4 | "types": [ "admin" ] 5 | }] 6 | } -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/org.keycloak.broker.provider.IdentityProviderFactory: -------------------------------------------------------------------------------- 1 | io.github.johnjcool.keycloak.broker.cas.CasIdentityProviderFactory -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/org.keycloak.broker.provider.IdentityProviderMapper: -------------------------------------------------------------------------------- 1 | io.github.johnjcool.keycloak.broker.cas.mappers.UserAttributeMapper 2 | io.github.johnjcool.keycloak.broker.cas.mappers.AttributeToRoleMapper -------------------------------------------------------------------------------- /src/test/resources/test-without-attributes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | -------------------------------------------------------------------------------- /src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM jboss/keycloak:4.8.3.Final 2 | MAINTAINER John J Cool 3 | 4 | ARG project_version=1.0.0 5 | 6 | ADD keycloak-cas-services-$project_version.jar /opt/jboss/keycloak/standalone/deployments/keycloak-cas-services-$project_version.jar 7 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/model/Code.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.model; 2 | 3 | public enum Code { 4 | INVALID_REQUEST, 5 | INVALID_TICKET_SPEC, 6 | UNAUTHORIZED_SERVICE_PROXY, 7 | INVALID_PROXY_CALLBACK, 8 | INVALID_TICKET, 9 | INVALID_SERVICE, 10 | INTERNAL_ERROR; 11 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ 25 | /derby.log 26 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/jaxb/ServiceResponseJaxbContextResolver.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.jaxb; 2 | 3 | import javax.ws.rs.Produces; 4 | import javax.ws.rs.core.MediaType; 5 | import javax.ws.rs.ext.Provider; 6 | 7 | import org.jboss.resteasy.plugins.providers.jaxb.XmlJAXBContextFinder; 8 | 9 | @Provider 10 | @Produces(MediaType.WILDCARD) 11 | public class ServiceResponseJaxbContextResolver extends XmlJAXBContextFinder { 12 | 13 | } -------------------------------------------------------------------------------- /src/test/resources/test-with-attributes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | 7 | test.test@test.test 8 | 9 | tets 10 | 11 | test 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/jaxb/AttributesAdapter.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.jaxb; 2 | 3 | import java.util.Map; 4 | 5 | import javax.xml.bind.annotation.adapters.XmlAdapter; 6 | 7 | public class AttributesAdapter extends XmlAdapter> { 8 | 9 | @Override 10 | public AttributesWrapper marshal(final Map attributes) throws Exception { 11 | throw new UnsupportedOperationException("This adapter only supports from xml to map."); 12 | } 13 | 14 | @Override 15 | public Map unmarshal(final AttributesWrapper attributesWrapper) throws Exception { 16 | return attributesWrapper.toMap(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.travis/settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | ossrh 9 | ${env.SONATYPE_USERNAME} 10 | ${env.SONATYPE_PASSWORD} 11 | 12 | 13 | 14 | 15 | 16 | ossrh 17 | 18 | true 19 | 20 | 21 | ${env.GPG_EXECUTABLE} 22 | ${env.GPG_PASSPHRASE} 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/jaxb/ServiceResponseJaxbProvider.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.jaxb; 2 | 3 | import io.github.johnjcool.keycloak.broker.cas.model.ServiceResponse; 4 | 5 | import java.lang.annotation.Annotation; 6 | import java.lang.reflect.Type; 7 | 8 | import javax.ws.rs.Consumes; 9 | import javax.ws.rs.core.MediaType; 10 | import javax.ws.rs.ext.Provider; 11 | 12 | import org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider; 13 | 14 | @Provider 15 | @Consumes(value = { MediaType.WILDCARD }) 16 | public class ServiceResponseJaxbProvider extends AbstractJAXBProvider { 17 | 18 | @Override 19 | protected boolean isReadWritable(final Class type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) { 20 | return type == ServiceResponse.class; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/resources/theme/keycloak-extended/admin/messages/admin-messages_en.properties: -------------------------------------------------------------------------------- 1 | cas-config.tooltip=The CAS Configuration is what detects whether a user needs to be authenticated or not. If a user needs to be authenticated, it will redirect the user to the CAS server. 2 | cas-config=CAS Config 3 | cas-server-url-prefix=CAS Server URL Prefix 4 | cas-server-url-prefix.tooltip=The start of the CAS server URL, i.e. https://localhost:8443/cas 5 | cas-server-protocol3=CAS Server Protocol 3.0 6 | cas-server-protocol3.tooltip=Enable to use CAS Server Protocol 3.0 to validate the ticket 7 | cas-renew=CAS renew 8 | cas-renew.tooltip=Specifies whether renew=true should be sent to the CAS server. Valid values are either true/false (or no value at all). Note that renew cannot be specified as local init-param setting. 9 | cas-gateway=CAS gateway 10 | cas-gateway.tooltip=Specifies whether gateway=true should be sent to the CAS server. Valid values are either true/false (or no value at all) -------------------------------------------------------------------------------- /src/test/java/io/github/johnjcool/keycloak/broker/cas/mappers/AbstractAttributeMapperTest.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.mappers; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | public class AbstractAttributeMapperTest { 9 | 10 | @Test 11 | public void getAttributeValueListTest() { 12 | Object userAttribute = "[jioij098, kjh#´lkjkj, oijoiuo]"; 13 | Object list = AbstractAttributeMapper.getAttributeValue(userAttribute); 14 | Assert.assertTrue(list instanceof ArrayList); 15 | } 16 | 17 | @Test 18 | public void getAttributeValueStringTest() { 19 | Object userAttribute = "fsiudhfk"; 20 | Assert.assertTrue(AbstractAttributeMapper.getAttributeValue(userAttribute) instanceof String); 21 | } 22 | 23 | @Test 24 | public void getAttributeValueObjectTest() { 25 | Object userAttribute = new Object(); 26 | Assert.assertTrue(AbstractAttributeMapper.getAttributeValue(userAttribute) instanceof Object); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/model/Failure.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.model; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.xml.bind.annotation.XmlAccessType; 6 | import javax.xml.bind.annotation.XmlAccessorType; 7 | import javax.xml.bind.annotation.XmlAttribute; 8 | import javax.xml.bind.annotation.XmlValue; 9 | 10 | @XmlAccessorType(XmlAccessType.FIELD) 11 | public class Failure implements Serializable { 12 | 13 | private static final long serialVersionUID = 1L; 14 | 15 | @XmlAttribute 16 | private Code code; 17 | 18 | @XmlValue 19 | private String description; 20 | 21 | public Code getCode() { 22 | return code; 23 | } 24 | 25 | public void setCode(final Code code) { 26 | this.code = code; 27 | } 28 | 29 | public String getDescription() { 30 | return description; 31 | } 32 | 33 | public void setDescription(final String description) { 34 | this.description = description; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return String.format("Failure [code=%s, description=%s]", code, description); 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/model/ServiceResponse.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.model; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.xml.bind.annotation.XmlAccessType; 6 | import javax.xml.bind.annotation.XmlAccessorType; 7 | import javax.xml.bind.annotation.XmlElement; 8 | import javax.xml.bind.annotation.XmlRootElement; 9 | 10 | @XmlAccessorType(XmlAccessType.FIELD) 11 | @XmlRootElement(name = "serviceResponse", namespace = "http://www.yale.edu/tp/cas") 12 | public class ServiceResponse implements Serializable { 13 | 14 | private static final long serialVersionUID = 1L; 15 | 16 | @XmlElement(name = "authenticationFailure", namespace = "http://www.yale.edu/tp/cas") 17 | private Failure failure; 18 | 19 | @XmlElement(name = "authenticationSuccess", namespace = "http://www.yale.edu/tp/cas") 20 | private Success success; 21 | 22 | public Failure getFailure() { 23 | return failure; 24 | } 25 | 26 | public void setFailure(final Failure failure) { 27 | this.failure = failure; 28 | } 29 | 30 | public Success getSuccess() { 31 | return success; 32 | } 33 | 34 | public void setSuccess(final Success success) { 35 | this.success = success; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return String.format("ServiceResponse [failure=%s, success=%s]", failure, success); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/CasIdentityProviderFactory.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas; 2 | 3 | import io.github.johnjcool.keycloak.broker.cas.jaxb.ServiceResponseJaxbContextResolver; 4 | import io.github.johnjcool.keycloak.broker.cas.jaxb.ServiceResponseJaxbProvider; 5 | import org.jboss.resteasy.spi.ResteasyProviderFactory; 6 | import org.keycloak.Config; 7 | import org.keycloak.broker.provider.AbstractIdentityProviderFactory; 8 | import org.keycloak.models.IdentityProviderModel; 9 | import org.keycloak.models.KeycloakSession; 10 | 11 | public class CasIdentityProviderFactory extends AbstractIdentityProviderFactory { 12 | 13 | public static final String PROVIDER_ID = "cas"; 14 | 15 | @Override 16 | public void init(final Config.Scope config) { 17 | super.init(config); 18 | ResteasyProviderFactory.getInstance().registerProvider(ServiceResponseJaxbProvider.class, true); 19 | ResteasyProviderFactory.getInstance().registerProvider(ServiceResponseJaxbContextResolver.class, true); 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return "CAS"; 25 | } 26 | 27 | @Override 28 | public CasIdentityProvider create(final KeycloakSession session, final IdentityProviderModel model) { 29 | return new CasIdentityProvider(session, new CasIdentityProviderConfig(model)); 30 | } 31 | 32 | @Override 33 | public String getId() { 34 | return PROVIDER_ID; 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/model/Success.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.model; 2 | 3 | import io.github.johnjcool.keycloak.broker.cas.jaxb.AttributesAdapter; 4 | 5 | import java.io.Serializable; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import javax.xml.bind.annotation.XmlAccessType; 10 | import javax.xml.bind.annotation.XmlAccessorType; 11 | import javax.xml.bind.annotation.XmlElement; 12 | import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 13 | 14 | @XmlAccessorType(XmlAccessType.FIELD) 15 | public class Success implements Serializable { 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | @XmlElement(name = "user", namespace = "http://www.yale.edu/tp/cas") 20 | private String user; 21 | 22 | @XmlElement(name = "attributes", namespace = "http://www.yale.edu/tp/cas") 23 | @XmlJavaTypeAdapter(AttributesAdapter.class) 24 | private Map attributes = new HashMap<>(); 25 | 26 | public String getUser() { 27 | return user; 28 | } 29 | 30 | public void setUser(final String user) { 31 | this.user = user; 32 | } 33 | 34 | public Map getAttributes() { 35 | return attributes; 36 | } 37 | 38 | public void setAttributes(final Map attributes) { 39 | this.attributes = attributes; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return String.format("Success [user=%s, attributes=%s]", user, attributes); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/CasIdentityProviderConfig.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas; 2 | 3 | import org.keycloak.models.IdentityProviderModel; 4 | 5 | public class CasIdentityProviderConfig extends IdentityProviderModel { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private static final String DEFAULT_CAS_LOGIN_SUFFFIX = "login"; 10 | private static final String DEFAULT_CAS_LOGOUT_SUFFFIX = "logout"; 11 | private static final String DEFAULT_CAS_SERVICE_VALIDATE_SUFFFIX = "serviceValidate"; 12 | private static final String DEFAULT_CAS_3_PROTOCOL_PREFIX = "p3"; 13 | 14 | public CasIdentityProviderConfig(final IdentityProviderModel model) { 15 | super(model); 16 | } 17 | 18 | public void setCasServerUrlPrefix(final String casServerUrlPrefix) { 19 | getConfig().put("casServerUrlPrefix", casServerUrlPrefix); 20 | } 21 | 22 | public String getCasServerUrlPrefix() { 23 | return getConfig().get("casServerUrlPrefix"); 24 | } 25 | 26 | public void setCasServerProtocol3(final boolean casServerProtocol3) { 27 | getConfig().put("casServerProtocol3", String.valueOf(casServerProtocol3)); 28 | } 29 | 30 | public boolean isCasServerProtocol3() { 31 | return Boolean.valueOf(getConfig().get("casServerProtocol3")); 32 | } 33 | 34 | public void setGateway(final boolean gateway) { 35 | getConfig().put("gateway", String.valueOf(gateway)); 36 | } 37 | 38 | public boolean isGateway() { 39 | return Boolean.valueOf(getConfig().get("gateway")); 40 | } 41 | 42 | public void setRenew(final boolean renew) { 43 | getConfig().put("renew", String.valueOf(renew)); 44 | } 45 | 46 | public boolean isRenew() { 47 | return Boolean.valueOf(getConfig().get("renew")); 48 | } 49 | 50 | public String getCasServerLoginUrl() { 51 | return String.format("%s/%s", getConfig().get("casServerUrlPrefix"), DEFAULT_CAS_LOGIN_SUFFFIX); 52 | } 53 | 54 | public String getCasServerLogoutUrl() { 55 | return String.format("%s/%s", getConfig().get("casServerUrlPrefix"), DEFAULT_CAS_LOGOUT_SUFFFIX); 56 | } 57 | 58 | public String getCasServiceValidateUrl() { 59 | return isCasServerProtocol3() ? 60 | String.format("%s/%s/%s", getConfig().get("casServerUrlPrefix"), DEFAULT_CAS_3_PROTOCOL_PREFIX, DEFAULT_CAS_SERVICE_VALIDATE_SUFFFIX) 61 | : String.format("%s/%s", getConfig().get("casServerUrlPrefix"), DEFAULT_CAS_SERVICE_VALIDATE_SUFFFIX); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/util/UrlHelper.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.util; 2 | 3 | import io.github.johnjcool.keycloak.broker.cas.CasIdentityProvider; 4 | import io.github.johnjcool.keycloak.broker.cas.CasIdentityProviderConfig; 5 | import org.keycloak.broker.provider.AuthenticationRequest; 6 | import org.keycloak.models.RealmModel; 7 | import org.keycloak.models.UserSessionModel; 8 | import org.keycloak.services.resources.IdentityBrokerService; 9 | import org.keycloak.services.resources.RealmsResource; 10 | 11 | import javax.ws.rs.core.UriBuilder; 12 | import javax.ws.rs.core.UriInfo; 13 | 14 | public final class UrlHelper { 15 | private static final String PROVIDER_PARAMETER_SERVICE = "service"; 16 | private static final String PROVIDER_PARAMETER_RENEW = "renew"; 17 | private static final String PROVIDER_PARAMETER_GATEWAY = "gateway"; 18 | public static final String PROVIDER_PARAMETER_TICKET = "ticket"; 19 | public static final String PROVIDER_PARAMETER_STATE = "state"; 20 | 21 | private UrlHelper() { 22 | // util 23 | } 24 | 25 | public static UriBuilder createAuthenticationUrl(final CasIdentityProviderConfig config, final AuthenticationRequest request) { 26 | UriBuilder builder = UriBuilder.fromUri(config.getCasServerLoginUrl()) 27 | .queryParam(PROVIDER_PARAMETER_SERVICE, createServiceUrl(request.getRedirectUri(), request.getState().getEncoded())); 28 | if (config.isRenew()) { 29 | builder.queryParam(PROVIDER_PARAMETER_RENEW, config.isRenew()); 30 | } 31 | if (config.isGateway()) { 32 | builder.queryParam(PROVIDER_PARAMETER_GATEWAY, config.isGateway()); 33 | } 34 | return builder; 35 | } 36 | 37 | public static UriBuilder createValidateServiceUrl(final CasIdentityProviderConfig config, final String ticket, final UriInfo uriInfo, final String state) { 38 | UriBuilder builder = UriBuilder.fromUri(config.getCasServiceValidateUrl()).queryParam(PROVIDER_PARAMETER_TICKET, ticket) 39 | .queryParam(PROVIDER_PARAMETER_SERVICE, createServiceUrl(uriInfo.getAbsolutePath().toString(), state)); 40 | if (config.isRenew()) { 41 | builder.queryParam(PROVIDER_PARAMETER_RENEW, config.isRenew()); 42 | } 43 | return builder; 44 | } 45 | 46 | public static UriBuilder createLogoutUrl(final CasIdentityProviderConfig config, final UserSessionModel userSession, final RealmModel realm, 47 | final UriInfo uriInfo) { 48 | final String redirect = RealmsResource.brokerUrl(uriInfo).path(IdentityBrokerService.class, "getEndpoint") 49 | .path(CasIdentityProvider.Endpoint.class, "logoutResponse").queryParam(PROVIDER_PARAMETER_STATE, userSession.getId()) 50 | .build(realm.getName(), config.getAlias()).toString(); 51 | return UriBuilder.fromUri(config.getCasServerLogoutUrl()).queryParam(PROVIDER_PARAMETER_SERVICE, redirect); 52 | } 53 | 54 | private static String createServiceUrl(final String serviceUrlPrefix, final String state) { 55 | return String.format("%s?%s=%s", serviceUrlPrefix, PROVIDER_PARAMETER_STATE, state); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/jaxb/AttributesWrapper.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.jaxb; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Optional; 8 | import java.util.function.Function; 9 | import java.util.stream.Collectors; 10 | 11 | import javax.xml.bind.JAXBElement; 12 | import javax.xml.bind.annotation.XmlAnyElement; 13 | import javax.xml.bind.annotation.XmlType; 14 | 15 | import org.w3c.dom.Element; 16 | 17 | @XmlType 18 | public class AttributesWrapper { 19 | 20 | private final List> attributes = new ArrayList<>(); 21 | 22 | @XmlAnyElement 23 | public List> getAttributes() { 24 | return attributes; 25 | } 26 | 27 | /** 28 | *

29 | * To Read-Only Map 30 | *

31 | * 32 | * @return 33 | */ 34 | public Map toMap() { 35 | // Note: Due to type erasure, you cannot use properties.stream() directly when unmashalling is used.. 36 | List attrs = attributes; 37 | return attrs.stream().collect(Collectors.toMap(AttributesWrapper::extractLocalName, AttributesWrapper::extractTextContent)); 38 | } 39 | 40 | /** 41 | *

42 | * Extract local name from obj, whether it's javax.xml.bind.JAXBElement or org.w3c.dom.Element; 43 | *

44 | * 45 | * @param obj 46 | * @return 47 | */ 48 | @SuppressWarnings("unchecked") 49 | private static String extractLocalName(final Object obj) { 50 | Map, Function> strFuncs = new HashMap<>(); 51 | strFuncs.put(JAXBElement.class, (jaxb) -> ((JAXBElement) jaxb).getName().getLocalPart()); 52 | strFuncs.put(Element.class, ele -> ((Element) ele).getLocalName()); 53 | return extractPart(obj, strFuncs).orElse(""); 54 | } 55 | 56 | /** 57 | *

58 | * Extract text content from obj, whether it's javax.xml.bind.JAXBElement or org.w3c.dom.Element; 59 | *

60 | * 61 | * @param obj 62 | * @return 63 | */ 64 | @SuppressWarnings("unchecked") 65 | private static String extractTextContent(final Object obj) { 66 | Map, Function> strFuncs = new HashMap<>(); 67 | strFuncs.put(JAXBElement.class, (jaxb) -> ((JAXBElement) jaxb).getValue()); 68 | strFuncs.put(Element.class, ele -> ((Element) ele).getTextContent()); 69 | return extractPart(obj, strFuncs).orElse(""); 70 | } 71 | 72 | /** 73 | * Check class type of obj according to types listed in strFuncs keys, then extract some string part from it according 74 | * to the extract function specified in strFuncs values. 75 | * 76 | * @param obj 77 | * @param strFuncs 78 | * @return 79 | */ 80 | private static Optional extractPart(final ObjType obj, final Map, Function> strFuncs) { 81 | for (Class clazz : strFuncs.keySet()) { 82 | if (clazz.isInstance(obj)) { 83 | return Optional.of(strFuncs.get(clazz).apply(obj)); 84 | } 85 | } 86 | return Optional.empty(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/mappers/AbstractAttributeMapper.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.mappers; 2 | 3 | import io.github.johnjcool.keycloak.broker.cas.CasIdentityProvider; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import org.keycloak.broker.provider.AbstractIdentityProviderMapper; 11 | import org.keycloak.broker.provider.BrokeredIdentityContext; 12 | import org.keycloak.models.IdentityProviderMapperModel; 13 | 14 | public abstract class AbstractAttributeMapper extends AbstractIdentityProviderMapper { 15 | 16 | public static final String ATTRIBUTE = "attribute"; 17 | public static final String ATTRIBUTE_VALUE = "attribute.value"; 18 | 19 | public static Object getAttributeValue(final IdentityProviderMapperModel mapperModel, final BrokeredIdentityContext user) { 20 | String attributeName = mapperModel.getConfig().get(ATTRIBUTE); 21 | @SuppressWarnings("unchecked") 22 | Map userAttributes = (Map) user.getContextData().get(CasIdentityProvider.USER_ATTRIBUTES); 23 | if (userAttributes.containsKey(attributeName)) { 24 | return getAttributeValue(userAttributes.get(attributeName)); 25 | } 26 | return null; 27 | } 28 | 29 | public static Object getAttributeValue(final Object userAttribute) { 30 | if (userAttribute instanceof String && ((String) userAttribute).startsWith("[") && ((String) userAttribute).endsWith("]")) { 31 | String userArrayAttribute = (String) userAttribute; 32 | String[] userAttributes = userArrayAttribute.substring(1, userArrayAttribute.length() - 1).split(", "); 33 | return new ArrayList<>(Arrays.asList(userAttributes)); 34 | } 35 | return userAttribute; 36 | } 37 | 38 | protected boolean hasAttributeValue(final IdentityProviderMapperModel mapperModel, final BrokeredIdentityContext context) { 39 | Object value = getAttributeValue(mapperModel, context); 40 | String desiredValue = mapperModel.getConfig().get(ATTRIBUTE_VALUE); 41 | return valueEquals(desiredValue, value); 42 | } 43 | 44 | public boolean valueEquals(final String desiredValue, final Object value) { 45 | if (value instanceof String) { 46 | if (desiredValue.equals(value)) { 47 | return true; 48 | } 49 | } else if (value instanceof Double) { 50 | try { 51 | if (Double.valueOf(desiredValue).equals(value)) { 52 | return true; 53 | } 54 | } catch (Exception e) { 55 | 56 | } 57 | } else if (value instanceof Integer) { 58 | try { 59 | if (Integer.valueOf(desiredValue).equals(value)) { 60 | return true; 61 | } 62 | } catch (Exception e) { 63 | 64 | } 65 | } else if (value instanceof Boolean) { 66 | try { 67 | if (Boolean.valueOf(desiredValue).equals(value)) { 68 | return true; 69 | } 70 | } catch (Exception e) { 71 | 72 | } 73 | } else if (value instanceof List) { 74 | List list = (List) value; 75 | for (Object val : list) { 76 | if (valueEquals(desiredValue, val)) { 77 | return true; 78 | } 79 | } 80 | } 81 | return false; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: java 4 | 5 | jdk: 6 | - openjdk11 7 | 8 | services: 9 | - docker 10 | 11 | cache: 12 | directories: 13 | - $HOME/.m2 14 | - $TRAVIS_BUILD_DIR/target 15 | 16 | addons: 17 | sonarcloud: 18 | organization: "johnjcool-github" 19 | 20 | stages: 21 | - compile 22 | - name: deploy_snapshot 23 | if: branch = master AND type = push 24 | - name: deploy_release 25 | if: tag IS present 26 | - code_quality 27 | 28 | jobs: 29 | include: 30 | - stage: compile 31 | - stage: deploy_snapshot 32 | before_script: 33 | - echo $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import 34 | - echo $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust 35 | - export project_version=$(mvn help:evaluate -N -Dexpression=project.version|grep -v '\[') 36 | - echo $project_version 37 | script: 38 | - mvn deploy --settings .travis/settings.xml -DskipTests=true -B -U -Prelease 39 | - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin 40 | - cp src/main/docker/Dockerfile target/Dockerfile 41 | - cd target 42 | - echo docker build --tag $DOCKER_USERNAME/keycloak-cas:$project_version --build-arg project_version=${project_version} . 43 | - docker build --tag $DOCKER_USERNAME/keycloak-cas:$project_version --build-arg project_version=${project_version} . 44 | - echo docker push $DOCKER_USERNAME/keycloak-cas:$project_version 45 | - docker push $DOCKER_USERNAME/keycloak-cas:$project_version 46 | - cd .. 47 | - stage: deploy_release 48 | before_script: 49 | - echo $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import 50 | - echo $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust 51 | - export project_version=$TRAVIS_TAG 52 | script: 53 | - mvn org.codehaus.mojo:versions-maven-plugin:2.5:set --settings .travis/settings.xml -DnewVersion=$project_version -B -U 54 | - mvn clean deploy --settings .travis/settings.xml -DskipTests=true -B -U -Prelease 55 | - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin 56 | - cp src/main/docker/Dockerfile target/Dockerfile 57 | - cd target 58 | - docker build --tag $DOCKER_USERNAME/keycloak-cas:$project_version --build-arg project_version=${project_version} . 59 | - docker push $DOCKER_USERNAME/keycloak-cas:$project_version 60 | - docker tag $DOCKER_USERNAME/keycloak-cas:$project_version $DOCKER_USERNAME/keycloak-cas:latest 61 | - docker push $DOCKER_USERNAME/keycloak-cas:latest 62 | - cd .. 63 | deploy: 64 | provider: releases 65 | api_key: 66 | secure: X5KxTm0nA7QzGrIOroEqLuByj5aZyygWpltIQzDl4SCHnNXJ79trc0FRjmcwCpcspSRWLxKiM5J8DseXxjaFP415BTj5iK8eV+631DgOqF87uJDv5jrw9nRTzzqA35f4N+WiLnOf/OkilYOkF3CTWryD1aqwY6MhEeGXrDj7JCWfXBDgtLgUTO4yLE3So52NxxWcOMub9Aef1vvyihtazeRli2D5eqnl0v7G6Rze4IRY90iDQ5JPISOwXsGc09VZKvejUWCNgW2lyLH+oXMUAlVvq672skb+ECuy+QwsTXlvqn853LmavmVySQkukr39iQjahSVCgt4i4fCGKYnee0vWQIuC3TtlhcursYCDPtuIZlB+xgevuf9miv3EflcY3x+rAnGxLsV5bYvmtR8v/RjaokyjamzYaiCjgb+x04LA7TcAguRnDFgE2FhM/OezEY3HmYvHJzFhmFM7v1nYF8r3bx5zpYGTEoAuCZuVt5Oehzoa6mMkAODR/0UaBeHtI6a6YzJm0hrJERKJpxdOCg8d5G74HT2kcWy/fR/nrTXTWRelOs34bzyQfIqUzzVX3jqOqun+JDMLNhX6bARNuAECtGAA8BChy2NPj1zasKBjJUwtcIf/C3MPwGz7C6nnljIWg25s/selveyNIveP2OtIPAa+uwB1PqR53nYxatQ= 67 | file: 68 | - target/keycloak-cas-services-$project_version.jar 69 | - target/keycloak-cas-services-$project_version-javadoc.jar 70 | - target/keycloak-cas-services-$project_version-sources.jar 71 | skip_cleanup: true 72 | on: 73 | tags: true 74 | - stage: code_quality 75 | script: 76 | - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -Dsonar.login=$SONAR_TOKEN 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.johnjcool/keycloak-cas-services/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.johnjcool/keycloak-cas-services) [![Build Status](https://travis-ci.com/johnjcool/keycloak-cas-services.svg?branch=master)](https://travis-ci.com/johnjcool/keycloak-cas-services) [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=io.github.johnjcool%3Akeycloak-cas-services&metric=alert_status)](https://sonarcloud.io/dashboard/index/io.github.johnjcool%3Akeycloak-cas-services) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=io.github.johnjcool%3Akeycloak-cas-services&metric=coverage)](https://sonarcloud.io/component_measures?id=io.github.johnjcool%3Akeycloak-cas-services&metric=coverage) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=io.github.johnjcool%3Akeycloak-cas-services&metric=bugs)](https://sonarcloud.io/component_measures?id=io.github.johnjcool%3Akeycloak-cas-services&metric=bugs) [![Code smells](https://sonarcloud.io/api/project_badges/measure?project=io.github.johnjcool%3Akeycloak-cas-services&metric=code_smells)](https://sonarcloud.io/component_measures?id=io.github.johnjcool%3Akeycloak-cas-services&metric=code_smells) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=io.github.johnjcool%3Akeycloak-cas-services&metric=security_rating)](https://sonarcloud.io/component_measures?id=io.github.johnjcool%3Akeycloak-cas-services&metric=security_rating) 2 | 3 | Keycloak CAS Services 4 | ===================== 5 | 6 | Using as maven dependency 7 | ------------------------- 8 | You can use this module as dependency in your own modules. 9 | ``` 10 | 11 | io.github.johnjcool 12 | keycloak-cas-services 13 | 4.8.3.Final 14 | 15 | ``` 16 | 17 | Manual Deployment 18 | ----------------- 19 | 1. Download keycloak version from [https://www.keycloak.org/](https://www.keycloak.org/) 20 | 2. Download corresponding keycloak-cas-services version from [maven central](https://search.maven.org/search?q=g:io.github.johnjcool%20AND%20a:keycloak-cas-services&core=gav) 21 | 3. Copy keycloak-cas-services-.jar to ```/standalone/deployments``` 22 | 4. Start keycloak with ```/bin/standalone.``` 23 | 5. Navigate to [http://localhost:8080](http://localhost:8080) and create an admin account 24 | 25 | Using docker image 26 | ------------------ 27 | Start ready to use docker image: 28 | ```sh 29 | docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=xxxxxx johnjcool/keycloak-cas 30 | ``` 31 | 32 | Central Authentication Service Configuration 33 | -------------------------------------------- 34 | 1. Navigate to [http://localhost:8080/auth/admin](http://localhost:8080/auth/admin) 35 | 2. Login with your admin credentials 36 | 3. Navigate to Themes **Important!!! You have to do this on master realm** 37 | 4. Switch Admin Console Theme to keycloak-extended 38 | 5. Signout 39 | 6. Login with your admin credentials 40 | 7. Navigate to Identity Providers 41 | 8. Add provider CAS 42 | 9. Configure CAS provider 43 | 10. Click Save 44 | 11. Navigate to Mappers to get Attributes from CAS 45 | 12. Configure Attribute Mapper for email, firstName, lastName 46 | 13. Signout and Central Authentication Service should be available 47 | 48 | Optional Central Authentication Service Configuration 49 | -------------------------------------------- 50 | 1. Login with your admin credentials 51 | 2. Navigate to Authetication 52 | 3. Click on Actions/Config for Identity Provider Redirector 53 | 4. Set Alias and Default Identiy Provider to ```cas``` 54 | 5. Signout and now you are automatically redirected to CAS for Login 55 | 56 | 57 | **Have fun!** 58 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/mappers/AttributeToRoleMapper.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.mappers; 2 | 3 | import io.github.johnjcool.keycloak.broker.cas.CasIdentityProviderFactory; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.keycloak.broker.provider.BrokeredIdentityContext; 9 | import org.keycloak.broker.provider.ConfigConstants; 10 | import org.keycloak.broker.provider.IdentityBrokerException; 11 | import org.keycloak.models.IdentityProviderMapperModel; 12 | import org.keycloak.models.KeycloakSession; 13 | import org.keycloak.models.RealmModel; 14 | import org.keycloak.models.RoleModel; 15 | import org.keycloak.models.UserModel; 16 | import org.keycloak.models.utils.KeycloakModelUtils; 17 | import org.keycloak.provider.ProviderConfigProperty; 18 | 19 | public class AttributeToRoleMapper extends AbstractAttributeMapper { 20 | 21 | protected static final String[] COMPATIBLE_PROVIDERS = { CasIdentityProviderFactory.PROVIDER_ID }; 22 | 23 | private static final List configProperties = new ArrayList<>(); 24 | 25 | static { 26 | ProviderConfigProperty property; 27 | ProviderConfigProperty property1; 28 | property1 = new ProviderConfigProperty(); 29 | property1.setName(ATTRIBUTE); 30 | property1.setLabel("Attribute Name"); 31 | property1.setHelpText("Name of attribute to search for in assertion."); 32 | property1.setType(ProviderConfigProperty.STRING_TYPE); 33 | configProperties.add(property1); 34 | property1 = new ProviderConfigProperty(); 35 | property1.setName(ATTRIBUTE_VALUE); 36 | property1.setLabel("Attribute Value"); 37 | property1.setHelpText("Value the attribute must have. If the attribute is an array, then the value must be contained in the array."); 38 | property1.setType(ProviderConfigProperty.STRING_TYPE); 39 | configProperties.add(property1); 40 | property = new ProviderConfigProperty(); 41 | property.setName(ConfigConstants.ROLE); 42 | property.setLabel("Role"); 43 | property.setHelpText("Role to grant to user if attribute is present. Click 'Select Role' button to browse roles, or just type it in the textbox. To reference an application role the syntax is appname.approle, i.e. myapp.myrole"); 44 | property.setType(ProviderConfigProperty.ROLE_TYPE); 45 | configProperties.add(property); 46 | } 47 | 48 | public static final String PROVIDER_ID = "cas-role-idp-mapper"; 49 | 50 | @Override 51 | public List getConfigProperties() { 52 | return configProperties; 53 | } 54 | 55 | @Override 56 | public String getId() { 57 | return PROVIDER_ID; 58 | } 59 | 60 | @Override 61 | public String[] getCompatibleProviders() { 62 | return COMPATIBLE_PROVIDERS; 63 | } 64 | 65 | @Override 66 | public String getDisplayCategory() { 67 | return "Role Importer"; 68 | } 69 | 70 | @Override 71 | public String getDisplayType() { 72 | return "Attribute to Role"; 73 | } 74 | 75 | @Override 76 | public void importNewUser(final KeycloakSession session, final RealmModel realm, final UserModel user, final IdentityProviderMapperModel mapperModel, 77 | final BrokeredIdentityContext context) { 78 | String roleName = mapperModel.getConfig().get(ConfigConstants.ROLE); 79 | if (hasAttributeValue(mapperModel, context)) { 80 | RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName); 81 | if (role == null) { 82 | throw new IdentityBrokerException("Unable to find role: " + roleName); 83 | } 84 | user.grantRole(role); 85 | } 86 | } 87 | 88 | @Override 89 | public void updateBrokeredUser(final KeycloakSession session, final RealmModel realm, final UserModel user, final IdentityProviderMapperModel mapperModel, 90 | final BrokeredIdentityContext context) { 91 | String roleName = mapperModel.getConfig().get(ConfigConstants.ROLE); 92 | if (!hasAttributeValue(mapperModel, context)) { 93 | RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName); 94 | if (role == null) { 95 | throw new IdentityBrokerException("Unable to find role: " + roleName); 96 | } 97 | user.deleteRoleMapping(role); 98 | } 99 | 100 | } 101 | 102 | @Override 103 | public String getHelpText() { 104 | return "If a attribute exists, grant the user the specified realm or application role."; 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/test/java/io/github/johnjcool/keycloak/broker/cas/model/ServiceResponseTest.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.model; 2 | 3 | import io.github.johnjcool.keycloak.broker.cas.jaxb.ServiceResponseJaxbContextResolver; 4 | import io.github.johnjcool.keycloak.broker.cas.jaxb.ServiceResponseJaxbProvider; 5 | import io.undertow.Undertow; 6 | 7 | import java.io.File; 8 | import java.util.HashSet; 9 | import java.util.Set; 10 | 11 | import javax.ws.rs.ApplicationPath; 12 | import javax.ws.rs.Consumes; 13 | import javax.ws.rs.GET; 14 | import javax.ws.rs.Path; 15 | import javax.ws.rs.Produces; 16 | import javax.ws.rs.client.Client; 17 | import javax.ws.rs.client.WebTarget; 18 | import javax.ws.rs.core.Application; 19 | import javax.ws.rs.core.Response; 20 | 21 | import org.apache.commons.io.FileUtils; 22 | import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; 23 | import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer; 24 | import org.jboss.resteasy.spi.ResteasyProviderFactory; 25 | import org.junit.AfterClass; 26 | import org.junit.Assert; 27 | import org.junit.BeforeClass; 28 | import org.junit.Test; 29 | 30 | public class ServiceResponseTest { 31 | 32 | private static UndertowJaxrsServer server; 33 | 34 | @Test 35 | public void testReadWithAttributes() { 36 | server.deploy(MyApp.class); 37 | ResteasyProviderFactory.getInstance().registerProvider(ServiceResponseJaxbProvider.class, true); 38 | ResteasyProviderFactory.getInstance().registerProvider(ServiceResponseJaxbContextResolver.class, true); 39 | Client client = ResteasyClientBuilder.newClient(ResteasyProviderFactory.getInstance()); 40 | WebTarget target = client.target(String.format("http://%s:%d%s", "localhost", 9999, "/with-attributes")); 41 | Response response = target.request().get(); 42 | Assert.assertEquals(200, response.getStatus()); 43 | response.bufferEntity(); 44 | 45 | System.out.println(response.readEntity(String.class)); 46 | 47 | ServiceResponse serviceResponse = response.readEntity(ServiceResponse.class); 48 | Success success = serviceResponse.getSuccess(); 49 | 50 | Assert.assertEquals("test", success.getUser()); 51 | Assert.assertTrue(!success.getAttributes().isEmpty()); 52 | } 53 | 54 | @Test 55 | public void testReadWithoutAttributes() { 56 | server.deploy(MyApp.class); 57 | ResteasyProviderFactory.getInstance().registerProvider(ServiceResponseJaxbProvider.class, true); 58 | ResteasyProviderFactory.getInstance().registerProvider(ServiceResponseJaxbContextResolver.class, true); 59 | Client client = ResteasyClientBuilder.newClient(ResteasyProviderFactory.getInstance()); 60 | WebTarget target = client.target(String.format("http://%s:%d%s", "localhost", 9999, "/without-attributes")); 61 | Response response = target.request().get(); 62 | Assert.assertEquals(200, response.getStatus()); 63 | response.bufferEntity(); 64 | 65 | System.out.println(response.readEntity(String.class)); 66 | 67 | ServiceResponse serviceResponse = response.readEntity(ServiceResponse.class); 68 | Success success = serviceResponse.getSuccess(); 69 | 70 | Assert.assertEquals("test", success.getUser()); 71 | Assert.assertTrue(success.getAttributes().isEmpty()); 72 | } 73 | 74 | @Path("") 75 | static public class Resource { 76 | 77 | @GET 78 | @Path("with-attributes") 79 | @Consumes("*/*") 80 | @Produces("text/html; charset=UTF-8") 81 | public String withAttributes() throws Exception { 82 | return FileUtils.readFileToString(new File("src/test/resources/test-with-attributes.xml"), "UTF-8"); 83 | } 84 | 85 | @GET 86 | @Path("without-attributes") 87 | @Consumes("*/*") 88 | @Produces("text/html; charset=UTF-8") 89 | public String withoutAttributes() throws Exception { 90 | return FileUtils.readFileToString(new File("src/test/resources/test-without-attributes.xml"), "UTF-8"); 91 | } 92 | } 93 | 94 | @ApplicationPath("") 95 | public static class MyApp extends Application { 96 | @Override 97 | public Set> getClasses() { 98 | HashSet> classes = new HashSet>(); 99 | classes.add(Resource.class); 100 | return classes; 101 | } 102 | } 103 | 104 | @BeforeClass 105 | public static void init() throws Exception { 106 | server = new UndertowJaxrsServer().start(Undertow.builder().addHttpListener(9999, "localhost")); 107 | } 108 | 109 | @AfterClass 110 | public static void stop() throws Exception { 111 | server.stop(); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/mappers/UserAttributeMapper.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas.mappers; 2 | 3 | import io.github.johnjcool.keycloak.broker.cas.CasIdentityProviderFactory; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | import java.util.List; 8 | import java.util.Objects; 9 | import java.util.function.Consumer; 10 | import java.util.stream.Collectors; 11 | 12 | import org.keycloak.broker.provider.BrokeredIdentityContext; 13 | import org.keycloak.common.util.CollectionUtil; 14 | import org.keycloak.models.IdentityProviderMapperModel; 15 | import org.keycloak.models.KeycloakSession; 16 | import org.keycloak.models.RealmModel; 17 | import org.keycloak.models.UserModel; 18 | import org.keycloak.provider.ProviderConfigProperty; 19 | 20 | public class UserAttributeMapper extends AbstractAttributeMapper { 21 | 22 | private static final String[] cp = new String[] { CasIdentityProviderFactory.PROVIDER_ID }; 23 | 24 | private static final List configProperties = new ArrayList<>(); 25 | 26 | private static final String ATTRIBUTE = "attribute"; 27 | private static final String USER_ATTRIBUTE = "user.attribute"; 28 | private static final String EMAIL = "email"; 29 | private static final String FIRST_NAME = "firstName"; 30 | private static final String LAST_NAME = "lastName"; 31 | 32 | static { 33 | ProviderConfigProperty property; 34 | property = new ProviderConfigProperty(); 35 | property.setName(ATTRIBUTE); 36 | property.setLabel("Attribute"); 37 | property.setHelpText("Name of attribute to search for in assertion."); 38 | property.setType(ProviderConfigProperty.STRING_TYPE); 39 | configProperties.add(property); 40 | property = new ProviderConfigProperty(); 41 | property.setName(USER_ATTRIBUTE); 42 | property.setLabel("User Attribute Name"); 43 | property.setHelpText("User attribute name to store CAS attribute. Use email, lastName, and firstName to map to those predefined user properties."); 44 | property.setType(ProviderConfigProperty.STRING_TYPE); 45 | configProperties.add(property); 46 | } 47 | 48 | public static final String PROVIDER_ID = "cas-user-attribute-idp-mapper"; 49 | 50 | @Override 51 | public List getConfigProperties() { 52 | return configProperties; 53 | } 54 | 55 | @Override 56 | public String getId() { 57 | return PROVIDER_ID; 58 | } 59 | 60 | @Override 61 | public String[] getCompatibleProviders() { 62 | return cp; 63 | } 64 | 65 | @Override 66 | public String getDisplayCategory() { 67 | return "Attribute Importer"; 68 | } 69 | 70 | @Override 71 | public String getDisplayType() { 72 | return "Attribute Importer"; 73 | } 74 | 75 | @Override 76 | public void preprocessFederatedIdentity(final KeycloakSession session, final RealmModel realm, final IdentityProviderMapperModel mapperModel, 77 | final BrokeredIdentityContext context) { 78 | String attribute = mapperModel.getConfig().get(USER_ATTRIBUTE); 79 | if (attribute == null || attribute.isEmpty()) { 80 | return; 81 | } 82 | 83 | Object value = getAttributeValue(mapperModel, context); 84 | List values = toList(value); 85 | 86 | if (EMAIL.equalsIgnoreCase(attribute)) { 87 | setIfNotEmpty(context::setEmail, values); 88 | } else if (FIRST_NAME.equalsIgnoreCase(attribute)) { 89 | setIfNotEmpty(context::setFirstName, values); 90 | } else if (LAST_NAME.equalsIgnoreCase(attribute)) { 91 | setIfNotEmpty(context::setLastName, values); 92 | } else { 93 | List valuesToString = values.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.toList()); 94 | context.setUserAttribute(attribute, valuesToString); 95 | } 96 | } 97 | 98 | private void setIfNotEmpty(final Consumer consumer, final List values) { 99 | if (values != null && !values.isEmpty()) { 100 | consumer.accept(values.get(0)); 101 | } 102 | } 103 | 104 | @SuppressWarnings({ "rawtypes", "unchecked" }) 105 | private List toList(final Object value) { 106 | List values = (value instanceof List) ? (List) value : Collections.singletonList(value); 107 | return values.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.toList()); 108 | } 109 | 110 | @Override 111 | public void updateBrokeredUser(final KeycloakSession session, final RealmModel realm, final UserModel user, final IdentityProviderMapperModel mapperModel, 112 | final BrokeredIdentityContext context) { 113 | String attribute = mapperModel.getConfig().get(USER_ATTRIBUTE); 114 | if (attribute == null || attribute.isEmpty()) { 115 | return; 116 | } 117 | Object value = getAttributeValue(mapperModel, context); 118 | List values = toList(value); 119 | if (EMAIL.equalsIgnoreCase(attribute)) { 120 | setIfNotEmpty(user::setEmail, values); 121 | } else if (FIRST_NAME.equalsIgnoreCase(attribute)) { 122 | setIfNotEmpty(user::setFirstName, values); 123 | } else if (LAST_NAME.equalsIgnoreCase(attribute)) { 124 | setIfNotEmpty(user::setLastName, values); 125 | } else { 126 | List current = user.getAttribute(attribute); 127 | if (!CollectionUtil.collectionEquals(values, current)) { 128 | user.setAttribute(attribute, values); 129 | } else if (values.isEmpty()) { 130 | user.removeAttribute(attribute); 131 | } 132 | } 133 | } 134 | 135 | @Override 136 | public String getHelpText() { 137 | return "Import declared CAS attribute if it exists in assertion into the specified user property or attribute."; 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | io.github.johnjcool 6 | keycloak-cas-services 7 | 8.0.0-SNAPSHOT 8 | Keycloak CAS Services 9 | https://github.com/johnjcool/keycloak-cas-services 10 | Extend Keycloack with CAS IDP. 11 | 12 | 13 | 14 | Apache License, Version 2.0 15 | http://www.apache.org/licenses/LICENSE-2.0.txt 16 | repo 17 | 18 | 19 | 20 | 21 | https://github.com/johnjcool/keycloak-cas-services 22 | scm:git:https://github.com/johnjcool/keycloak-cas-services.git 23 | scm:git:https://github.com/johnjcool/keycloak-cas-services.git 24 | 25 | 26 | 27 | 28 | John J Cool 29 | john.j.cool@gmail.com 30 | 31 | 32 | 33 | 34 | 8.0.0 35 | 36 | 1.8 37 | 1.8 38 | 39 | 40 | 41 | 42 | 43 | org.keycloak 44 | keycloak-parent 45 | ${keycloak.version} 46 | pom 47 | import 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.keycloak 55 | keycloak-core 56 | provided 57 | 58 | 59 | org.keycloak 60 | keycloak-server-spi 61 | provided 62 | 63 | 64 | org.keycloak 65 | keycloak-server-spi-private 66 | provided 67 | 68 | 69 | org.jboss.logging 70 | jboss-logging 71 | provided 72 | 73 | 74 | org.keycloak 75 | keycloak-services 76 | provided 77 | 78 | 79 | org.keycloak 80 | keycloak-saml-core-public 81 | 82 | 83 | org.keycloak 84 | keycloak-model-jpa 85 | 86 | 87 | 88 | junit 89 | junit 90 | test 91 | 92 | 93 | org.jboss.resteasy 94 | resteasy-undertow 95 | test 96 | 97 | 98 | io.undertow 99 | undertow-servlet 100 | test 101 | 102 | 103 | 104 | 105 | 106 | 107 | org.apache.maven.plugins 108 | maven-jar-plugin 109 | 3.0.2 110 | 111 | 112 | 113 | org.keycloak.keycloak-services 114 | 115 | 116 | 117 | 118 | 119 | org.apache.maven.plugins 120 | maven-source-plugin 121 | 3.0.1 122 | 123 | 124 | attach-sources 125 | 126 | jar-no-fork 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | release 138 | 139 | 140 | 141 | false 142 | 143 | bintray-cy6ergn0m-maven 144 | bintray-plugins 145 | http://dl.bintray.com/cy6ergn0m/maven 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | org.sonatype.plugins 154 | nexus-staging-maven-plugin 155 | 1.6.8 156 | true 157 | 158 | ossrh 159 | https://oss.sonatype.org/ 160 | true 161 | 162 | 163 | 164 | org.apache.maven.plugins 165 | maven-javadoc-plugin 166 | 2.10.4 167 | 168 | 169 | attach-javadocs 170 | 171 | jar 172 | 173 | 174 | 175 | 176 | 177 | 178 | org.apache.maven.plugins 179 | maven-gpg-plugin 180 | 1.6 181 | 182 | 183 | sign-artifacts 184 | verify 185 | 186 | sign 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | keycloak-cas-services.wiki 199 | https://github.com/johnjcool/keycloak-cas-services/wiki 200 | 201 | 202 | 203 | ossrh 204 | https://oss.sonatype.org/content/repositories/snapshots 205 | 206 | 207 | ossrh 208 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 209 | 210 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /src/main/java/io/github/johnjcool/keycloak/broker/cas/CasIdentityProvider.java: -------------------------------------------------------------------------------- 1 | package io.github.johnjcool.keycloak.broker.cas; 2 | 3 | import static io.github.johnjcool.keycloak.broker.cas.util.UrlHelper.PROVIDER_PARAMETER_STATE; 4 | import static io.github.johnjcool.keycloak.broker.cas.util.UrlHelper.PROVIDER_PARAMETER_TICKET; 5 | import static io.github.johnjcool.keycloak.broker.cas.util.UrlHelper.createAuthenticationUrl; 6 | import static io.github.johnjcool.keycloak.broker.cas.util.UrlHelper.createLogoutUrl; 7 | import static io.github.johnjcool.keycloak.broker.cas.util.UrlHelper.createValidateServiceUrl; 8 | import io.github.johnjcool.keycloak.broker.cas.model.ServiceResponse; 9 | import io.github.johnjcool.keycloak.broker.cas.model.Success; 10 | 11 | import java.net.URI; 12 | 13 | import javax.ws.rs.GET; 14 | import javax.ws.rs.Path; 15 | import javax.ws.rs.QueryParam; 16 | import javax.ws.rs.client.Client; 17 | import javax.ws.rs.client.WebTarget; 18 | import javax.ws.rs.core.Context; 19 | import javax.ws.rs.core.HttpHeaders; 20 | import javax.ws.rs.core.MediaType; 21 | import javax.ws.rs.core.Response; 22 | import javax.ws.rs.core.Response.Status; 23 | import javax.ws.rs.core.UriInfo; 24 | 25 | import org.jboss.logging.Logger; 26 | import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; 27 | import org.jboss.resteasy.spi.ResteasyProviderFactory; 28 | import org.keycloak.broker.provider.AbstractIdentityProvider; 29 | import org.keycloak.broker.provider.AuthenticationRequest; 30 | import org.keycloak.broker.provider.BrokeredIdentityContext; 31 | import org.keycloak.broker.provider.IdentityBrokerException; 32 | import org.keycloak.common.ClientConnection; 33 | import org.keycloak.events.Errors; 34 | import org.keycloak.events.EventBuilder; 35 | import org.keycloak.events.EventType; 36 | import org.keycloak.models.FederatedIdentityModel; 37 | import org.keycloak.models.KeycloakSession; 38 | import org.keycloak.models.RealmModel; 39 | import org.keycloak.models.UserSessionModel; 40 | import org.keycloak.services.ErrorPage; 41 | import org.keycloak.services.managers.AuthenticationManager; 42 | import org.keycloak.services.messages.Messages; 43 | 44 | public class CasIdentityProvider extends AbstractIdentityProvider { 45 | 46 | protected static final Logger logger = Logger.getLogger(CasIdentityProvider.class); 47 | protected static final Logger LOGGER_DUMP_USER_PROFILE = Logger.getLogger("org.keycloak.social.user_profile_dump"); 48 | 49 | public static final String USER_ATTRIBUTES = "UserAttributes"; 50 | 51 | private final Client client; 52 | 53 | public CasIdentityProvider(final KeycloakSession session, final CasIdentityProviderConfig config) { 54 | super(session, config); 55 | client = ResteasyClientBuilder.newClient(ResteasyProviderFactory.getInstance()); 56 | } 57 | 58 | @Override 59 | public Response performLogin(final AuthenticationRequest request) { 60 | try { 61 | URI authenticationUrl = createAuthenticationUrl(getConfig(), request).build(); 62 | return Response.seeOther(authenticationUrl).build(); 63 | } catch (Exception e) { 64 | throw new IdentityBrokerException("Could send authentication request to cas provider.", e); 65 | } 66 | } 67 | 68 | @Override 69 | public Response keycloakInitiatedBrowserLogout(final KeycloakSession session, final UserSessionModel userSession, final UriInfo uriInfo, 70 | final RealmModel realm) { 71 | URI logoutUrl = createLogoutUrl(getConfig(), userSession, realm, uriInfo).build(); 72 | return Response.status(302).location(logoutUrl).build(); 73 | } 74 | 75 | @Override 76 | public Response retrieveToken(final KeycloakSession session, final FederatedIdentityModel identity) { 77 | return Response.ok(identity.getToken()).type(MediaType.APPLICATION_JSON).build(); 78 | } 79 | 80 | @Override 81 | public Object callback(final RealmModel realm, final org.keycloak.broker.provider.IdentityProvider.AuthenticationCallback callback, final EventBuilder event) { 82 | return new Endpoint(callback, realm, event); 83 | } 84 | 85 | public final class Endpoint { 86 | AuthenticationCallback callback; 87 | RealmModel realm; 88 | EventBuilder event; 89 | 90 | @Context 91 | protected KeycloakSession session; 92 | 93 | @Context 94 | protected ClientConnection clientConnection; 95 | 96 | @Context 97 | protected HttpHeaders headers; 98 | 99 | @Context 100 | protected UriInfo uriInfo; 101 | 102 | Endpoint(final AuthenticationCallback callback, final RealmModel realm, final EventBuilder event) { 103 | this.callback = callback; 104 | this.realm = realm; 105 | this.event = event; 106 | } 107 | 108 | @GET 109 | public Response authResponse(@QueryParam(PROVIDER_PARAMETER_TICKET) final String ticket, @QueryParam(PROVIDER_PARAMETER_STATE) final String state) { 110 | try { 111 | CasIdentityProviderConfig config = getConfig(); 112 | BrokeredIdentityContext federatedIdentity = getFederatedIdentity(client, config, ticket, uriInfo, state); 113 | 114 | return callback.authenticated(federatedIdentity); 115 | } catch (Exception e) { 116 | logger.error("Failed to call delegating authentication identity provider's callback method.", e); 117 | } 118 | event.event(EventType.LOGIN); 119 | event.error(Errors.IDENTITY_PROVIDER_LOGIN_FAILURE); 120 | return ErrorPage.error(session, null, Status.EXPECTATION_FAILED, Messages.IDENTITY_PROVIDER_UNEXPECTED_ERROR); 121 | } 122 | 123 | @GET 124 | @Path("logout_response") 125 | public Response logoutResponse(@Context final UriInfo uriInfo, @QueryParam("state") final String state) { 126 | UserSessionModel userSession = session.sessions().getUserSession(realm, state); 127 | if (userSession == null) { 128 | logger.error("no valid user session"); 129 | EventBuilder e = new EventBuilder(realm, session, clientConnection); 130 | e.event(EventType.LOGOUT); 131 | e.error(Errors.USER_SESSION_NOT_FOUND); 132 | return ErrorPage.error(session, null, Response.Status.BAD_REQUEST, Messages.IDENTITY_PROVIDER_UNEXPECTED_ERROR); 133 | } 134 | if (userSession.getState() != UserSessionModel.State.LOGGING_OUT) { 135 | logger.error("usersession in different state"); 136 | EventBuilder e = new EventBuilder(realm, session, clientConnection); 137 | e.event(EventType.LOGOUT); 138 | e.error(Errors.USER_SESSION_NOT_FOUND); 139 | return ErrorPage.error(session, null, Response.Status.BAD_REQUEST, Messages.SESSION_NOT_ACTIVE); 140 | } 141 | return AuthenticationManager.finishBrowserLogout(session, realm, userSession, uriInfo, clientConnection, headers); 142 | } 143 | 144 | private BrokeredIdentityContext getFederatedIdentity(final Client client, final CasIdentityProviderConfig config, final String ticket, 145 | final UriInfo uriInfo, final String state) { 146 | Response response = null; 147 | try { 148 | WebTarget target = client.target(createValidateServiceUrl(config, ticket, uriInfo, state)); 149 | response = target.request(MediaType.APPLICATION_XML_TYPE).get(); 150 | if (response.getStatus() != 200) { 151 | throw new Exception("Failed : HTTP error code : " + response.getStatus()); 152 | } 153 | 154 | response.bufferEntity(); 155 | if (LOGGER_DUMP_USER_PROFILE.isDebugEnabled()) { 156 | LOGGER_DUMP_USER_PROFILE.debug("User Profile XML Data for provider " + config.getAlias() + ": " + response.readEntity(String.class)); 157 | } 158 | 159 | ServiceResponse serviceResponse = response.readEntity(ServiceResponse.class); 160 | if (serviceResponse.getFailure() != null) { 161 | throw new Exception(serviceResponse.getFailure().getCode() + "(" + serviceResponse.getFailure().getDescription() 162 | + ") for authentication by External IdP " + config.getProviderId()); 163 | } 164 | Success success = serviceResponse.getSuccess(); 165 | BrokeredIdentityContext user = new BrokeredIdentityContext(success.getUser()); 166 | user.setUsername(success.getUser()); 167 | user.getContextData().put(USER_ATTRIBUTES, success.getAttributes()); 168 | user.setIdpConfig(config); 169 | user.setIdp(CasIdentityProvider.this); 170 | user.setCode(state); 171 | return user; 172 | } catch (Exception e) { 173 | throw new IdentityBrokerException("Could not fetch attributes from External IdP's userinfo endpoint.", e); 174 | } finally { 175 | if (response != null) { 176 | response.close(); 177 | } 178 | } 179 | } 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /src/main/resources/theme/keycloak-extended/admin/resources/partials/realm-identity-provider-cas.html: -------------------------------------------------------------------------------- 1 |
2 | 8 | 9 | 10 | 11 |
12 |
13 |
14 | 15 |
16 | 17 |
18 | {{:: 'redirect-uri.tooltip' | translate}} 19 |
20 |
21 |
22 |
23 | 24 |
25 | 26 |
27 | {{:: 'identity-provider.alias.tooltip' | translate}} 28 |
29 |
30 | 31 |
32 | 33 |
34 | {{:: 'identity-provider.display-name.tooltip' | translate}} 35 |
36 |
37 | 38 |
39 | 40 |
41 | {{:: 'identity-provider.enabled.tooltip' | translate}} 42 |
43 |
44 | 45 |
46 | 47 |
48 | {{:: 'trust-email.tooltip' | translate}} 49 |
50 |
51 | 52 |
53 | 54 |
55 | {{:: 'link-only.tooltip' | translate}} 56 |
57 |
58 | 59 |
60 | 61 |
62 | {{:: 'hide-on-login-page.tooltip' | translate}} 63 |
64 |
65 | 66 |
67 | 68 |
69 | {{:: 'gui-order.tooltip' | translate}} 70 |
71 |
72 | 73 |
74 |
75 | 80 |
81 |
82 | {{:: 'first-broker-login-flow.tooltip' | translate}} 83 |
84 |
85 | 86 |
87 |
88 | 92 |
93 |
94 | {{:: 'post-broker-login-flow.tooltip' | translate}} 95 |
96 |
97 | 98 | 99 |
100 | {{:: 'cas-config' | translate}} {{:: 'cas-config.tooltip' | translate}} 101 |
102 | 103 |
104 | 105 |
106 | {{:: 'cas-server-url-prefix.tooltip' | translate}} 107 |
108 |
109 | 110 |
111 | 112 |
113 | {{:: 'cas-server-protocol3.tooltip' | translate}} 114 |
115 |
116 | 117 |
118 | 119 |
120 | {{:: 'cas-gateway.tooltip' | translate}} 121 |
122 |
123 | 124 |
125 | 126 |
127 | {{:: 'cas-renew.tooltip' | translate}} 128 |
129 |
130 | 131 | 132 |
133 | {{:: 'import-external-idp-config' | translate}} {{:: 'import-external-idp-config.tooltip' | translate}} 134 |
135 | 136 |
137 | 138 |
139 | {{:: 'identity-provider.import-from-url.tooltip' | translate}} 140 |
141 |
142 | 143 |
144 | 145 |
146 |
147 |
148 | 149 | {{:: 'identity-provider.import-from-file.tooltip' | translate}} 150 |
151 |
152 | 153 | 154 |
155 | 156 | {{files[0].name}} 157 | 158 |
159 |
160 | 161 |
162 | 163 |
164 |
165 |
166 |
167 | 168 |
169 |
170 | 171 | 172 |
173 |
174 |
175 |
176 | 177 | 178 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------