Skip to content

Commit

Permalink
Enable loading the UserSchemaExtension from a classpath resource, e.g…
Browse files Browse the repository at this point in the history
…. a file packaged into the application's jar file

The change is fully backwards compatible, i.e. the previous method signature `buildUserSchemaExtension(String configFilePath)` is still available, and it behaves the same as before. Only a new method `buildUserSchemaExtension(InputStream inputStream)` has been made available.
  • Loading branch information
klaasdellschaft committed Jan 11, 2023
1 parent b0a70fd commit 11de282
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,30 @@ public AttributeSchema getExtensionSchema() {
return extensionSchema;
}

public void buildUserSchemaExtension(String configFilePath) throws CharonException, InternalErrorException {

File provisioningConfig = new File(configFilePath);

try (InputStream inputStream = new FileInputStream(provisioningConfig)) {

buildUserSchemaExtension(inputStream);

} catch (FileNotFoundException e) {
throw new CharonException(SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file not found!",
e);
} catch (IOException e) {
throw new CharonException("Error while closing " +
SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file!", e);
}
}

/*
* Logic goes here
* @throws CharonException
*/
public void buildUserSchemaExtension(String configFilePath) throws CharonException, InternalErrorException {
public void buildUserSchemaExtension(InputStream inputStream) throws CharonException, InternalErrorException {

readConfiguration(configFilePath);
readConfiguration(inputStream);

for (Map.Entry<String, ExtensionAttributeSchemaConfig> attributeSchemaConfig : extensionConfig.entrySet()) {
// if there are no children its a simple attribute, build it
Expand All @@ -88,11 +105,9 @@ public void buildUserSchemaExtension(String configFilePath) throws CharonExcepti
* @param configFilePath
* @throws CharonException
*/
private void readConfiguration(String configFilePath) throws CharonException {
private void readConfiguration(InputStream inputStream) throws CharonException {

File provisioningConfig = new File(configFilePath);
try (InputStream inputStream = new FileInputStream(provisioningConfig)) {
//Scanner scanner = new Scanner(new FileInputStream(provisioningConfig));
try {
Scanner scanner = new Scanner(inputStream, "utf-8").useDelimiter("\\A");
String jsonString = scanner.hasNext() ? scanner.next() : "";

Expand All @@ -112,15 +127,9 @@ private void readConfiguration(String configFilePath) throws CharonException {
extensionRootAttributeName = schemaAttributeConfig.getName();
}
}
} catch (FileNotFoundException e) {
throw new CharonException(SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file not found!",
e);
} catch (JSONException e) {
throw new CharonException("Error while parsing " +
SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file!", e);
} catch (IOException e) {
throw new CharonException("Error while closing " +
SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file!", e);
}
}

Expand Down

0 comments on commit 11de282

Please sign in to comment.