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

Add DAO layer support to manage the user defined local authenticators #6070

Open
wants to merge 2 commits into
base: add-user-defined_authenticator_support
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
@@ -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;
}
}
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.LocalAuthenticatorConfig;
import org.wso2.carbon.identity.core.cache.CacheEntry;

/**
* Cache Entry for the Local Application Authenticator configurations.
*/
public class AuthenticatorCacheEntry extends CacheEntry {

private LocalAuthenticatorConfig authenticatorConfig;

public AuthenticatorCacheEntry(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,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();
}
}
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() {

}
}
}
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.LocalAuthenticatorConfig;
import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.AuthenticationType;

import java.util.List;

/**
* This interface performs CRUD operations for the 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 LocalAuthenticatorConfig.
* @throws AuthenticatorMgtException If an error occurs while adding the authenticator configuration.
*/
LocalAuthenticatorConfig addUserDefinedLocalAuthenticator(
LocalAuthenticatorConfig authenticatorConfig, Integer 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 LocalAuthenticatorConfig.
* @throws AuthenticatorMgtException If an error occurs while updating the authenticator configuration.
*/
LocalAuthenticatorConfig updateUserDefinedLocalAuthenticator(LocalAuthenticatorConfig existingAuthenticatorConfig,
LocalAuthenticatorConfig updatedAuthenticatorConfig, Integer 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 LocalAuthenticatorConfig
* @throws AuthenticatorMgtException If an error occurs while retrieving the authenticator configuration.
*/
LocalAuthenticatorConfig getUserDefinedLocalAuthenticator(String authenticatorConfigName, Integer tenantId)
throws AuthenticatorMgtException;


/**
* Retrieve all user defined Local Application Authenticator configurations.
*
* @param tenantId Tenant Id.
*
* @return Retrieved LocalAuthenticatorConfig
* @throws AuthenticatorMgtException If an error occurs while retrieving the authenticator configurations.
*/
List<LocalAuthenticatorConfig> getAllUserDefinedLocalAuthenticator(Integer 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, Integer tenantId)
throws AuthenticatorMgtException;
}
Loading