Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix sample code issue

...

  • Create a custom Java component and add the below dependencies to that project.
    1. com.wso2.finance.open.banking.sca.keymanager 

      Info

      com.wso2.finance.open.banking.sca.keymanager-2.0.0.jar is available in <WSO2_OB_APIM_HOME>/repository/components/dropins/com.wso2.finance.open.banking.sca.keymanager-2.0.0.jar

    2. org.wso2.carbon.apimgt.impl

      Info

      org.wso2.carbon.apimgt.impl_6.6.163.jar is available in <WSO2_OB_APIM_HOME>/repository/components/plugins/org.wso2.carbon.apimgt.impl_6.6.163.jar

  • Add a Java class to your custom module extending the SCABasedKeyManagerClient class. Override the setAuthenticators method to define the required authenticators. The sample SampleKeyManagerClient module sets two authentication steps(local authentication and federated authentication steps respectively) using this extension as follows:

    Code Block
    languagejava
    /**
     * Sample class to set authenticators in KeyManagerClient
     **/
    public class SampleKeyManagerClient extends SCABasedKeyManagerClient {
    
        private static final String BASIC_AUTHENTICATOR_NAME = "FOOBasicCustomAuth";
        private static final String BASIC_AUTHENTICATOR_DISPLAY_NAME = "FOO Authenticator";
        private static final String FEDERATED_AUTHENTICATOR_NAME = "BARFedCustomAuth";
    
        @Override
        public void setAuthenticators(LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig,
                                      OAuthApplicationInfo oAuthApplicationInfo)
                throws RemoteException, IdentityApplicationManagementServiceIdentityApplicationManagementException,
                APIManagementException {
            AuthenticationStep[] authenticationSteps = new AuthenticationStep[2];
    
            //Step 1 - Basic authentication
            LocalAuthenticatorConfig localAuthenticatorConfig = new LocalAuthenticatorConfig();
            LocalAuthenticatorConfig[] localAuthenticatorConfigs = new LocalAuthenticatorConfig[1];
            AuthenticationStep basicAuthenticationStep = new AuthenticationStep();
    
            localAuthenticatorConfig.setName(BASIC_AUTHENTICATOR_NAME);
            localAuthenticatorConfig.setDisplayName(BASIC_AUTHENTICATOR_DISPLAY_NAME);
            localAuthenticatorConfig.setEnabled(true);
            localAuthenticatorConfigs[0] = localAuthenticatorConfig;
    
            basicAuthenticationStep.setStepOrder(1);
            basicAuthenticationStep.setLocalAuthenticatorConfigs(localAuthenticatorConfigs);
            basicAuthenticationStep.setAttributeStep(true);
            basicAuthenticationStep.setSubjectStep(true);
            //set step 1
            authenticationSteps[0] = basicAuthenticationStep;
    
            //Step 2 - Federated authentication
            IdentityProvider identityProvider = null;
      
            AdminServiceHolder adminServiceHolder = AdminServiceHolder.getInstance();
            IdentityApplicationManagementServiceStub stub = super.getIdentityApplicationManagementServiceStub();
    
            if (stub != null) {
                IdentityProvider[] federatedIdPs = stub.getAllIdentityProviders();
                if (federatedIdPs != null && federatedIdPs.length > 0) {
                    for (IdentityProvider registeredIdentityProvider : federatedIdPs) {
                        if (registeredIdentityProvider.getIdentityProviderName().equals(FEDERATED_AUTHENTICATOR_NAME)) {
                            identityProvider = registeredIdentityProvider;
                            break;
                        }
                    }
                }
            } else {
                throw new APIManagementException("Retrieving IdentityApplicationManagementServiceStub failed.");
            }
    
            IdentityProvider[] identityProviders = new IdentityProvider[1];
            identityProviders[0] = identityProvider;
    
            AuthenticationStep authenticationStep = new AuthenticationStep();
            authenticationStep.setStepOrder(2);
            authenticationStep.setFederatedIdentityProviders(identityProviders);
    
            //set step 2
            authenticationSteps[1] = authenticationStep;
    
            //set authentication steps
            localAndOutboundAuthenticationConfig.setAuthenticationSteps(authenticationSteps);
        }
    }
    
    
    

...