How to read to the contents of "Authentication requirements" (Apache Sling Authentication Service) using code? | Community
Skip to main content
jayv25585659
Level 8
Oct 25, 2017 4:50 AM UTC
Solved

How to read to the contents of "Authentication requirements" (Apache Sling Authentication Service) using code?

I have this code that reads the contents of the module above

ConfigurationAdmin configAdmin = getSlingScriptHelper().getService( ConfigurationAdmin.class );

Configuration conf = configAdmin.getConfiguration("org.apache.sling.engine.impl.auth.SlingAuthenticatorß");

           

@SuppressWarnings("unchecked")

Dictionary<String, Object> props = conf.getProperties();

I put at breakpoint (eclipse user here if it matters) on line 5 to inspect the value of props and conf variables. I've drilled down on the folder-like structure but I cannot find what I'm looking for.

When I view the service via

http://localhost:4502/system/console/configMgr/org.apache.sling.engine.impl.auth.SlingAuthenticator

I can see several values for "Authentication Requirements" (screenshot below). Any ideas on how to do it? Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
edubey
edubeyAccepted solution
Level 10
Oct 25, 2017 8:48 AM UTC

Use below code

Configuration conf = configAdmin.getConfiguration("org.apache.sling.engine.impl.auth.SlingAuthenticator"); String[] props = (String[]) conf.getProperties().get("sling.auth.requirements");

for (String value : props) { logger.info("Value {}", value); }

Thanks

4 replies

joerghoh
Employee
Oct 26, 2017 5:12 AM UTC

What's your usecase which requires you to read these properties?

Jörg

Translate
jayv25585659
Level 8
Oct 25, 2017 10:49 PM UTC

how would you do it then?

Thanks!

Translate
joerghoh
Employee
Oct 25, 2017 4:58 PM UTC

While edubey​'s approach is definitly working, the OSGI configuration properties of a service/component should be considered implementation details. You should not do that, as any subsequent version of the Sling authentication might change the configuration without further notice.

Jörg

Translate
edubey
edubeyAccepted solution
Level 10
Oct 25, 2017 8:48 AM UTC

Use below code

Configuration conf = configAdmin.getConfiguration("org.apache.sling.engine.impl.auth.SlingAuthenticator"); String[] props = (String[]) conf.getProperties().get("sling.auth.requirements");

for (String value : props) { logger.info("Value {}", value); }

Thanks

Translate