Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[NOTASK]
CAS updates
updated sample integration for shib idp that uses the v2 protocol endpoint
allow for use of v2 protocol (since that's what the shib idp supports)
updated tests
Jj! committed Nov 6, 2023
1 parent 7d40f06 commit 767262d
Showing 5 changed files with 74 additions and 49 deletions.
@@ -59,12 +59,13 @@ public static void setProperties(BaseClientConfiguration configuration, String a
try {
Method method = getSetter(clazz, getMethodNameFromFieldName(fieldName));
method.invoke(configuration, getProperty(grouperConfig, method.getParameterTypes()[0], name));
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException |
ClassNotFoundException e) {
try {
Field field = getField(clazz, fieldName);
field.setAccessible(true);
field.set(configuration, getProperty(grouperConfig, field.getType(), name));
} catch (NoSuchFieldException | IllegalAccessException ex) {
} catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException ex) {
throw new RuntimeException("could not set " + fieldName, ex);
}
}
@@ -92,55 +93,59 @@ private static Method getSetter(Class clazz, String name) throws NoSuchMethodExc
return Arrays.stream(clazz.getMethods()).filter(m -> m.getName().equals(name)).findFirst().orElseThrow(NoSuchMethodException::new);
}

private static Object getProperty(ConfigPropertiesCascadeBase configPropertiesCascadeBase, Type type, String propName) {
switch (type.getTypeName()) {
case "java.lang.String" : {
return configPropertiesCascadeBase.propertyValueString(propName);
}
case "int" :
case "java.lang.Integer" : {
return configPropertiesCascadeBase.propertyValueInt(propName);
}
case "long" :
case "java.lang.Long" : {
return Long.parseLong(configPropertiesCascadeBase.propertyValueString(propName));
}
case "double" :
case "java.lang.Double" : {
return Double.parseDouble(configPropertiesCascadeBase.propertyValueString(propName));
}
case "boolean" :
case "java.lang.Boolean" : {
return configPropertiesCascadeBase.propertyValueBoolean(propName);
}
case "java.util.List" :
case "java.util.Collection" :{
return Arrays.asList(configPropertiesCascadeBase.propertyValueString(propName).split(","));
}
case "java.util.Set" : {
Set set = new HashSet();
for (String prop : configPropertiesCascadeBase.propertyValueString(propName).split(",")) {
set.add(prop);
private static Object getProperty(ConfigPropertiesCascadeBase configPropertiesCascadeBase, Type type, String propName) throws ClassNotFoundException {
if (Enum.class.isAssignableFrom((Class<?>) type)) {
return Enum.valueOf((Class<Enum>)type, configPropertiesCascadeBase.propertyValueString(propName));
} else {
switch (type.getTypeName()) {
case "java.lang.String": {
return configPropertiesCascadeBase.propertyValueString(propName);
}
return set;
}
case "java.util.Map" : {
Map<String, String> map = new HashMap();
for (String pairs : configPropertiesCascadeBase.propertyValueString(propName).split(",")) {
String [] keyValue = pairs.split("=");
map.put(keyValue[0].trim(),keyValue[1].trim());
case "int":
case "java.lang.Integer": {
return configPropertiesCascadeBase.propertyValueInt(propName);
}
return map;
}
case "java.time.Period" : {
return Period.parse(configPropertiesCascadeBase.propertyValueString(propName));
}
case "org.springframework.core.io.WritableResource":
case "org.springframework.core.io.Resource": {
return resourceLoader.getResource(configPropertiesCascadeBase.propertyValueString(propName));
case "long":
case "java.lang.Long": {
return Long.parseLong(configPropertiesCascadeBase.propertyValueString(propName));
}
case "double":
case "java.lang.Double": {
return Double.parseDouble(configPropertiesCascadeBase.propertyValueString(propName));
}
case "boolean":
case "java.lang.Boolean": {
return configPropertiesCascadeBase.propertyValueBoolean(propName);
}
case "java.util.List":
case "java.util.Collection": {
return Arrays.asList(configPropertiesCascadeBase.propertyValueString(propName).split(","));
}
case "java.util.Set": {
Set set = new HashSet();
for (String prop : configPropertiesCascadeBase.propertyValueString(propName).split(",")) {
set.add(prop);
}
return set;
}
case "java.util.Map": {
Map<String, String> map = new HashMap();
for (String pairs : configPropertiesCascadeBase.propertyValueString(propName).split(",")) {
String[] keyValue = pairs.split("=");
map.put(keyValue[0].trim(), keyValue[1].trim());
}
return map;
}
case "java.time.Period": {
return Period.parse(configPropertiesCascadeBase.propertyValueString(propName));
}
case "org.springframework.core.io.WritableResource":
case "org.springframework.core.io.Resource": {
return resourceLoader.getResource(configPropertiesCascadeBase.propertyValueString(propName));
}
default:
throw new IllegalStateException("Unexpected type: " + type.getTypeName());
}
default:
throw new IllegalStateException("Unexpected type: " + type.getTypeName());
}
}

1 change: 1 addition & 0 deletions src/test/docker/docker-compose.yml
@@ -86,6 +86,7 @@ services:
- ./grouper/config/grouper.properties:/opt/grouper/grouperWebapp/WEB-INF/classes/grouper.properties
- ./grouper/config/grouper-ui.properties:/opt/grouper/grouperWebapp/WEB-INF/classes/grouper-ui.properties
- ./shibboleth-idp/config/shib-idp/metadata/idp-metadata.xml:/opt/grouper/idp-metadata.xml
- ./grouper/cacerts:/usr/lib/jvm/java-17-amazon-corretto/lib/security/cacerts
environment:
GROUPER_DATABASE_URL: "jdbc:postgresql://database/grouper"
GROUPER_DATABASE_USERNAME: "grouper"
Binary file added src/test/docker/grouper/cacerts
Binary file not shown.
3 changes: 2 additions & 1 deletion src/test/docker/grouper/config/grouper-ui.properties
@@ -19,4 +19,5 @@ external.authentication.grouperContextUrl = https://grouper-ui.unicon.local/grou

# Note for CAS: you'll need to make sure that the CAS server SSL certificate is available in the trust store
#external.authentication.provider = cas
#external.authentication.cas.loginUrl = https://idp.unicon.local/idp/profile/cas/login
#external.authentication.cas.prefixUrl = https://idp.unicon.local/idp/profile/cas
#external.authentication.cas.protocol = CAS20
@@ -22,6 +22,7 @@
import org.osgi.framework.ServiceReference;
import org.pac4j.cas.client.CasClient;
import org.pac4j.cas.config.CasConfiguration;
import org.pac4j.cas.config.CasProtocol;
import org.pac4j.core.config.Config;
import org.pac4j.oidc.client.OidcClient;
import org.pac4j.oidc.config.OidcConfiguration;
@@ -332,4 +333,21 @@ public void testPac4jConfigMethodFind() throws IOException {

Assert.assertTrue(configuration.getIdentityProviderMetadataResource().isFile() && ((FileSystemResource)configuration.getIdentityProviderMetadataResource()).getPath().equals("/opt/grouper/idp-metadata.xml"));
}
@Test
public void testPac4jConfigEnum() throws IOException {
// external.authentication.saml.identityProviderMetadataPath = file:/opt/grouper/idp-metadata.xml
ConfigPropertiesCascadeBase grouperConfig = ConfigUtils.getConfigPropertiesCascadeBase("ui");

grouperConfig.propertiesOverrideMap().clear();
Map<String, String> overrides = grouperConfig.propertiesOverrideMap();
overrides.put("external.authentication.provider","cas");
overrides.put("external.authentication.cas.protocol", "CAS20");

Pac4jConfigFactory pac4jConfigFactory = new Pac4jConfigFactory();
Config config = pac4jConfigFactory.build();

CasConfiguration configuration = ((CasClient) config.getClients().getClients().get(0)).getConfiguration();

Assert.assertTrue(CasProtocol.CAS20.equals(configuration.getProtocol()));
}
}

0 comments on commit 767262d

Please sign in to comment.