Skip to content

Commit

Permalink
Improve authentication mgt
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Jan 18, 2025
1 parent 682372d commit 1c840ef
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static ApplicationAuthenticatorService getInstance() {
* This method is used to get the list of SYSTEM defined local authenticator configurations.
*
* @deprecated It is recommended to use {@link #getAllSystemDefinedLocalAuthenticators()},
* which returning the SYSTEM defined local application authenticator configurations.
* which returning both SYSTEM and USER defined local application authenticator configurations.
*/
@Deprecated
public List<LocalAuthenticatorConfig> getLocalAuthenticators() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public List<ApplicationAuthenticator> getAllAuthenticators() throws ApplicationA
return FrameworkServiceComponent.getAuthenticators();
}

public List<ApplicationAuthenticator> getAllSystemDefinedLocalAuthenticators() {
public List<ApplicationAuthenticator> getLocalAuthenticators() throws ApplicationAuthenticationException {

List<ApplicationAuthenticator> localAuthenticators = new ArrayList<ApplicationAuthenticator>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;
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.FederatedAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig;
import org.wso2.carbon.identity.base.IdentityRuntimeException;
import org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService;
import org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException;
import org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary;
Expand Down Expand Up @@ -320,9 +322,7 @@ protected void filterOptions(Map<String, Map<String, String>> authenticationOpti
removeOption = true;

if (FrameworkConstants.LOCAL_IDP_NAME.equals(idpName)) {
List<LocalAuthenticatorConfig> localAuthenticators = ApplicationAuthenticatorService
.getInstance().getAllSystemDefinedLocalAuthenticators();
for (LocalAuthenticatorConfig localAuthenticatorConfig : localAuthenticators) {
for (LocalAuthenticatorConfig localAuthenticatorConfig : getLocalAuthenticatorConfigsList()) {
if (FrameworkUtils.isAuthenticatorNameInAuthConfigEnabled()) {
if (authenticatorConfig.getName().equals(localAuthenticatorConfig.getName()) &&
authenticators.contains(localAuthenticatorConfig.getName())) {
Expand Down Expand Up @@ -416,6 +416,17 @@ protected void filterOptions(Map<String, Map<String, String>> authenticationOpti
}
}

private List<LocalAuthenticatorConfig> getLocalAuthenticatorConfigsList() {

String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try {
return ApplicationAuthenticatorService.getInstance().getAllLocalAuthenticators(tenantDomain);
} catch (AuthenticatorMgtException e) {
throw new IdentityRuntimeException(String.format("Error while retrieving all local authenticator" +
" configurations for tenant: %s", tenantDomain), e);
}
}

/**
* Add authenticator params in the message context.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;
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.FederatedAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig;
import org.wso2.carbon.identity.base.IdentityRuntimeException;
import org.wso2.carbon.identity.central.log.mgt.utils.LogConstants;
import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils;
import org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService;
Expand Down Expand Up @@ -475,9 +477,7 @@ protected void filterOptions(Map<String, Map<String, String>> authenticationOpti
removeOption = true;

if (FrameworkConstants.LOCAL_IDP_NAME.equals(idpName)) {
List<LocalAuthenticatorConfig> localAuthenticators = ApplicationAuthenticatorService
.getInstance().getAllSystemDefinedLocalAuthenticators();
for (LocalAuthenticatorConfig localAuthenticatorConfig : localAuthenticators) {
for (LocalAuthenticatorConfig localAuthenticatorConfig : getLocalAuthenticatorConfigsList()) {
if (FrameworkUtils.isAuthenticatorNameInAuthConfigEnabled()) {
if (authenticatorConfig.getName().equals(localAuthenticatorConfig.getName()) &&
authenticators.contains(localAuthenticatorConfig.getName())) {
Expand Down Expand Up @@ -571,6 +571,17 @@ protected void filterOptions(Map<String, Map<String, String>> authenticationOpti
}
}

private List<LocalAuthenticatorConfig> getLocalAuthenticatorConfigsList() {

String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try {
return ApplicationAuthenticatorService.getInstance().getAllLocalAuthenticators(tenantDomain);
} catch (AuthenticatorMgtException e) {
throw new IdentityRuntimeException(String.format("Error while retrieving all local authenticator" +
" configurations for tenant: %s", tenantDomain), e);
}
}

/**
* Add authenticator params in the message context.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;
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.FederatedAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig;
import org.wso2.carbon.identity.base.IdentityRuntimeException;
import org.wso2.carbon.identity.central.log.mgt.utils.LogConstants;
import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils;
import org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService;
Expand Down Expand Up @@ -498,9 +500,7 @@ protected void filterOptions(Map<String, Map<String, String>> authenticationOpti
removeOption = true;

if (FrameworkConstants.LOCAL_IDP_NAME.equals(idpName)) {
List<LocalAuthenticatorConfig> localAuthenticators = ApplicationAuthenticatorService
.getInstance().getAllSystemDefinedLocalAuthenticators();
for (LocalAuthenticatorConfig localAuthenticatorConfig : localAuthenticators) {
for (LocalAuthenticatorConfig localAuthenticatorConfig : getLocalAuthenticatorConfigsList()) {
if (FrameworkUtils.isAuthenticatorNameInAuthConfigEnabled()) {
if (authenticatorConfig.getName().equals(localAuthenticatorConfig.getName()) &&
authenticators.contains(localAuthenticatorConfig.getName())) {
Expand Down Expand Up @@ -594,6 +594,17 @@ protected void filterOptions(Map<String, Map<String, String>> authenticationOpti
}
}

private List<LocalAuthenticatorConfig> getLocalAuthenticatorConfigsList() {

String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try {
return ApplicationAuthenticatorService.getInstance().getAllLocalAuthenticators(tenantDomain);
} catch (AuthenticatorMgtException e) {
throw new IdentityRuntimeException(String.format("Error while retrieving all local authenticator" +
" configurations for tenant: %s", tenantDomain), e);
}
}

/**
* Add authenticator params in the message context.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ public void testGetAllAuthenticators() throws Exception {
}

@Test
public void testGetLocalAuthenticators() {
public void testGetLocalAuthenticators() throws Exception {

List<ApplicationAuthenticator> localAuthenticators =
applicationAuthenticationService.getAllSystemDefinedLocalAuthenticators();
List<ApplicationAuthenticator> localAuthenticators = applicationAuthenticationService.getLocalAuthenticators();
assertEquals(localAuthenticators.size(), 1);
assertEquals(localAuthenticators.get(0).getName(), LOCAL_AUTHENTICATOR_NAME);
}
Expand Down

0 comments on commit 1c840ef

Please sign in to comment.