Skip to content

Commit

Permalink
Add trusted tags to yaml loader options
Browse files Browse the repository at this point in the history
  • Loading branch information
ImalshaG committed Sep 18, 2023
1 parent 957129d commit 44a2aa0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.error.YAMLException;
import org.yaml.snakeyaml.inspector.TagInspector;
import org.yaml.snakeyaml.inspector.TrustedPrefixesTagInspector;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -686,7 +688,16 @@ private ServiceProvider parseServiceProviderFromYaml(SpFileContent spFileContent
throws IdentityApplicationManagementException {

try {
Yaml yaml = new Yaml(new Constructor(ServiceProvider.class, new LoaderOptions()));
// Add trusted tags included in the SP YAML file.
List<String> trustedTagList = new ArrayList<>();
trustedTagList.add(ServiceProvider.class.getName());
trustedTagList.add(OAuthAppDO.class.getName());
trustedTagList.add(SAMLSSOServiceProviderDTO.class.getName());

LoaderOptions loaderOptions = new LoaderOptions();
TagInspector tagInspector = new TrustedPrefixesTagInspector(trustedTagList);
loaderOptions.setTagInspector(tagInspector);
Yaml yaml = new Yaml(new Constructor(ServiceProvider.class, loaderOptions));
return yaml.loadAs(spFileContent.getContent(), ServiceProvider.class);
} catch (YAMLException e) {
throw new IdentityApplicationManagementException(String.format("Error in reading YAML Service Provider " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.error.YAMLException;
import org.yaml.snakeyaml.inspector.TagInspector;
import org.yaml.snakeyaml.inspector.TrustedPrefixesTagInspector;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -1155,7 +1157,16 @@ private ClaimDialectConfiguration parseClaimDialectFromJson(FileContent fileCont
private ClaimDialectConfiguration parseClaimDialectFromYaml(FileContent fileContent) throws ClaimMetadataException {

try {
Yaml yaml = new Yaml(new Constructor(ClaimDialectConfiguration.class, new LoaderOptions()));
// Add trusted tags included in the Claims YAML files.
List<String> trustedTagList = new ArrayList<>();
trustedTagList.add(ClaimDialectConfiguration.class.getName());
trustedTagList.add(ExternalClaimResDTO.class.getName());
trustedTagList.add(LocalClaimResDTO.class.getName());

LoaderOptions loaderOptions = new LoaderOptions();
TagInspector tagInspector = new TrustedPrefixesTagInspector(trustedTagList);
loaderOptions.setTagInspector(tagInspector);
Yaml yaml = new Yaml(new Constructor(ClaimDialectConfiguration.class, loaderOptions));
return yaml.loadAs(fileContent.getContent(), ClaimDialectConfiguration.class);
} catch (YAMLException e) {
throw new ClaimMetadataException(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.error.YAMLException;
import org.yaml.snakeyaml.inspector.TagInspector;
import org.yaml.snakeyaml.inspector.TrustedPrefixesTagInspector;
import org.yaml.snakeyaml.representer.Representer;

import java.io.IOException;
Expand Down Expand Up @@ -3696,7 +3698,14 @@ private IdentityProvider parseIdpFromYaml(FileContent fileContent)
throws IdentityProviderManagementClientException {

try {
Yaml yaml = new Yaml(new Constructor(IdentityProvider.class, new LoaderOptions()));
// Add trusted tags included in the IDP YAML files.
List<String> trustedTagList = new ArrayList<>();
trustedTagList.add(IdentityProvider.class.getName());

LoaderOptions loaderOptions = new LoaderOptions();
TagInspector tagInspector = new TrustedPrefixesTagInspector(trustedTagList);
loaderOptions.setTagInspector(tagInspector);
Yaml yaml = new Yaml(new Constructor(IdentityProvider.class, loaderOptions));
return yaml.loadAs(fileContent.getContent(), IdentityProvider.class);
} catch (YAMLException e) {
throw new IdentityProviderManagementClientException(String.format("Error in reading YAML file " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.error.YAMLException;
import org.yaml.snakeyaml.inspector.TagInspector;
import org.yaml.snakeyaml.inspector.TrustedPrefixesTagInspector;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -1661,7 +1663,14 @@ private UserStoreConfigurations parseUserStoreFromXml(FileContent fileContent) t
private UserStoreConfigurations parseUserStoreFromYaml(FileContent fileContent) throws UserStoreException {

try {
Yaml yaml = new Yaml(new Constructor(UserStoreConfigurations.class, new LoaderOptions()));
// Add trusted tags included in the Userstore YAML files.
List<String> trustedTagList = new ArrayList<>();
trustedTagList.add(UserStoreConfigurations.class.getName());

LoaderOptions loaderOptions = new LoaderOptions();
TagInspector tagInspector = new TrustedPrefixesTagInspector(trustedTagList);
loaderOptions.setTagInspector(tagInspector);
Yaml yaml = new Yaml(new Constructor(UserStoreConfigurations.class, loaderOptions));
return yaml.loadAs(fileContent.getContent(), UserStoreConfigurations.class);
} catch (YAMLException e) {
throw new UserStoreException(String.format("Error in reading YAML file " +
Expand Down

0 comments on commit 44a2aa0

Please sign in to comment.