Skip to content

Commit

Permalink
Add authentication DAO layer for user def auth mgt.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Dec 3, 2024
1 parent 56b7c3b commit 5ef08cc
Show file tree
Hide file tree
Showing 7 changed files with 783 additions and 0 deletions.
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 user defined 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.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;
}
}
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 user defined 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,91 @@
/*
* 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 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) 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 user defined 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;
}
Loading

0 comments on commit 5ef08cc

Please sign in to comment.