Skip to content

Bring First Class Support for AMR #6598

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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
63e0ca6
Initial Changes
Eranda2001 Feb 6, 2025
1b5f48b
FederatedAuthenticator level changes
Eranda2001 Feb 6, 2025
3622107
AMR Updated
Eranda2001 Feb 14, 2025
402cad3
System Local Authenticator AMR fixes
Eranda2001 Feb 25, 2025
31822ab
Initial Changes
Eranda2001 Feb 25, 2025
5ede0d3
Intermediate
Eranda2001 Feb 26, 2025
d0b8c3b
Changes 3/4
Eranda2001 Mar 4, 2025
11d5266
/authenticators/system and Validation
Eranda2001 Mar 24, 2025
2560215
/authenticators/system and Validation
Eranda2001 Mar 24, 2025
666c2e3
j2 changes and remove management level isExistingAuthenticatorNameDB
Eranda2001 Mar 24, 2025
2fef8f7
Cache Layer Implementation and changes to default.json
Eranda2001 Mar 25, 2025
5999d46
Add SQL constants
Eranda2001 Mar 25, 2025
0d76fa8
Formatting changes and minor fixes
Eranda2001 Mar 26, 2025
615b064
Formatting changes and minor fixes
Eranda2001 Mar 31, 2025
a151efe
minor fixes
Eranda2001 Mar 31, 2025
102d96a
Test Cases
Eranda2001 Mar 31, 2025
63368d3
wsdl changes
Eranda2001 Apr 1, 2025
7d54e2f
wsdl bug fix
Eranda2001 Apr 1, 2025
5e45aaa
Updated test cases
Eranda2001 Apr 7, 2025
6b50504
Update federated auth
Eranda2001 Apr 7, 2025
3a12f4a
Checkstyle update
Eranda2001 Apr 8, 2025
33b9ed1
Checkstyle update
Eranda2001 Apr 8, 2025
c494cac
Checkstyle update
Eranda2001 Apr 8, 2025
5052916
Merged the localAuthenticators list loaded on server startup and syst…
Eranda2001 Apr 10, 2025
9e8b105
minor fixes
Eranda2001 Apr 25, 2025
af879cb
Code Review Requested Changes
Eranda2001 Apr 25, 2025
782b273
Minor Changes
Eranda2001 Apr 28, 2025
f908b80
Minor Changes
Eranda2001 Apr 28, 2025
815d645
Minor Fix
Eranda2001 Apr 29, 2025
21c8f16
Caching Issue
Eranda2001 Apr 30, 2025
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 @@ -301,10 +301,62 @@ public UserDefinedLocalAuthenticatorConfig updateUserDefinedLocalAuthenticator(
}

/**
* Update a Local Application Authenticator configuration.
* Add a system defined Local Application Authenticator configuration.
*
* @param authenticatorName Name of Local Application Authenticator configuration to be deleted.
* @param authenticatorConfig Local Application Authenticator configuration.
* @param tenantDomain Tenant domain.
* @throws AuthenticatorMgtException If an error occurs while adding the authenticator configuration.
*/
public LocalAuthenticatorConfig addSystemDefinedLocalAuthenticator(
LocalAuthenticatorConfig authenticatorConfig, String tenantDomain)
throws AuthenticatorMgtException {

if (isAuthenticatorExistsInDB(authenticatorConfig.getName(), tenantDomain)) {
throw buildClientException(AuthenticatorMgtError.ERROR_AUTHENTICATOR_ALREADY_EXIST,
authenticatorConfig.getName());
}
for (LocalAuthenticatorConfig localAuthenticator : localAuthenticators) {
if (localAuthenticator.getName().equals(authenticatorConfig.getName())) {
authenticatorConfig.setEnabled(localAuthenticator.getEnabled());
authenticatorConfig.setDisplayName(localAuthenticator.getDisplayName());
break;
}
}
return dao.addSystemLocalAuthenticator(
authenticatorConfig, IdentityTenantUtil.getTenantId(tenantDomain));
}

/**
* Update a Local Application Authenticator configuration.
*
* @param authenticatorConfig Local Application Authenticator configuration.
*/
public LocalAuthenticatorConfig updateAuthenticatorAmrValue(
LocalAuthenticatorConfig authenticatorConfig, String tenantDomain)
throws AuthenticatorMgtException {

authenticatorValidator.validateAmrValue(authenticatorConfig.getAmrValue());
LocalAuthenticatorConfig existingConfig = resolveExistingSystemLocalAuthenticator(authenticatorConfig.getName(),
tenantDomain);
if (existingConfig == null) {
for (LocalAuthenticatorConfig localAuthenticator : localAuthenticators) {
if (localAuthenticator.getName().equals(authenticatorConfig.getName())) {
existingConfig = addSystemDefinedLocalAuthenticator(authenticatorConfig, tenantDomain);
return existingConfig;
}
}
throw buildClientException(AuthenticatorMgtError.ERROR_NOT_FOUND_AUTHENTICATOR,
authenticatorConfig.getName());
}
return dao.updateSystemLocalAuthenticatorAmrValue(
existingConfig, authenticatorConfig, IdentityTenantUtil.getTenantId(tenantDomain));
}

/**
* Update a Local Application Authenticator configuration.
*
* @param authenticatorName Name of Local Application Authenticator configuration to be deleted.
* @param tenantDomain Tenant domain.
* @throws AuthenticatorMgtException If an error occurs while deleting the authenticator configuration.
*/
public void deleteUserDefinedLocalAuthenticator(String authenticatorName, String tenantDomain)
Expand Down Expand Up @@ -339,7 +391,7 @@ public UserDefinedLocalAuthenticatorConfig getUserDefinedLocalAuthenticator(Stri
* Check whether any local or federated authenticator configuration exists with the given name.
*
* @param authenticatorName Name of the authenticator.
* @param tenantDomain Tenant domain.
* @param tenantDomain Tenant domain.
* @return True if an authenticator with the given name exists.
* @throws AuthenticatorMgtException If an error occurs while checking the existence of the authenticator.
*/
Expand Down Expand Up @@ -374,4 +426,16 @@ private UserDefinedLocalAuthenticatorConfig resolveExistingAuthenticator(String

return dao.getUserDefinedLocalAuthenticator(authenticatorName, IdentityTenantUtil.getTenantId(tenantDomain));
}

private LocalAuthenticatorConfig resolveExistingSystemLocalAuthenticator(String authenticatorName,
String tenantDomain) throws AuthenticatorMgtException {

return dao.getSystemLocalAuthenticator(authenticatorName, IdentityTenantUtil.getTenantId(tenantDomain));
}

private boolean isAuthenticatorExistsInDB(String authenticatorName, String tenantDomain)
throws AuthenticatorMgtException {

return dao.isExistingAuthenticatorName(authenticatorName, IdentityTenantUtil.getTenantId(tenantDomain));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.application.common.cache;

import org.wso2.carbon.identity.core.cache.BaseCache;
import org.wso2.carbon.utils.CarbonUtils;

/**
* Cache for the system defined authenticator configurations.
*/
public class SystemDefinedAuthenticatorCache extends
BaseCache<SystemDefinedAuthenticatorCacheKey, SystemDefinedAuthenticatorCacheEntry> {

private static final String SYSTEM_DEFINED_AUTHENTICATOR_CACHE_NAME = "SystemDefinedAuthenticatorCache";
private static final SystemDefinedAuthenticatorCache INSTANCE = new SystemDefinedAuthenticatorCache();

private SystemDefinedAuthenticatorCache() {
super(SYSTEM_DEFINED_AUTHENTICATOR_CACHE_NAME);
}

public static SystemDefinedAuthenticatorCache getInstance() {

CarbonUtils.checkSecurity();
return INSTANCE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.application.common.cache;

import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig;
import org.wso2.carbon.identity.core.cache.CacheEntry;

/**
* Cache Entry for the system defined authenticator configurations.
*/
public class SystemDefinedAuthenticatorCacheEntry extends CacheEntry {

private LocalAuthenticatorConfig authenticatorConfig;

public SystemDefinedAuthenticatorCacheEntry(LocalAuthenticatorConfig authenticatorConfig) {

this.authenticatorConfig = authenticatorConfig;
}

public LocalAuthenticatorConfig getAuthenticatorConfig() {

return authenticatorConfig;
}

public void setAuthenticatorConfig(LocalAuthenticatorConfig authenticatorConfig) {

this.authenticatorConfig = authenticatorConfig;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.application.common.cache;

import org.wso2.carbon.identity.core.cache.BaseCache;
import org.wso2.carbon.identity.core.cache.CacheKey;

/**
* Cache key for the system defined authenticator configurations.
*/
public class SystemDefinedAuthenticatorCacheKey extends CacheKey {

private final String authenticatorName;

public SystemDefinedAuthenticatorCacheKey(String authenticatorName) {

this.authenticatorName = authenticatorName;
}

public String getAuthenticatorName() {

return authenticatorName;
}

@Override
public boolean equals(Object o) {

if (!(o instanceof AuthenticatorCacheKey)) {
return false;
}
return authenticatorName.equals(((AuthenticatorCacheKey) o).getAuthenticatorName());
}

@Override
public int hashCode() {

return authenticatorName.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static class Column {
public static final String IS_SECRET = "IS_SECRET";
public static final String IMAGE_URL = "IMAGE_URL";
public static final String DESCRIPTION = "DESCRIPTION";
public static final String AMR_VALUE = "AMR_VALUE";

private Column() {

Expand All @@ -64,9 +65,32 @@ public static class Query {
" (:TENANT_ID;, (SELECT ID FROM IDP WHERE IDP.NAME = :IDP_NAME; AND IDP.TENANT_ID = :TENANT_ID;), " +
":NAME;, :IS_ENABLED;, :DEFINED_BY;, :AUTHENTICATION_TYPE;, :DISPLAY_NAME;, " +
":IMAGE_URL;, :DESCRIPTION;)";
public static final String ADD_AUTHENTICATOR_SQL_WITH_AMR = "INSERT INTO IDP_AUTHENTICATOR " +
"(TENANT_ID, IDP_ID, NAME, IS_ENABLED, DEFINED_BY, AMR_VALUE, AUTHENTICATION_TYPE," +
" DISPLAY_NAME, IMAGE_URL, DESCRIPTION) VALUES" +
" (:TENANT_ID;, (SELECT ID FROM IDP WHERE IDP.NAME = :IDP_NAME; AND IDP.TENANT_ID = :TENANT_ID;), " +
":NAME;, :IS_ENABLED;, :DEFINED_BY;, :AUTHENTICATION_TYPE;, :DISPLAY_NAME;, " +
":IMAGE_URL;, :DESCRIPTION;)";
public static final String ADD_SYSTEM_LOCAL_AUTHENTICATOR_SQL = "INSERT INTO IDP_AUTHENTICATOR " +
"(TENANT_ID, IDP_ID, NAME, IS_ENABLED, DEFINED_BY, AMR_VALUE, AUTHENTICATION_TYPE, DISPLAY_NAME) " +
"VALUES " +
"(:TENANT_ID;, " +
"(SELECT ID FROM IDP WHERE NAME = :IDP_NAME; AND TENANT_ID = :TENANT_ID;), " +
":NAME;, :IS_ENABLED;, :DEFINED_BY;, :AMR_VALUE;, :AUTHENTICATION_TYPE;, :DISPLAY_NAME;)";
public static final String UPDATE_AUTHENTICATOR_SQL = "UPDATE IDP_AUTHENTICATOR SET IS_ENABLED = " +
":IS_ENABLED;, DISPLAY_NAME = :DISPLAY_NAME;, IMAGE_URL = :IMAGE_URL;, DESCRIPTION = :DESCRIPTION; " +
"WHERE NAME = :NAME; AND TENANT_ID = :TENANT_ID;";
public static final String UPDATE_AUTHENTICATOR_SQL_WITH_AMR = "UPDATE IDP_AUTHENTICATOR SET IS_ENABLED = " +
":IS_ENABLED;, DISPLAY_NAME = :DISPLAY_NAME;, IMAGE_URL = :IMAGE_URL;, DESCRIPTION = :DESCRIPTION;, " +
"AMR_VALUE = :AMR_VALUE" +
" " +
"WHERE NAME = :NAME; AND TENANT_ID = :TENANT_ID;";
public static final String UPDATE_AUTHENTICATOR_AMR_VALUE_SQL = "UPDATE IDP_AUTHENTICATOR SET AMR_VALUE = " +
":AMR_VALUE; WHERE NAME = :NAME; AND TENANT_ID = :TENANT_ID;";
public static final String GET_SYSTEM_DEFINED_LOCAL_AUTHENTICATOR_SQL = "SELECT * FROM IDP_AUTHENTICATOR " +
"WHERE DEFINED_BY = :DEFINED_BY; AND NAME = :NAME; AND TENANT_ID = :TENANT_ID;" +
"AND IDP_ID IN (SELECT ID FROM IDP WHERE IDP.NAME = :IDP_NAME; " +
"AND IDP.TENANT_ID = :TENANT_ID;)";
public static final String GET_USER_DEFINED_LOCAL_AUTHENTICATOR_SQL = "SELECT * FROM IDP_AUTHENTICATOR " +
"WHERE DEFINED_BY = :DEFINED_BY; AND NAME = :NAME; AND TENANT_ID = :TENANT_ID;" +
"AND IDP_ID IN (SELECT ID FROM IDP WHERE IDP.NAME = :IDP_NAME; " +
Expand All @@ -79,6 +103,13 @@ public static class Query {
"WHERE DEFINED_BY = :DEFINED_BY; AND TENANT_ID = :TENANT_ID; " +
"AND IDP_ID IN (SELECT ID FROM IDP WHERE IDP.NAME = :IDP_NAME; " +
"AND IDP.TENANT_ID = :TENANT_ID;)";
public static final String GET_ALL_USER_DEFINED_AUTHENTICATOR_SQL_WITH_AMR =
"SELECT AUTHENTICATION_TYPE, NAME, DISPLAY_NAME, AMR_VALUE, IMAGE_URL, DESCRIPTION, IS_ENABLED, " +
"DEFINED_BY, ID " +
"FROM IDP_AUTHENTICATOR " +
"WHERE DEFINED_BY = :DEFINED_BY; AND TENANT_ID = :TENANT_ID; " +
"AND IDP_ID IN (SELECT ID FROM IDP WHERE IDP.NAME = :IDP_NAME; " +
"AND IDP.TENANT_ID = :TENANT_ID;)";
public static final String DELETE_AUTHENTICATOR_SQL = "DELETE FROM IDP_AUTHENTICATOR WHERE NAME = :NAME; " +
" AND TENANT_ID = :TENANT_ID;";
public static final String GET_AUTHENTICATOR_ID_SQL = "SELECT ID FROM IDP_AUTHENTICATOR " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.wso2.carbon.identity.application.common.dao;

import org.wso2.carbon.identity.application.common.exception.AuthenticatorMgtException;
import org.wso2.carbon.identity.application.common.exception.AuthenticatorMgtServerException;
import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig;

import java.util.List;
Expand Down Expand Up @@ -53,6 +55,17 @@ UserDefinedLocalAuthenticatorConfig updateUserDefinedLocalAuthenticator(
UserDefinedLocalAuthenticatorConfig updatedAuthenticatorConfig, int tenantId)
throws AuthenticatorMgtException;

/**
*
* @param existingAuthenticatorConfig Existing Local application authenticator configuration.
* @param amrValue New local application authenticator configuration.
* @param tenantId Tenant Id.
* @return Updated LocalAuthenticatorConfig.
* @throws AuthenticatorMgtException If an error occurs while updating the authenticator configuration.
*/
LocalAuthenticatorConfig updateSystemLocalAuthenticatorAmrValue(LocalAuthenticatorConfig existingAuthenticatorConfig,
LocalAuthenticatorConfig amrValue, int tenantId) throws AuthenticatorMgtException;

/**
* Retrieve a local user defined application authenticator configuration by name.
*
Expand All @@ -64,6 +77,16 @@ UserDefinedLocalAuthenticatorConfig updateUserDefinedLocalAuthenticator(
UserDefinedLocalAuthenticatorConfig getUserDefinedLocalAuthenticator(
String authenticatorConfigName, int tenantId) throws AuthenticatorMgtException;

/**
*
* @param authenticatorConfigName Name of the local application authenticator configuration.
* @param tenantId Tenant Id.
* @return Retrieved LocalAuthenticatorConfig.
* @throws AuthenticatorMgtException If an error occurs while retrieving the authenticator configuration.
*/
LocalAuthenticatorConfig getSystemLocalAuthenticator(String authenticatorConfigName, int tenantId)
throws AuthenticatorMgtException;

/**
* Retrieve all user defined local application authenticator configurations.
*
Expand Down Expand Up @@ -93,4 +116,14 @@ void deleteUserDefinedLocalAuthenticator(String authenticatorConfigName, UserDef
* @throws AuthenticatorMgtException If an error occurs while checking the existence of the authenticator.
*/
boolean isExistingAuthenticatorName(String authenticatorName, int tenantId) throws AuthenticatorMgtException;

/**
* Add a new system local authenticator configuration.
*
* @param authenticatorConfig Local application authenticator configuration.
* @param tenantId Tenant Id.
* @return Created LocalAuthenticatorConfig.
*/
LocalAuthenticatorConfig addSystemLocalAuthenticator(LocalAuthenticatorConfig authenticatorConfig, int tenantId)
throws AuthenticatorMgtException;
}
Loading
Loading