Expand my Community achievements bar.

SOLVED

Saml configuration values in sightly for aem6.5

Avatar

Level 8

Hi ,

 

Wanted to know if there is any way or exact I could use to fetch the values that are stored in saml based on runmodes

 

I have under

/apps/project/configuration/config.local

com.adobe.granite.auth.saml.SamlAuthenticationHandler-applicationName 

from that i need to fetch logout url value .

The property is stored as logoutUrl

 

Now I need to get the value of this in the sightly  code i.e in *.html file

Which I could use for href value

 

Could anyone provide inputs as how this could be resolved

Thanks

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@srinivas_chann1 You might be able to read OOTB config using configurationAdmin but again that's not recommended. The better approach would be to create a custom osgi config and a service to read this custom config.

View solution in original post

7 Replies

Avatar

Employee Advisor

Hi @srinivas_chann1 ,

 

You can define a new attribute in config for instance : logoutUrl, and you can getLogouUrl in model using the config service. 

And in sightly you can use the model and get the url value in href using the model getter.

Thanks.

Avatar

Community Advisor

@srinivas_chann1 ,

 

You can implement sling model and reference OSGI configs as as service and call the sling mode l in sightly with use class and implement getters and setters for the config values to access in the sightly html.

 

Thanks

Hope this helps!!

Avatar

Employee Advisor

Hi @srinivas_chann1 ,

There are multiple ways to get this done:

1. You can create a service, read the values and return it to sling model and then get it into html. Reference URL: https://sourcedcode.com/blog/aem/aem-sling-model-injectors-annotations-reference-guide#OSGiService

2. You can directly read the values in JS and then pass it to html. Reference: https://gist.github.com/gabrielwalt/278f8cee870aac7ec619

 

Avatar

Community Advisor

Hi @srinivas_chann1 

 

Its not recommended to read OOTB config in another service. Here is an another community question which talks about this.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/correct-way-to-read-osgi-c...

 

Avatar

Level 8

Hi,

 

Thanks for the response.

As this OOTB config not sure how to read this values in slightly code.

com.adobe.granite.auth.saml.SamlAuthenticationHandler-applicationName 

 

For custom created config. I am already aware as 

 

@ObjectClassDefinition(name = "config", description = "configuration")
public @interface ConfigurationProperties {}

@Component(configurationPolicy = ConfigurationPolicy.REQUIRE, immediate = true,
service = Configuration.class)
@Designate(ocd = ConfigurationProperties.class)
public class Configuration {}

Avatar

Correct answer by
Community Advisor

@srinivas_chann1 You might be able to read OOTB config using configurationAdmin but again that's not recommended. The better approach would be to create a custom osgi config and a service to read this custom config.

Avatar

Community Advisor

You can try something like this

Configuration[] getConfigurations(String configId) throws IOException, InvalidSyntaxException {

return this.configurationAdmin.listConfigurations("(&(" + "oauth.config.id" + "="
+ configId + ")(" + "service.factoryPid" + "=" + "com.adobe.granite.auth.oauth.provider" + "))");
}

Change the oauth.config.id(property to match the specific configuration) and the oauth factory id with SAML configuration details

Configuration[] configurations = getConfigurations(configId);

if (configurations != null && configurations.length >= 1) {

String clientId=configurations[0].getProperties().get(Constants.OAUTH_CLIENT_ID).toString();

}

Regards

Albin I

www.albinsblog.com