forked from wso2/carbon-identity-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dao layer support for the custom local auth extensions.
- Loading branch information
1 parent
1dfce46
commit 631d55f
Showing
8 changed files
with
858 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...n/src/main/java/org/wso2/carbon/identity/application/common/cache/AuthenticatorCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2024, 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 Local Application Authenticator configurations. | ||
*/ | ||
public class AuthenticatorCache extends BaseCache<AuthenticatorCacheKey, AuthenticatorCacheEntry> { | ||
|
||
private static final String CACHE_NAME = "AuthenticatorCache"; | ||
private static final AuthenticatorCache INSTANCE = new AuthenticatorCache(); | ||
|
||
private AuthenticatorCache() { | ||
|
||
super(CACHE_NAME); | ||
} | ||
|
||
/** | ||
* Get Authenticator cache by the name instance. | ||
* | ||
* @return Authenticator cache by name instance. | ||
*/ | ||
public static AuthenticatorCache getInstance() { | ||
|
||
CarbonUtils.checkSecurity(); | ||
return INSTANCE; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../main/java/org/wso2/carbon/identity/application/common/cache/AuthenticatorCacheEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2024, 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.UserDefinedLocalAuthenticatorConfig; | ||
import org.wso2.carbon.identity.core.cache.CacheEntry; | ||
|
||
/** | ||
* Cache Entry for the User Defined Local Application Authenticator configurations. | ||
*/ | ||
public class AuthenticatorCacheEntry extends CacheEntry { | ||
|
||
private UserDefinedLocalAuthenticatorConfig authenticatorConfig; | ||
|
||
public AuthenticatorCacheEntry(UserDefinedLocalAuthenticatorConfig authenticatorConfig) { | ||
|
||
this.authenticatorConfig = authenticatorConfig; | ||
} | ||
|
||
public UserDefinedLocalAuthenticatorConfig getAuthenticatorConfig() { | ||
|
||
return authenticatorConfig; | ||
} | ||
|
||
public void setAuthenticatorConfig(UserDefinedLocalAuthenticatorConfig authenticatorConfig) { | ||
|
||
this.authenticatorConfig = authenticatorConfig; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...rc/main/java/org/wso2/carbon/identity/application/common/cache/AuthenticatorCacheKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2024, 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.CacheKey; | ||
|
||
/** | ||
* Cache key for the Local Application Authenticator configurations. | ||
*/ | ||
public class AuthenticatorCacheKey extends CacheKey { | ||
|
||
private final String authenticatorName; | ||
|
||
public AuthenticatorCacheKey(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(); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...va/org/wso2/carbon/identity/application/common/constant/AuthenticatorMgtSQLConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) 2024, 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.constant; | ||
|
||
/** | ||
* SQL constants for authenticator configuration management service. | ||
*/ | ||
public class AuthenticatorMgtSQLConstants { | ||
|
||
private AuthenticatorMgtSQLConstants() { | ||
|
||
} | ||
|
||
/** | ||
* Column Names. | ||
*/ | ||
public static class Column { | ||
|
||
public static final String IDP_ID = "ID"; | ||
public static final String IDP_NAME = "IDP_NAME"; | ||
public static final String TENANT_ID = "TENANT_ID"; | ||
public static final String NAME = "NAME"; | ||
public static final String IS_ENABLED = "IS_ENABLED"; | ||
public static final String DEFINED_BY = "DEFINED_BY"; | ||
public static final String AUTHENTICATION_TYPE = "AUTHENTICATION_TYPE"; | ||
public static final String DISPLAY_NAME = "DISPLAY_NAME"; | ||
public static final String ID = "ID"; | ||
public static final String AUTHENTICATOR_ID = "AUTHENTICATOR_ID"; | ||
public static final String PROPERTY_KEY = "PROPERTY_KEY"; | ||
public static final String PROPERTY_VALUE = "PROPERTY_VALUE"; | ||
public static final String IS_SECRET = "IS_SECRET"; | ||
|
||
private Column() { | ||
|
||
} | ||
} | ||
|
||
/** | ||
* Queries. | ||
*/ | ||
public static class Query { | ||
|
||
public static final String ADD_AUTHENTICATOR_SQL = "INSERT INTO IDP_AUTHENTICATOR " + | ||
"(TENANT_ID, IDP_ID, NAME, IS_ENABLED, DEFINED_BY, AUTHENTICATION_TYPE, DISPLAY_NAME) 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;);"; | ||
public static final String UPDATE_AUTHENTICATOR_SQL = "UPDATE IDP_AUTHENTICATOR SET IS_ENABLED = " + | ||
":IS_ENABLED;, DISPLAY_NAME = :DISPLAY_NAME; WHERE NAME = :NAME; AND TENANT_ID = :TENANT_ID;"; | ||
public static final String GET_AUTHENTICATOR_SQL = "SELECT * FROM IDP_AUTHENTICATOR WHERE NAME = :NAME; " + | ||
" AND TENANT_ID = :TENANT_ID;"; | ||
public static final String GET_ALL_USER_DEFINED_AUTHENTICATOR_SQL = "SELECT * FROM IDP_AUTHENTICATOR " + | ||
"WHERE DEFINED_BY = :DEFINED_BY; AND 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 " + | ||
"WHERE NAME = :NAME; AND TENANT_ID = :TENANT_ID;"; | ||
public static final String ADD_AUTHENTICATOR_PROP_SQL = "INSERT INTO IDP_AUTHENTICATOR_PROPERTY " + | ||
"(AUTHENTICATOR_ID, TENANT_ID, PROPERTY_KEY, PROPERTY_VALUE, IS_SECRET) VALUES " + | ||
"(:AUTHENTICATOR_ID;, :TENANT_ID;, :PROPERTY_KEY;, :PROPERTY_VALUE;, :IS_SECRET;);"; | ||
public static final String DELETE_AUTHENTICATOR_PROP_SQL = "DELETE FROM IDP_AUTHENTICATOR_PROPERTY " + | ||
"WHERE AUTHENTICATOR_ID = :AUTHENTICATOR_ID; AND TENANT_ID = :TENANT_ID;"; | ||
public static final String GET_AUTHENTICATOR_PROP_SQL = "SELECT PROPERTY_KEY, PROPERTY_VALUE, IS_SECRET" + | ||
" FROM IDP_AUTHENTICATOR_PROPERTY " + | ||
"WHERE AUTHENTICATOR_ID = :AUTHENTICATOR_ID; AND TENANT_ID = :TENANT_ID;"; | ||
|
||
private Query() { | ||
|
||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...main/java/org/wso2/carbon/identity/application/common/dao/AuthenticatorManagementDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) 2024, 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.dao; | ||
|
||
import org.wso2.carbon.identity.application.common.exception.AuthenticatorMgtException; | ||
import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig; | ||
import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.AuthenticationType; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* This interface performs CRUD operations for the User defined Local Application Authenticator configurations. | ||
*/ | ||
public interface AuthenticatorManagementDAO { | ||
|
||
/** | ||
* Create a new user defined Local Application Authenticator configuration. | ||
* | ||
* @param authenticatorConfig Local Application Authenticator configuration. | ||
* @param tenantId Tenant Id. | ||
* | ||
* @return Created UserDefinedLocalAuthenticatorConfig. | ||
* @throws AuthenticatorMgtException If an error occurs while adding the authenticator configuration. | ||
*/ | ||
UserDefinedLocalAuthenticatorConfig addUserDefinedLocalAuthenticator( | ||
UserDefinedLocalAuthenticatorConfig authenticatorConfig, int tenantId, AuthenticationType type) | ||
throws AuthenticatorMgtException; | ||
|
||
/** | ||
* Update a user defined Local Application Authenticator configuration. | ||
* | ||
* @param existingAuthenticatorConfig Existing Local Application Authenticator configuration. | ||
* @param updatedAuthenticatorConfig New Local Application Authenticator configuration. | ||
* @param tenantId Tenant Id. | ||
* | ||
* @return Updated UserDefinedLocalAuthenticatorConfig. | ||
* @throws AuthenticatorMgtException If an error occurs while updating the authenticator configuration. | ||
*/ | ||
UserDefinedLocalAuthenticatorConfig updateUserDefinedLocalAuthenticator( | ||
UserDefinedLocalAuthenticatorConfig existingAuthenticatorConfig, | ||
UserDefinedLocalAuthenticatorConfig updatedAuthenticatorConfig, int tenantId) | ||
throws AuthenticatorMgtException; | ||
|
||
/** | ||
* Retrieve a Local user defined Application Authenticator configuration by name. | ||
* | ||
* @param authenticatorConfigName Name of the Local Application Authenticator configuration. | ||
* @param tenantId Tenant Id. | ||
* | ||
* @return Retrieved UserDefinedLocalAuthenticatorConfig | ||
* @throws AuthenticatorMgtException If an error occurs while retrieving the authenticator configuration. | ||
*/ | ||
UserDefinedLocalAuthenticatorConfig getUserDefinedLocalAuthenticator( | ||
String authenticatorConfigName, int tenantId) throws AuthenticatorMgtException; | ||
|
||
/** | ||
* Retrieve all user defined Local Application Authenticator configurations. | ||
* | ||
* @param tenantId Tenant Id. | ||
* | ||
* @return Retrieved UserDefinedLocalAuthenticatorConfig | ||
* @throws AuthenticatorMgtException If an error occurs while retrieving the authenticator configurations. | ||
*/ | ||
List<UserDefinedLocalAuthenticatorConfig> getAllUserDefinedLocalAuthenticator(int tenantId) | ||
throws AuthenticatorMgtException; | ||
|
||
/** | ||
* Create a new Local Application Authenticator configuration. | ||
* | ||
* @param authenticatorConfigName Name of the Local Application Authenticator configuration. | ||
* @param tenantId Tenant Id. | ||
* | ||
* @throws AuthenticatorMgtException If an error occurs while deleting the authenticator configuration. | ||
*/ | ||
void deleteUserDefinedLocalAuthenticator(String authenticatorConfigName, UserDefinedLocalAuthenticatorConfig | ||
authenticatorConfig, int tenantId) throws AuthenticatorMgtException; | ||
} |
Oops, something went wrong.