Skip to content

Commit

Permalink
Add new method to get federated authenticator by name.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Jan 25, 2025
1 parent 5ed2769 commit 9b739c1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.wso2.carbon.identity.application.authentication.framework.exception.session.storage.SessionDataStorageOptimizationServerException;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder;
import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService;
import org.wso2.carbon.identity.application.common.exception.AuthenticatorMgtException;
import org.wso2.carbon.identity.application.common.model.AuthenticationStep;
import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.IdentityProvider;
Expand Down Expand Up @@ -295,7 +296,7 @@ public AuthenticationStep[] getAuthenticationSteps(String tenantDomain) throws F
AuthenticationStep authenticationStep = new AuthenticationStep();
authenticationStep.setStepOrder(authStep.getStepOrder());
authenticationStep.setLocalAuthenticatorConfigs(
getLocalAuthenticatorConfigs(authStep.getLocalAuthenticatorConfigNames()));
getLocalAuthenticatorConfigs(authStep.getLocalAuthenticatorConfigNames(), tenantDomain));
if (authStep.federatedIdPResourceIds == null || authStep.federatedIdPResourceIds.isEmpty()) {
// For new caches federatedIdPResourceIds will be null. But will have optimized federated IdPs.
authenticationStep.setFederatedIdentityProviders(getIdPsFromOptimizedFederatedIdPs(
Expand All @@ -315,15 +316,21 @@ public AuthenticationStep[] getAuthenticationSteps(String tenantDomain) throws F
return authenticationSteps;
}

private LocalAuthenticatorConfig[] getLocalAuthenticatorConfigs(List<String> localAuthConfigNames) {
private LocalAuthenticatorConfig[] getLocalAuthenticatorConfigs(List<String> localAuthConfigNames,
String tenantDomain) throws FrameworkException {

LocalAuthenticatorConfig[] localAuthenticatorConfigs = new
LocalAuthenticatorConfig[localAuthConfigNames.size()];
for (int i = 0; i < localAuthConfigNames.size(); i++) {
localAuthenticatorConfigs[i] = ApplicationAuthenticatorService.getInstance().
getLocalAuthenticatorByName(localAuthConfigNames.get(i));
try {
LocalAuthenticatorConfig[] localAuthenticatorConfigs = new
LocalAuthenticatorConfig[localAuthConfigNames.size()];
for (int i = 0; i < localAuthConfigNames.size(); i++) {
localAuthenticatorConfigs[i] = ApplicationAuthenticatorService.getInstance()
.getLocalAuthenticatorByName(localAuthConfigNames.get(i), tenantDomain);
}
return localAuthenticatorConfigs;
} catch (AuthenticatorMgtException e) {
throw new SessionDataStorageOptimizationException(String.format("Error while getting local authenticator " +
"configs by name for tenant domain: %s", tenantDomain), e);
}
return localAuthenticatorConfigs;
}

private IdentityProvider[] getFederatedIdPs(List<String> federatedIdPResourceIds, String tenantDomain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ public List<ApplicationAuthenticator> getSystemDefinedAuthenticators() {
return systemDefinedAuthenticators;
}

/**
* Get the ApplicationAuthenticator for the given system defined authenticator configuration name.
*
* @param authenticatorName Authenticator name.
* @return ApplicationAuthenticator instance.
*/
public ApplicationAuthenticator getSystemDefinedAuthenticatorByName(String authenticatorName) {

for (ApplicationAuthenticator authenticator : systemDefinedAuthenticators) {
if (authenticator.getName().equals(authenticatorName)) {
return authenticator;
}
}
return null;
}

/**
* Get the ApplicationAuthenticator for the given user defined federated authenticator config.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException;
import org.wso2.carbon.identity.application.authentication.framework.exception.LogoutFailedException;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder;
import org.wso2.carbon.identity.application.authentication.framework.internal.core.ApplicationAuthenticatorManager;
import org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder;
Expand Down Expand Up @@ -88,7 +89,7 @@ public void testExceptionRetry() throws Exception {
LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl();
CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl);

FrameworkServiceDataHolder.getInstance().getAuthenticators().add(
ApplicationAuthenticatorManager.getInstance().addSystemDefinedAuthenticator(
new FailingMockAuthenticator("FailingMockAuthenticator"));

FrameworkServiceDataHolder.getInstance().setLongWaitStatusStoreService(new LongWaitStatusStoreService
Expand Down

0 comments on commit 9b739c1

Please sign in to comment.