Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snakeyaml constructors #480

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.carbon.identity.api.server.application.management.v1.core;

import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.representer.Representer;

Expand All @@ -33,6 +34,10 @@ public class CustomRepresenter extends Representer {
private static final String[] PROPERTIES_TO_REMOVE = {"inboundConfiguration", "applicationID", "owner",
"tenantDomain", "id", "idpProperties", "resourceId", "spProperties", "applicationResourceId"};

public CustomRepresenter(DumperOptions options) {
super(options);
}

@Override
protected Set<Property> getProperties(Class<?> type) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
import org.wso2.carbon.identity.template.mgt.model.Template;
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
import org.wso2.carbon.user.core.service.RealmService;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
Expand Down Expand Up @@ -551,8 +553,8 @@ public void beforeMarshal(Object source) {

private String parseYamlFromServiceProvider(ServiceProvider serviceProvider) {

Constructor constructor = new Constructor();
CustomRepresenter representer = new CustomRepresenter();
Constructor constructor = new Constructor(new LoaderOptions());
CustomRepresenter representer = new CustomRepresenter(new DumperOptions());

for (Class<?> protocol : INBOUND_CONFIG_PROTOCOLS) {
TypeDescription description = new TypeDescription(InboundConfigurationProtocol.class);
Expand Down Expand Up @@ -684,7 +686,7 @@ private ServiceProvider parseServiceProviderFromYaml(SpFileContent spFileContent
throws IdentityApplicationManagementException {

try {
Yaml yaml = new Yaml(new Constructor(ServiceProvider.class));
Yaml yaml = new Yaml(new Constructor(ServiceProvider.class, new 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 @@ -58,6 +58,7 @@
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.UserStoreManager;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.error.YAMLException;
Expand Down Expand Up @@ -1154,7 +1155,7 @@ private ClaimDialectConfiguration parseClaimDialectFromJson(FileContent fileCont
private ClaimDialectConfiguration parseClaimDialectFromYaml(FileContent fileContent) throws ClaimMetadataException {

try {
Yaml yaml = new Yaml(new Constructor(ClaimDialectConfiguration.class));
Yaml yaml = new Yaml(new Constructor(ClaimDialectConfiguration.class, new 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 @@ -112,6 +112,8 @@
import org.wso2.carbon.idp.mgt.model.ConnectedAppsResult;
import org.wso2.carbon.idp.mgt.model.IdpSearchResult;
import org.wso2.carbon.user.core.UserCoreConstants;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
Expand Down Expand Up @@ -3620,7 +3622,7 @@ private FileContent parseIdpToYaml(IdentityProvider identityProvider)
StringBuilder fileNameSB = new StringBuilder(identityProvider.getIdentityProviderName());
fileNameSB.append(YAML_FILE_EXTENSION);

Representer representer = new Representer();
Representer representer = new Representer(new DumperOptions());
TypeDescription typeDescription = new TypeDescription(IdentityProvider.class);
typeDescription.setExcludes("id", "resourceId");
representer.addTypeDescription(typeDescription);
Expand Down Expand Up @@ -3694,7 +3696,7 @@ private IdentityProvider parseIdpFromYaml(FileContent fileContent)
throws IdentityProviderManagementClientException {

try {
Yaml yaml = new Yaml(new Constructor(IdentityProvider.class));
Yaml yaml = new Yaml(new Constructor(IdentityProvider.class, new 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 @@ -76,6 +76,7 @@
import org.wso2.carbon.user.core.UserStoreManager;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.tracker.UserStoreManagerRegistry;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.error.YAMLException;
Expand Down Expand Up @@ -1660,7 +1661,7 @@ private UserStoreConfigurations parseUserStoreFromXml(FileContent fileContent) t
private UserStoreConfigurations parseUserStoreFromYaml(FileContent fileContent) throws UserStoreException {

try {
Yaml yaml = new Yaml(new Constructor(UserStoreConfigurations.class));
Yaml yaml = new Yaml(new Constructor(UserStoreConfigurations.class, new LoaderOptions()));
return yaml.loadAs(fileContent.getContent(), UserStoreConfigurations.class);
} catch (YAMLException e) {
throw new UserStoreException(String.format("Error in reading YAML file " +
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@
<maven.buildnumber.plugin.version>1.4</maven.buildnumber.plugin.version>
<org.apache.felix.annotations.version>1.2.4</org.apache.felix.annotations.version>
<identity.governance.version>1.8.57</identity.governance.version>
<carbon.identity.framework.version>5.25.198</carbon.identity.framework.version>
<carbon.identity.framework.version>5.25.302</carbon.identity.framework.version>
<maven.findbugsplugin.version>3.0.5</maven.findbugsplugin.version>
<identity.workflow.impl.bps.version>5.2.0</identity.workflow.impl.bps.version>
<maven.checkstyleplugin.excludes>**/gen/**/*</maven.checkstyleplugin.excludes>
Expand Down
Loading