Skip to content

Commit

Permalink
Improve authenticator mgt.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Jan 16, 2025
1 parent 6640eab commit 62bf5b7
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,41 @@ public static ApplicationAuthenticatorService getInstance() {
return instance;
}

/**
* 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.
*/
@Deprecated
public List<LocalAuthenticatorConfig> getLocalAuthenticators() {
return this.localAuthenticators;
}

/**
* This returns list of all SYSTEM defined local authenticator configurations.
*
* @return Retrieved LocalAuthenticatorConfig.
*/
public List<LocalAuthenticatorConfig> getAllSystemDefinedLocalAuthenticators() {

return this.localAuthenticators;
}

/**
* This returns list of all SYSTEM and USER defined local authenticator configurations.
*
* @param tenantDomain Tenant domain.
* @return Retrieved LocalAuthenticatorConfig.
*/
public List<LocalAuthenticatorConfig> getAllLocalAuthenticators(String tenantDomain)
throws AuthenticatorMgtException {

List<LocalAuthenticatorConfig> configList = new ArrayList<>(getAllUserDefinedLocalAuthenticators(tenantDomain));
configList.addAll(localAuthenticators);
return configList;
}

/**
* This returns user defined local authenticators.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException;
import org.wso2.carbon.identity.application.common.IdentityApplicationRegistrationFailureException;
import org.wso2.carbon.identity.application.common.exception.AuthenticatorMgtException;
import org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo;
import org.wso2.carbon.identity.application.common.model.AssociatedRolesConfig;
import org.wso2.carbon.identity.application.common.model.AuthenticationStep;
Expand Down Expand Up @@ -997,8 +999,8 @@ public LocalAuthenticatorConfig[] getAllLocalAuthenticators(String tenantDomain)

try {
startTenantFlow(tenantDomain);
IdentityProviderDAO idpdao = ApplicationMgtSystemConfig.getInstance().getIdentityProviderDAO();
List<LocalAuthenticatorConfig> localAuthenticators = idpdao.getAllLocalAuthenticators();
List<LocalAuthenticatorConfig> localAuthenticators = ApplicationAuthenticatorService.getInstance()
.getAllLocalAuthenticators(tenantDomain);
if (localAuthenticators != null) {
return localAuthenticators.toArray(new LocalAuthenticatorConfig[localAuthenticators.size()]);
}
Expand Down Expand Up @@ -1506,15 +1508,15 @@ private void validateResourceId(String resourceId, String tenantDomain)
int filteredCount = 0;
try {
startTenantFlow(tenantDomain);
IdentityProviderDAO idpdao = ApplicationMgtSystemConfig.getInstance().getIdentityProviderDAO();
List<LocalAuthenticatorConfig> localAuthenticators = idpdao.getAllLocalAuthenticators();
List<LocalAuthenticatorConfig> localAuthenticators = ApplicationAuthenticatorService.getInstance()
.getAllLocalAuthenticators(tenantDomain);
if (localAuthenticators != null) {
filteredCount = (int) localAuthenticators.stream()
.filter(authenticatorConfig ->
authenticatorConfig.getName()
.equals(authenticatorName)).count();
}
} catch (IdentityApplicationManagementException e) {
} catch (IdentityApplicationManagementException | AuthenticatorMgtException e) {
throw new IdentityApplicationManagementException(
String.format(IdPManagementConstants.ErrorMessage
.ERROR_CODE_GET_CONNECTED_APPS_REQUEST_INVALID.getMessage(), resourceId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public interface IdentityProviderDAO {
* Returns all the local authenticators available on the system.
* @return
* @throws IdentityApplicationManagementException
* @deprecated use {@link ApplicationAuthenticatorService#getInstance().getAllLocalAuthenticators(String)} instead.
*/
@Deprecated
List<LocalAuthenticatorConfig> getAllLocalAuthenticators() throws IdentityApplicationManagementException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ public List<IdentityProvider> getAllIdentityProviders()
return federatedIdentityProviders;
}

@Override
/**
*
* @deprecated use {@link ApplicationAuthenticatorService#getInstance().getAllLocalAuthenticators(String)} instead.
*/
@Override
@Deprecated
public List<LocalAuthenticatorConfig> getAllLocalAuthenticators()
throws IdentityApplicationManagementException {

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> getLocalAuthenticators() throws ApplicationAuthenticationException {
public List<ApplicationAuthenticator> getAllSystemDefinedLocalAuthenticators() {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ protected void filterOptions(Map<String, Map<String, String>> authenticationOpti

if (FrameworkConstants.LOCAL_IDP_NAME.equals(idpName)) {
List<LocalAuthenticatorConfig> localAuthenticators = ApplicationAuthenticatorService
.getInstance().getLocalAuthenticators();
.getInstance().getAllSystemDefinedLocalAuthenticators();
for (LocalAuthenticatorConfig localAuthenticatorConfig : localAuthenticators) {
if (FrameworkUtils.isAuthenticatorNameInAuthConfigEnabled()) {
if (authenticatorConfig.getName().equals(localAuthenticatorConfig.getName()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ protected void filterOptions(Map<String, Map<String, String>> authenticationOpti

if (FrameworkConstants.LOCAL_IDP_NAME.equals(idpName)) {
List<LocalAuthenticatorConfig> localAuthenticators = ApplicationAuthenticatorService
.getInstance().getLocalAuthenticators();
.getInstance().getAllSystemDefinedLocalAuthenticators();
for (LocalAuthenticatorConfig localAuthenticatorConfig : localAuthenticators) {
if (FrameworkUtils.isAuthenticatorNameInAuthConfigEnabled()) {
if (authenticatorConfig.getName().equals(localAuthenticatorConfig.getName()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ protected void filterOptions(Map<String, Map<String, String>> authenticationOpti

if (FrameworkConstants.LOCAL_IDP_NAME.equals(idpName)) {
List<LocalAuthenticatorConfig> localAuthenticators = ApplicationAuthenticatorService
.getInstance().getLocalAuthenticators();
.getInstance().getAllSystemDefinedLocalAuthenticators();
for (LocalAuthenticatorConfig localAuthenticatorConfig : localAuthenticators) {
if (FrameworkUtils.isAuthenticatorNameInAuthConfigEnabled()) {
if (authenticatorConfig.getName().equals(localAuthenticatorConfig.getName()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ public void testFilterOptions(Map<String, Map<String, String>> options, StepConf
@DataProvider
public Object[][] filterOptionsDataProvider() {

ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().clear();
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().clear();
LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig();
basic.setName("BasicAuthenticator");
basic.setDisplayName("basic");
LocalAuthenticatorConfig totp = new LocalAuthenticatorConfig();
totp.setName("TOTPAuthenticator");
totp.setDisplayName("totp");
ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().add(basic);
ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().add(totp);
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(basic);
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(totp);

IdentityProvider localIdp = new IdentityProvider();
localIdp.setId("LOCAL");
Expand Down Expand Up @@ -290,7 +290,7 @@ public void testParamsOptions(Map<String, Object> options, StepConfig stepConfig
@DataProvider
public Object[][] filterParamsDataProvider() {

ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().clear();
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().clear();
LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig();
basic.setName("BasicAuthenticator");
basic.setDisplayName("basic");
Expand All @@ -299,8 +299,8 @@ public Object[][] filterParamsDataProvider() {
totp.setName("TOTPAuthenticator");
totp.setDisplayName("totp");

ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().add(basic);
ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().add(totp);
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(basic);
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(totp);

FederatedAuthenticatorConfig twitterFederated = new FederatedAuthenticatorConfig();
twitterFederated.setDisplayName("twitter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ public void testFilterOptions(Map<String, Map<String, String>> options, StepConf
@DataProvider
public Object[][] filterOptionsDataProvider() {

ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().clear();
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().clear();
LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig();
basic.setName("BasicAuthenticator");
basic.setDisplayName("basic");
LocalAuthenticatorConfig totp = new LocalAuthenticatorConfig();
totp.setName("TOTPAuthenticator");
totp.setDisplayName("totp");
ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().add(basic);
ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().add(totp);
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(basic);
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(totp);

IdentityProvider localIdp = new IdentityProvider();
localIdp.setId("LOCAL");
Expand Down Expand Up @@ -296,7 +296,7 @@ public void testParamsOptions(Map<String, Object> options, StepConfig stepConfig
@DataProvider
public Object[][] filterParamsDataProvider() {

ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().clear();
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().clear();
LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig();
basic.setName("BasicAuthenticator");
basic.setDisplayName("basic");
Expand All @@ -305,8 +305,8 @@ public Object[][] filterParamsDataProvider() {
totp.setName("TOTPAuthenticator");
totp.setDisplayName("totp");

ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().add(basic);
ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().add(totp);
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(basic);
ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(totp);

FederatedAuthenticatorConfig twitterFederated = new FederatedAuthenticatorConfig();
twitterFederated.setDisplayName("twitter");
Expand Down

0 comments on commit 62bf5b7

Please sign in to comment.