Java: Sample Okta application is using Spring+Autowired to initialize variable - How to use/initialize Sling/Osgi instead?

This is the class I’m trying to use => okta-idx-java/api/src/main/java/com/okta/idx/sdk/api/client/ at master · okta/okta-idx-java · GitHub

This is how I’ve imported the SDK into my maven project


This is the sample Sprint application => okta-idx-java/samples/embedded-auth-with-sdk/src/main/java/com/okta/spring/example/controllers/ at master · okta/okta-idx-java · GitHub

private IDXAuthenticationWrapper idxAuthenticationWrapper;

I’m trying to do the same but on my Sling+OSGI application. I’ve tried

import com.okta.idx.sdk.api.client.IDXAuthenticationWrapper;
import javax.inject.Inject;
import org.osgi.service.component.annotations.Reference;

public class MyClass
    private IDXAuthenticationWrapper idxAuthenticationWrapper1;
    private IDXAuthenticationWrapper idxAuthenticationWrapper2;
    public main() {
        IDXAuthenticationWrapper idxAuthenticationWrapper3 =
            new IDXAuthenticationWrapper();

and all 3 variables return null.

Any ideas on how to get it work? thanks

Hi NTrOcasTItIsitH,

Your question is a bit off the scope of using Okta as an identity provider. But…

What you are talking about is dependency injection. It sounds like you may be unfamiliar with that, I apologize if I am wrong. It isn’t the Okta application that’s doing it, it’s all a Spring thing. The idea is to divorce classes from their dependencies, in other words don’t build a Java class with a hardwired source for the data, like initializing a string or even using the Java library to load a string from a properties file. The Spring framework stuffs the dependency value into the class when the class is instantiated because Spring handles instantiating all the class instances. So, you can configure the Spring source of the dependency (a file or a class) and swap it out for different environments. Like, what is the URL for your Okta organization in development, integration testing, and production :slight_smile:

Your starting point for how to configure that for Apache Sling is here: Apache Sling :: Sling Models.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.