Skip to content

Commit

Permalink
fix damin it
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybeeelsdon committed Dec 4, 2024
1 parent b34f1a2 commit 1095bbd
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/BL/Models/Settings/BaseKeyCloakSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BaseKeyCloakSettings
public string ProxyAddresURL { get; set; }
public string TokenRefreshSeconds { get; set; }

public bool IgnoreHttps { get; set; }
public bool DemoMode { get; set; }
public string RedirectURL { get; set; }

public bool UseRedirectURL { get; set; }
Expand Down
7 changes: 4 additions & 3 deletions src/BL/Services/KeycloakCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ namespace BL.Services
public class KeycloakCommon
{
public static async Task<string> GetTokenForUserGuts(string username, string password, string requiredRole, HttpClientHandler proxyHandler,
string keycloakBaseUrl, string clientId, string clientSecret, bool requireHttps)
string keycloakBaseUrl, string clientId, string clientSecret, bool demoMode)
{

Log.Information("{Function} keycloakBaseUrl > {BaseUrl} ,RequireHttps: {RequireHttps}" , "GetTokenForUserGuts", keycloakBaseUrl, requireHttps);
Log.Information("{Function} keycloakBaseUrl > {BaseUrl} , DemoMode: {DemoMode}" , "GetTokenForUserGuts", keycloakBaseUrl, demoMode);
// Log.Information("{Function} username > " + username + " password: " + password, "GetTokenForUserGuts");
var client = new HttpClient(proxyHandler);
var disco = await client.GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest
{
Address = keycloakBaseUrl,
Policy = new DiscoveryPolicy
{
RequireHttps = requireHttps,
RequireHttps = !demoMode,
ValidateEndpoints = !demoMode,
ValidateIssuerName = false, // Keycloak may have a different issuer name format
}
});
Expand Down
10 changes: 5 additions & 5 deletions src/BL/Services/KeycloakTokenHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public class KeycloakTokenHelper
public string _clientId { get; set; }
public string _clientSecret { get; set; }
public bool _useProxy { get; set; }
public bool _requireHttps { get; set; }
public bool _demoMode { get; set; }
public string _proxyUrl { get; set; }

public KeycloakTokenHelper(string keycloakBaseUrl, string clientId, string clientSecret, bool useProxy, string proxyurl, bool ignoreHttps)
public KeycloakTokenHelper(string keycloakBaseUrl, string clientId, string clientSecret, bool useProxy, string proxyurl, bool demoMode)
{
_keycloakBaseUrl = keycloakBaseUrl;
_clientId = clientId;
_clientSecret = clientSecret;
_useProxy = useProxy;
_proxyUrl = proxyurl;
_requireHttps = !ignoreHttps;
_demoMode = demoMode;
}

public async Task<string> GetTokenForUser(string username, string password, string requiredRole)
Expand All @@ -48,9 +48,9 @@ public async Task<string> GetTokenForUser(string username, string password, stri

}

Log.Information("{Function}} 2 requireHttps {RequireHttps}", "GetTokenForUser", _requireHttps);
Log.Information("{Function} 2 demoMode {DemoMode}", "GetTokenForUser", _demoMode);
// Create an HttpClient with the handler
return await KeycloakCommon.GetTokenForUserGuts(username, password, requiredRole, handler, keycloakBaseUrl, clientId, clientSecret, _requireHttps);
return await KeycloakCommon.GetTokenForUserGuts(username, password, requiredRole, handler, keycloakBaseUrl, clientId, clientSecret, _demoMode);

}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DARE-API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
var submissionKeyCloakSettings = new SubmissionKeyCloakSettings();
configuration.Bind(nameof(submissionKeyCloakSettings), submissionKeyCloakSettings);
var demomode = configuration["DemoMode"].ToLower() == "true";
submissionKeyCloakSettings.IgnoreHttps = demomode;
submissionKeyCloakSettings.DemoMode = demomode;
builder.Services.AddSingleton(submissionKeyCloakSettings);

builder.Services.Configure<KestrelServerOptions>(options =>
Expand Down
6 changes: 3 additions & 3 deletions src/DARE-API/Services/KeyclockTokenAPIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public async Task<string> GetTokenForUser(string username, string password, stri
string clientSecret = _settings.ClientSecret;
var proxyhandler = _settings.getProxyHandler;

var requireHttps = !_settings.IgnoreHttps;
Log.Information("{Function}} 1 using proxyhandler _settings.Authority > {Authority}, requireHttps {RequireHttps}", "GetTokenForUser", _settings.Authority, requireHttps);
return await KeycloakCommon.GetTokenForUserGuts(username, password, requiredRole, proxyhandler, keycloakBaseUrl, clientId, clientSecret, requireHttps);

Log.Information("{Function}} 1 using proxyhandler _settings.Authority > {Authority}, demoMode {demoMode}", "GetTokenForUser", _settings.Authority, _settings.DemoMode);
return await KeycloakCommon.GetTokenForUserGuts(username, password, requiredRole, proxyhandler, keycloakBaseUrl, clientId, clientSecret, _settings.DemoMode);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/DARE-FrontEnd/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
var submissionKeyCloakSettings = new SubmissionKeyCloakSettings();
configuration.Bind(nameof(submissionKeyCloakSettings), submissionKeyCloakSettings);
var demomode = configuration["DemoMode"].ToLower() == "true";
submissionKeyCloakSettings.IgnoreHttps = demomode;
submissionKeyCloakSettings.DemoMode = demomode;
builder.Services.AddSingleton(submissionKeyCloakSettings);

var formIOSettings = new FormIOSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public TreCredentialsController(ApplicationDbContext applicationDbContext, IEncD
_encDecHelper = encDec;
_DbContext = applicationDbContext;
_keycloakTokenHelper = new KeycloakTokenHelper(keycloakSettings.BaseUrl, keycloakSettings.ClientId,
keycloakSettings.ClientSecret, keycloakSettings.Proxy, keycloakSettings.ProxyAddresURL, keycloakSettings.IgnoreHttps);
keycloakSettings.ClientSecret, keycloakSettings.Proxy, keycloakSettings.ProxyAddresURL, keycloakSettings.DemoMode);

}

Expand Down
4 changes: 2 additions & 2 deletions src/Data-Egress-API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@
var dataEgressKeyCloakSettings = new DataEgressKeyCloakSettings();
configuration.Bind(nameof(dataEgressKeyCloakSettings), dataEgressKeyCloakSettings);
var demomode = configuration["DemoMode"].ToLower() == "true";
dataEgressKeyCloakSettings.IgnoreHttps = demomode;
dataEgressKeyCloakSettings.DemoMode = demomode;
builder.Services.AddSingleton(dataEgressKeyCloakSettings);


var treKeyCloakSettings = new TreKeyCloakSettings();
configuration.Bind(nameof(treKeyCloakSettings), treKeyCloakSettings);
treKeyCloakSettings.IgnoreHttps = demomode;
treKeyCloakSettings.DemoMode = demomode;
builder.Services.AddSingleton(treKeyCloakSettings);

var minioSettings = new MinioSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public TreClientWithoutTokenHelper(IHttpClientFactory httpClientFactory,
config["TreAPISettings:Address"], false)
{
CredDb = db;
_keycloakTokenHelper = new KeycloakTokenHelper(settings.BaseUrl, settings.ClientId, settings.ClientSecret, settings.Proxy, settings.ProxyAddresURL, settings.IgnoreHttps);
_keycloakTokenHelper = new KeycloakTokenHelper(settings.BaseUrl, settings.ClientId, settings.ClientSecret, settings.Proxy, settings.ProxyAddresURL, settings.DemoMode);
var creds = db.KeycloakCredentials.FirstOrDefault(x => x.CredentialType == CredentialType.Tre);
if (creds != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Data-Egress-UI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
var dataEgressKeyCloakSettings = new DataEgressKeyCloakSettings();
configuration.Bind(nameof(dataEgressKeyCloakSettings), dataEgressKeyCloakSettings);
var demomode = configuration["DemoMode"].ToLower() == "true";
dataEgressKeyCloakSettings.IgnoreHttps = demomode;
dataEgressKeyCloakSettings.DemoMode = demomode;
builder.Services.AddSingleton(dataEgressKeyCloakSettings);


Expand Down
2 changes: 1 addition & 1 deletion src/TRE-API/Controllers/DataEgressCredentialsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DataEgressCredentialsController(ApplicationDbContext applicationDbContext
_encDecHelper = encDec;
_DbContext = applicationDbContext;
_keycloakTokenHelper = new KeycloakTokenHelper(keycloakSettings.BaseUrl, keycloakSettings.ClientId,
keycloakSettings.ClientSecret, keycloakSettings.Proxy, keycloakSettings.ProxyAddresURL, keycloakSettings.IgnoreHttps);
keycloakSettings.ClientSecret, keycloakSettings.Proxy, keycloakSettings.ProxyAddresURL, keycloakSettings.DemoMode);
}

[Authorize(Roles = "dare-tre-admin")]
Expand Down
2 changes: 1 addition & 1 deletion src/TRE-API/Controllers/SubmissionCredentialsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public SubmissionCredentialsController(ApplicationDbContext applicationDbContext
_encDecHelper = encDec;
_DbContext = applicationDbContext;
_keycloakTokenHelper = new KeycloakTokenHelper(keycloakSettings.BaseUrl, keycloakSettings.ClientId,
keycloakSettings.ClientSecret, keycloakSettings.Proxy, keycloakSettings.ProxyAddresURL, keycloakSettings.IgnoreHttps);
keycloakSettings.ClientSecret, keycloakSettings.Proxy, keycloakSettings.ProxyAddresURL, keycloakSettings.DemoMode);

}

Expand Down
2 changes: 1 addition & 1 deletion src/TRE-API/Controllers/TRECredentialsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public TRECredentialsController(ApplicationDbContext applicationDbContext, IEncD
_encDecHelper = encDec;
_DbContext = applicationDbContext;
_keycloakTokenHelper = new KeycloakTokenHelper(keycloakSettings.BaseUrl, keycloakSettings.ClientId,
keycloakSettings.ClientSecret, keycloakSettings.Proxy, keycloakSettings.ProxyAddresURL, keycloakSettings.IgnoreHttps);
keycloakSettings.ClientSecret, keycloakSettings.Proxy, keycloakSettings.ProxyAddresURL, keycloakSettings.DemoMode);

}

Expand Down
6 changes: 3 additions & 3 deletions src/TRE-API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@
var treKeyCloakSettings = new TreKeyCloakSettings();
configuration.Bind(nameof(treKeyCloakSettings), treKeyCloakSettings);
var demomode = configuration["DemoMode"].ToLower() == "true";
treKeyCloakSettings.IgnoreHttps = demomode;
treKeyCloakSettings.DemoMode = demomode;
builder.Services.AddSingleton(treKeyCloakSettings);

var dataEgressKeyCloakSettings = new DataEgressKeyCloakSettings();
configuration.Bind(nameof(dataEgressKeyCloakSettings), dataEgressKeyCloakSettings);
dataEgressKeyCloakSettings.IgnoreHttps = demomode;
dataEgressKeyCloakSettings.DemoMode = demomode;
builder.Services.AddSingleton(dataEgressKeyCloakSettings);

var submissionKeyCloakSettings = new SubmissionKeyCloakSettings();
configuration.Bind(nameof(submissionKeyCloakSettings), submissionKeyCloakSettings);
submissionKeyCloakSettings.IgnoreHttps = demomode;
submissionKeyCloakSettings.DemoMode = demomode;
Log.Information("{Function} DemoMode {DemoMode}, DemoModeS {DemoS}", "Main", demomode, configuration["DemoMode"]);
builder.Services.AddSingleton(submissionKeyCloakSettings);

Expand Down
2 changes: 1 addition & 1 deletion src/TRE-API/Services/DareClientWithoutTokenHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public DareClientWithoutTokenHelper(IHttpClientFactory httpClientFactory,
config["DareAPISettings:Address"], false)
{
CredDb = db;
_keycloakTokenHelper = new KeycloakTokenHelper(settings.BaseUrl, settings.ClientId, settings.ClientSecret, settings.Proxy, settings.ProxyAddresURL, settings.IgnoreHttps);
_keycloakTokenHelper = new KeycloakTokenHelper(settings.BaseUrl, settings.ClientId, settings.ClientSecret, settings.Proxy, settings.ProxyAddresURL, settings.DemoMode);

var creds = db.KeycloakCredentials.FirstOrDefault(x => x.CredentialType == CredentialType.Submission);
if (creds != null)
Expand Down
2 changes: 1 addition & 1 deletion src/TRE-API/Services/DataEgressClientWithoutTokenHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public DataEgressClientWithoutTokenHelper(IHttpClientFactory httpClientFactory,
config["DataEgressAPISettings:Address"], false)
{
CredDb = db;
_keycloakTokenHelper = new KeycloakTokenHelper(settings.BaseUrl, settings.ClientId, settings.ClientSecret, settings.Proxy, settings.ProxyAddresURL, settings.IgnoreHttps);
_keycloakTokenHelper = new KeycloakTokenHelper(settings.BaseUrl, settings.ClientId, settings.ClientSecret, settings.Proxy, settings.ProxyAddresURL, settings.DemoMode);

var creds = db.KeycloakCredentials.FirstOrDefault(x => x.CredentialType == CredentialType.Egress);
if (creds != null)
Expand Down
2 changes: 1 addition & 1 deletion src/TRE-UI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
var treKeyCloakSettings = new TreKeyCloakSettings();
configuration.Bind(nameof(treKeyCloakSettings), treKeyCloakSettings);
var demomode = configuration["DemoMode"].ToLower() == "true";
treKeyCloakSettings.IgnoreHttps = demomode;
treKeyCloakSettings.DemoMode = demomode;
builder.Services.AddSingleton(treKeyCloakSettings);
Log.Information("{Function} Step 1 Authority {Authority}", treKeyCloakSettings.Authority);
var UIName = new TRE_UI.Models.UIName();
Expand Down

0 comments on commit 1095bbd

Please sign in to comment.