using System; using System.Threading.Tasks; using FrameworkDAL.CustomCode.KeyCloak; using FrameworkDAL.DTO.KeyCloak; namespace FrameworkBLL.KeyCloak { public class KeyCloakBLL : IKeyCloakBLL { private readonly IKeyCloakDAL _keyCloakDAL; public KeyCloakBLL(IKeyCloakDAL keyCloakDAL) { _keyCloakDAL = keyCloakDAL; } // Delegates to KeyCloakDAL's own GetMasterAccessToken (Vault-backed admin credential, // named "oidc" HttpClient) — this method used to duplicate that logic with a hardcoded // admin/admin credential; there is exactly one implementation now. public async Task GetMasterAccessToken() { try { return await _keyCloakDAL.GetMasterAccessToken(); } catch (Exception) { throw; } } public async Task CreateRealm(string RealmName) { try { return await _keyCloakDAL.CreateRealm(RealmName); } catch (Exception) { throw; } } public async Task CreateClient(KeyCloakDTO KeyCloakDTO) { try { return await _keyCloakDAL.CreateClient(KeyCloakDTO); } catch (Exception) { throw; } } public async Task CreateRole(KeyCloakDTO KeyCloakDTO) { try { return await _keyCloakDAL.CreateRole(KeyCloakDTO); } catch (Exception) { throw; } } public async Task CreateUser(KeyCloakDTO KeyCloakDTO) { try { return await _keyCloakDAL.CreateUser(KeyCloakDTO); } catch (Exception) { throw; } } public async Task GetUserByUsername(KeyCloakDTO KeyCloakDTO) { try { return await _keyCloakDAL.GetUserByUsername(KeyCloakDTO); } catch (Exception) { throw; } } public async Task KeyCloakAuthenticateUser(KeyCloakDTO KeyCloakDTO) { try { return await _keyCloakDAL.KeyCloakAuthenticateUser(KeyCloakDTO); } catch (Exception) { throw; } } public async Task CreateClientRole(KeyCloakDTO KeyCloakDTO) { try { return await _keyCloakDAL.CreateClientRole(KeyCloakDTO); } catch { throw; } } public async Task AssignClientRoleToUser(KeyCloakDTO dto) { try { return await _keyCloakDAL.AssignClientRoleToUser(dto); } catch (Exception) { throw; } } public async Task SetUserPasswordByUsername(KeyCloakDTO KeyCloakDTO) { try { return await _keyCloakDAL.SetUserPasswordByUsername(KeyCloakDTO); } catch (Exception) { throw; } } public async Task CreateClientAsync(KeycloakClientDTO KeycloakClientDTO) { try { return await _keyCloakDAL.CreateClientAsync(KeycloakClientDTO); } catch (Exception) { throw; } } public async Task GetClientsByRealmAsync(string realmName) { try { return await _keyCloakDAL.GetClientsByRealmAsync( realmName); } catch (Exception) { throw; } } public async Task GetClientByClientIdAsync(string realm, string clientId) { try { return await _keyCloakDAL.GetClientByClientIdAsync( realm, clientId); } catch (Exception) { throw; } } public async Task DeleteClientAsync(string realm, string clientId) { try { return await _keyCloakDAL.DeleteClientAsync( realm, clientId); } catch (Exception) { throw; } } public async Task UpdateClientAsync(string realm, string clientId, KeycloakClientDTO updatedClientDTO) { try { return await _keyCloakDAL.UpdateClientAsync( realm, clientId, updatedClientDTO); } catch (Exception) { throw; } } } }