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 14, 2025
1 parent 0e2f2c9 commit 6b46fe4
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,35 @@ public static ApplicationAuthenticatorService getInstance() {
return instance;
}

@Deprecated
public List<LocalAuthenticatorConfig> getLocalAuthenticators() {
return this.localAuthenticators;
}

/**
* This returns all system defined local authenticators.
*
* @return Retrieved LocalAuthenticatorConfig.
*/
public List<LocalAuthenticatorConfig> getAllSystemDefinedLocalAuthenticators() {

return this.localAuthenticators;
}

/**
* This returns all local authenticators.
*
* @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,8 @@
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
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.*;
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 @@ -1506,15 +1503,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 @@ -52,6 +52,7 @@ public interface IdentityProviderDAO {
* @return
* @throws IdentityApplicationManagementException
*/
@Deprecated
List<LocalAuthenticatorConfig> getAllLocalAuthenticators() throws IdentityApplicationManagementException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public List<IdentityProvider> getAllIdentityProviders()
/**
*
*/
@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 @@ -105,7 +105,8 @@ public void testGetAllAuthenticators() throws Exception {
@Test
public void testGetLocalAuthenticators() throws Exception {

List<ApplicationAuthenticator> localAuthenticators = applicationAuthenticationService.getLocalAuthenticators();
List<ApplicationAuthenticator> localAuthenticators =
applicationAuthenticationService.getAllSystemDefinedLocalAuthenticators();
assertEquals(localAuthenticators.size(), 1);
assertEquals(localAuthenticators.get(0).getName(), LOCAL_AUTHENTICATOR_NAME);
}
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 6b46fe4

Please sign in to comment.