wso2 / charon

121 stars 164 forks source link

Enable loading the UserSchemaExtension from a classpath resource #378

Open klaasdellschaft opened 2 years ago

klaasdellschaft commented 2 years ago

Purpose

When using Charon in the context of a Spring Boot application, typically all resources needed by the application are packaged into the jar file together with all of the application's classes. In this case, it is not directly possible to read that classpath resource via a FileInputStream. In order to still be able to load a UserSchemaExtension, currently a workaround would need to applied in the application, i.e. the classpath resource would need to be copied to a temporary file, and then the temporary file would need to be deleted after being loaded by SCIMUserSchemaExtensionBuilder.

Goals

In order to avoid this workaround, I added a further method to SCIMUserSchemaExtensionBuilder which it loads the schema from any InputStream. When using this newly introduced method, the application is responsible for opening and closing that stream (and handling the exceptions that may appear during opening and closing).

The solution 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.