Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve authenticator management #6290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -103,9 +103,10 @@ public void testGetAllAuthenticators() throws Exception {
}

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

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
Loading