diff --git a/docs/Features/security.md b/docs/Features/security.md index f9211982c..2b071a708 100644 --- a/docs/Features/security.md +++ b/docs/Features/security.md @@ -16,6 +16,19 @@ You can find the jwt configuration in `appsettings.json` }, ``` +## Enforce HTTPS + +You can enforce HTTPS by setting `"EnforceHttps": true` in `appsettings.Development.json` or `appsettings.Production.json`. + +```json +"Security": { + "EnforceHttps": true +}, +``` + +For more details, please see [Enforce HTTPS in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-2.1&tabs=visual-studio#http-strict-transport-security-protocol-hsts) + + ## OAuth2 and OpenID Connect OAuth is a stateful security mechanism, like HTTP Session. Spring Security provides excellent OAuth 2.0 and OIDC support, and this is leveraged by JHipster. If you're not sure what OAuth and OpenID Connect (OIDC) are, please see [What the Heck is OAuth?](https://developer.okta.com/blog/2017/06/21/what-the-heck-is-oauth) @@ -35,16 +48,15 @@ The security settings in `appsettings.json` are configured for this image. ``` appsettings.json: ... -"jhipster": { - "Security": { - "Authentication": { - "OAuth2": { - "Provider": { - "IssuerUri": "http://localhost:9080/auth/realms/jhipster", - "LogOutUri": "http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/logout", - "ClientId": "web_app", - "ClientSecret": "web_app" - } + "Security": { + "Authentication": { + "OAuth2": { + "Provider": { + "IssuerUri": "http://localhost:9080/auth/realms/jhipster", + "LogOutUri": "http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/logout", + "ClientId": "web_app", + "ClientSecret": "web_app" + } ``` Keycloak uses an embedded H2 database by default, so you will lose the created users if you restart your Docker container. To keep your data, please read the [Keycloak Docker documentation](https://hub.docker.com/r/jboss/keycloak/). One solution, with keeping the H2 database, is to do the following: @@ -63,16 +75,15 @@ Modify `appsettings.json` to use your Okta settings. Hint: replace `{yourOktaDom ``` appsettings.json: ... -"jhipster": { - "Security": { - "Authentication": { - "OAuth2": { - "Provider": { - "IssuerUri": "https://{yourOktaDomain}/oauth2/default", - "LogOutUri": "https://{yourOktaDomain}/oauth2/default/v1/logout", - "ClientId": "client_id", - "ClientSecret": "client_secret" - } + "Security": { + "Authentication": { + "OAuth2": { + "Provider": { + "IssuerUri": "https://{yourOktaDomain}/oauth2/default", + "LogOutUri": "https://{yourOktaDomain}/oauth2/default/v1/logout", + "ClientId": "client_id", + "ClientSecret": "client_secret" + } ``` Create an OIDC App in Okta to get a `{client-id}` and `{client-secret}`. To do this, log in to your Okta Developer account and navigate to **Applications** > **Add Application**. Click **Web** and click the **Next** button. Give the app a name you’ll remember, and specify `http://localhost:[port]/login/oauth2/code/oidc` as a Login redirect URI. Click **Done**, then edit your app to add `http://localhost:[port]` as a Logout redirect URI. Copy the client ID and secret into your `application.yml` file. diff --git a/generators/common/templates/dotnetcore/README.md.ejs b/generators/common/templates/dotnetcore/README.md.ejs index ade059b6c..49d98f390 100644 --- a/generators/common/templates/dotnetcore/README.md.ejs +++ b/generators/common/templates/dotnetcore/README.md.ejs @@ -142,7 +142,7 @@ To format the dotnet code, run To launch your application's tests, run: - dotnet test --list-tests --verbosity normal + dotnet test --verbosity normal <% if (!skipClient) { %> ### Client tests diff --git a/generators/entity-server/templates/dotnetcore/test/Project.Test/Controllers/EntityResourceIntTest.cs.ejs b/generators/entity-server/templates/dotnetcore/test/Project.Test/Controllers/EntityResourceIntTest.cs.ejs index 167014846..122c7957b 100644 --- a/generators/entity-server/templates/dotnetcore/test/Project.Test/Controllers/EntityResourceIntTest.cs.ejs +++ b/generators/entity-server/templates/dotnetcore/test/Project.Test/Controllers/EntityResourceIntTest.cs.ejs @@ -157,7 +157,7 @@ namespace <%= namespace %>.Test.Controllers { public <%= pascalizedEntityClass %>ResourceIntTest() { - _factory = new NhipsterWebApplicationFactory().WithMockUser(); + _factory = new AppWebApplicationFactory().WithMockUser(); _client = _factory.CreateClient(); _<%= camelCasedEntityClass %>Repository = _factory.GetRequiredServiceRepository>(); @@ -188,7 +188,7 @@ namespace <%= namespace %>.Test.Controllers <%_ } _%> <%_ }); _%> - private readonly NhipsterWebApplicationFactory _factory; + private readonly AppWebApplicationFactory _factory; private readonly HttpClient _client; private readonly I<%= pascalizedEntityClass %>Repository _<%= camelCasedEntityClass %>Repository; diff --git a/generators/server/files.js b/generators/server/files.js index 751af5f01..15147c52f 100644 --- a/generators/server/files.js +++ b/generators/server/files.js @@ -419,9 +419,9 @@ const serverFiles = { path: SERVER_SRC_DIR, templates: [ { - file: 'Project.Infrastructure/Configuration/JHipsterSettings.cs', + file: 'Project.Infrastructure/Configuration/SecuritySettings.cs', renameTo: generator => - `${generator.pascalizedBaseName}${constants.PROJECT_INFRASTRUCTURE_SUFFIX}/Configuration/JHipsterSettings.cs`, + `${generator.pascalizedBaseName}${constants.PROJECT_INFRASTRUCTURE_SUFFIX}/Configuration/SecuritySettings.cs`, }, ], }, @@ -503,8 +503,8 @@ const serverFiles = { path: SERVER_SRC_DIR, templates: [ { - file: 'Project/Configuration/NhipsterStartup.cs', - renameTo: generator => `${generator.mainProjectDir}/Configuration/NhipsterStartup.cs`, + file: 'Project/Configuration/AppSettingsStartup.cs', + renameTo: generator => `${generator.mainProjectDir}/Configuration/AppSettingsStartup.cs`, }, ], }, @@ -984,8 +984,8 @@ const serverFiles = { path: SERVER_TEST_DIR, templates: [ { - file: 'Project.Test/Setup/NhipsterWebApplicationFactory.cs', - renameTo: generator => `${generator.testProjectDir}/Setup/NhipsterWebApplicationFactory.cs`, + file: 'Project.Test/Setup/AppWebApplicationFactory.cs', + renameTo: generator => `${generator.testProjectDir}/Setup/AppWebApplicationFactory.cs`, }, ], }, diff --git a/generators/server/index.js b/generators/server/index.js index 48da67e4c..0d94238ef 100644 --- a/generators/server/index.js +++ b/generators/server/index.js @@ -146,11 +146,7 @@ module.exports = class extends ServerGenerator { )}` ) ); - this.log( - chalk.green( - `Test your .Net Core application:\n${chalk.yellow.bold('dotnet test --list-tests --verbosity normal')}` - ) - ); + this.log(chalk.green(`Test your .Net Core application:\n${chalk.yellow.bold('dotnet test --verbosity normal')}`)); }); }, }; diff --git a/generators/server/templates/dotnetcore/docker/central-server-config/application.json.ejs b/generators/server/templates/dotnetcore/docker/central-server-config/application.json.ejs index e12caf4ba..6f7dd5577 100644 --- a/generators/server/templates/dotnetcore/docker/central-server-config/application.json.ejs +++ b/generators/server/templates/dotnetcore/docker/central-server-config/application.json.ejs @@ -1,12 +1,10 @@ -{ - "jhipster": { - "Security": { - "Authentication": { - "Jwt": { - "Base64Secret": "bXktc2VjcmV0LWtleS13aGljaC1zaG91bGQtYmUtY2hhbmdlZC1pbi1wcm9kdWN0aW9uLWFuZC1iZS1iYXNlNjQtZW5jb2RlZAo=", - "TokenValidityInSeconds": 86400, - "TokenValidityInSecondsForRememberMe": 2592000 - } +{ + "Security": { + "Authentication": { + "Jwt": { + "Base64Secret": "bXktc2VjcmV0LWtleS13aGljaC1zaG91bGQtYmUtY2hhbmdlZC1pbi1wcm9kdWN0aW9uLWFuZC1iZS1iYXNlNjQtZW5jb2RlZAo=", + "TokenValidityInSeconds": 86400, + "TokenValidityInSecondsForRememberMe": 2592000 } }, "Cors": { @@ -16,6 +14,7 @@ "ExposedHeaders": "Authorization,Link,X-Total-Count,X-Pagination", "AllowCredentials": true, "MaxAge": 1800 - } + }, + "EnforceHttps": false } } diff --git a/generators/server/templates/dotnetcore/src/Project.Domain.Services/MailService.cs.ejs b/generators/server/templates/dotnetcore/src/Project.Domain.Services/MailService.cs.ejs index 9b018c177..e0a2c7d56 100644 --- a/generators/server/templates/dotnetcore/src/Project.Domain.Services/MailService.cs.ejs +++ b/generators/server/templates/dotnetcore/src/Project.Domain.Services/MailService.cs.ejs @@ -25,11 +25,11 @@ namespace <%= namespace %>.Domain.Services { } - // private readonly JHipsterSettings _jhipsterSettings; + // private readonly SecuritySettings _securitySettings; - // public MailService(IOptions jhipsterSettings) + // public MailService(IOptions securitySettings) // { - // _jhipsterSettings = jhipsterSettings.Value; + // _securitySettings = securitySettings.Value; // } public virtual Task SendPasswordResetMail(User user) diff --git a/generators/server/templates/dotnetcore/src/Project.Infrastructure/Configuration/JHipsterSettings.cs.ejs b/generators/server/templates/dotnetcore/src/Project.Infrastructure/Configuration/SecuritySettings.cs.ejs similarity index 94% rename from generators/server/templates/dotnetcore/src/Project.Infrastructure/Configuration/JHipsterSettings.cs.ejs rename to generators/server/templates/dotnetcore/src/Project.Infrastructure/Configuration/SecuritySettings.cs.ejs index a58e09942..99f79609b 100644 --- a/generators/server/templates/dotnetcore/src/Project.Infrastructure/Configuration/JHipsterSettings.cs.ejs +++ b/generators/server/templates/dotnetcore/src/Project.Infrastructure/Configuration/SecuritySettings.cs.ejs @@ -14,16 +14,11 @@ -%> namespace <%= namespace %>.Infrastructure.Configuration { - public class JHipsterSettings - { - public Security Security { get; set; } - - public Cors Cors { get; set; } - } - - public class Security + public class SecuritySettings { public Authentication Authentication { get; set; } + public Cors Cors { get; set; } + public bool EnforceHttps { get; set; } } <%_ if (authenticationType === 'jwt') { _%> diff --git a/generators/server/templates/dotnetcore/src/Project/Configuration/NhipsterStartup.cs.ejs b/generators/server/templates/dotnetcore/src/Project/Configuration/AppSettingsStartup.cs.ejs similarity index 74% rename from generators/server/templates/dotnetcore/src/Project/Configuration/NhipsterStartup.cs.ejs rename to generators/server/templates/dotnetcore/src/Project/Configuration/AppSettingsStartup.cs.ejs index ce4a02373..b55e4ce4c 100644 --- a/generators/server/templates/dotnetcore/src/Project/Configuration/NhipsterStartup.cs.ejs +++ b/generators/server/templates/dotnetcore/src/Project/Configuration/AppSettingsStartup.cs.ejs @@ -19,11 +19,13 @@ using Microsoft.Extensions.DependencyInjection; namespace <%= namespace %>.Configuration { - public static class NhipsterSettingsConfiguration + public static class AppSettingsConfiguration { - public static IServiceCollection AddNhipsterModule(this IServiceCollection services, IConfiguration configuration) + public static IServiceCollection AddAppSettingsModule(this IServiceCollection services, IConfiguration configuration) { - services.Configure(configuration.GetSection("jhipster")); + // Use this to load settings from appSettings file + services.Configure(options => configuration.GetSection("security").Bind(options)); + return services; } } diff --git a/generators/server/templates/dotnetcore/src/Project/Configuration/SecurityStartup.cs.ejs b/generators/server/templates/dotnetcore/src/Project/Configuration/SecurityStartup.cs.ejs index 3ba967bc7..7b8937352 100644 --- a/generators/server/templates/dotnetcore/src/Project/Configuration/SecurityStartup.cs.ejs +++ b/generators/server/templates/dotnetcore/src/Project/Configuration/SecurityStartup.cs.ejs @@ -59,15 +59,15 @@ namespace <%= namespace %>.Configuration <%_ if (authenticationType === 'jwt') { _%> public static IServiceCollection AddSecurityModule(this IServiceCollection services) <%_ } else { _%> - public static IServiceCollection AddSecurityModule(this IServiceCollection services, JHipsterSettings jhipsterSettings) + public static IServiceCollection AddSecurityModule(this IServiceCollection services, SecuritySettings securitySettings) <%_ } _%> { <%_ if (authenticationType === 'jwt') { _%> //TODO Retrieve the signing key properly (DRY with TokenProvider) - var opt = services.BuildServiceProvider().GetRequiredService>(); - var jhipsterSettings = opt.Value; + var opt = services.BuildServiceProvider().GetRequiredService>(); + var securitySettings = opt.Value; byte[] keyBytes; - var secret = jhipsterSettings.Security.Authentication.Jwt.Secret; + var secret = securitySettings.Authentication.Jwt.Secret; if (!string.IsNullOrWhiteSpace(secret)) { @@ -75,7 +75,7 @@ namespace <%= namespace %>.Configuration } else { - keyBytes = Convert.FromBase64String(jhipsterSettings.Security.Authentication.Jwt.Base64Secret); + keyBytes = Convert.FromBase64String(securitySettings.Authentication.Jwt.Base64Secret); } JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); // => remove default claims @@ -130,9 +130,9 @@ namespace <%= namespace %>.Configuration .AddCookie() .AddOpenIdConnect(options => { - options.Authority = jhipsterSettings.Security.Authentication.OAuth2.Provider.IssuerUri; - options.ClientId = jhipsterSettings.Security.Authentication.OAuth2.Provider.ClientId; - options.ClientSecret = jhipsterSettings.Security.Authentication.OAuth2.Provider.ClientSecret; + options.Authority = securitySettings.Authentication.OAuth2.Provider.IssuerUri; + options.ClientId = securitySettings.Authentication.OAuth2.Provider.ClientId; + options.ClientSecret = securitySettings.Authentication.OAuth2.Provider.ClientSecret; options.SaveTokens = true; options.ResponseType = OpenIdConnectResponseType.Code; options.RequireHttpsMetadata = false; // dev only @@ -151,16 +151,18 @@ namespace <%= namespace %>.Configuration } public static IApplicationBuilder UseApplicationSecurity(this IApplicationBuilder app, - JHipsterSettings jhipsterSettings) + SecuritySettings securitySettings) { - app.UseCors(CorsPolicyBuilder(jhipsterSettings.Cors)); + app.UseCors(CorsPolicyBuilder(securitySettings.Cors)); app.UseAuthentication(); <%_ if (authenticationType === 'oauth2') { _%> app.UseAuthorization(); <%_ } _%> - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - app.UseHttpsRedirection(); + if (securitySettings.EnforceHttps) + { + app.UseHsts(); + app.UseHttpsRedirection(); + } return app; } diff --git a/generators/server/templates/dotnetcore/src/Project/Controllers/AuthController.cs.ejs b/generators/server/templates/dotnetcore/src/Project/Controllers/AuthController.cs.ejs index b3bc30fea..2cacd0711 100644 --- a/generators/server/templates/dotnetcore/src/Project/Controllers/AuthController.cs.ejs +++ b/generators/server/templates/dotnetcore/src/Project/Controllers/AuthController.cs.ejs @@ -12,9 +12,9 @@ namespace <%= namespace %>.Controllers [ApiController] public class AuthController : ControllerBase { - private readonly JHipsterSettings _settings; + private readonly SecuritySettings _settings; - public AuthController(IOptions settings) + public AuthController(IOptions settings) { _settings = settings.Value; } @@ -37,7 +37,7 @@ namespace <%= namespace %>.Controllers await HttpContext.SignOutAsync(); return Ok(new { - logoutUrl = _settings.Security.Authentication.OAuth2.Provider.LogOutUri, + logoutUrl = _settings.Authentication.OAuth2.Provider.LogOutUri, idToken = await HttpContext.GetTokenAsync("id_token") }); } diff --git a/generators/server/templates/dotnetcore/src/Project/Security/Jwt/TokenProvider.cs.ejs b/generators/server/templates/dotnetcore/src/Project/Security/Jwt/TokenProvider.cs.ejs index 041e21306..a550a84ba 100644 --- a/generators/server/templates/dotnetcore/src/Project/Security/Jwt/TokenProvider.cs.ejs +++ b/generators/server/templates/dotnetcore/src/Project/Security/Jwt/TokenProvider.cs.ejs @@ -37,7 +37,7 @@ namespace <%= namespace %>.Security.Jwt { private const string AuthoritiesKey = "auth"; - private readonly JHipsterSettings _jhipsterSettings; + private readonly SecuritySettings _securitySettings; private readonly JwtSecurityTokenHandler _jwtSecurityTokenHandler; @@ -50,10 +50,10 @@ namespace <%= namespace %>.Security.Jwt private long _tokenValidityInSecondsForRememberMe; - public TokenProvider(ILogger log, IOptions jhipsterSettings) + public TokenProvider(ILogger log, IOptions securitySettings) { _log = log; - _jhipsterSettings = jhipsterSettings.Value; + _securitySettings = securitySettings.Value; _jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); Init(); } @@ -100,24 +100,24 @@ namespace <%= namespace %>.Security.Jwt private void Init() { byte[] keyBytes; - var secret = _jhipsterSettings.Security.Authentication.Jwt.Secret; + var secret = _securitySettings.Authentication.Jwt.Secret; if (!string.IsNullOrWhiteSpace(secret)) { _log.LogWarning("Warning: the JWT key used is not Base64-encoded. " + - "We recommend using the `jhipster.security.authentication.jwt.base64-secret` key for optimum security."); + "We recommend using the `security.authentication.jwt.base64-secret` key for optimum security."); keyBytes = Encoding.ASCII.GetBytes(secret); } else { _log.LogDebug("Using a Base64-encoded JWT secret key"); - keyBytes = Convert.FromBase64String(_jhipsterSettings.Security.Authentication.Jwt.Base64Secret); + keyBytes = Convert.FromBase64String(_securitySettings.Authentication.Jwt.Base64Secret); } _key = new SigningCredentials(new SymmetricSecurityKey(keyBytes), SecurityAlgorithms.HmacSha256Signature); - _tokenValidityInSeconds = _jhipsterSettings.Security.Authentication.Jwt.TokenValidityInSeconds; + _tokenValidityInSeconds = _securitySettings.Authentication.Jwt.TokenValidityInSeconds; _tokenValidityInSecondsForRememberMe = - _jhipsterSettings.Security.Authentication.Jwt.TokenValidityInSecondsForRememberMe; + _securitySettings.Authentication.Jwt.TokenValidityInSecondsForRememberMe; } private static ClaimsIdentity CreateSubject(IPrincipal principal) diff --git a/generators/server/templates/dotnetcore/src/Project/Startup.cs.ejs b/generators/server/templates/dotnetcore/src/Project/Startup.cs.ejs index 3e9943944..18d5b7fbf 100644 --- a/generators/server/templates/dotnetcore/src/Project/Startup.cs.ejs +++ b/generators/server/templates/dotnetcore/src/Project/Startup.cs.ejs @@ -51,14 +51,14 @@ namespace <%= namespace %> public virtual void ConfigureServices(IServiceCollection services) { services - .AddNhipsterModule(Configuration); + .AddAppSettingsModule(Configuration); AddDatabase(services); <%_ if (authenticationType === 'oauth2') { _%> // Build an intermediate service provider var sp = services.BuildServiceProvider(); - var jhipsterSettings = sp.GetService>().Value; + var securitySettings = sp.GetService>().Value; <%_ } _%> services @@ -66,7 +66,7 @@ namespace <%= namespace %> .AddSecurityModule() <%_ } else { if (applicationType !== 'microservice') { _%> - .AddSecurityModule(jhipsterSettings) + .AddSecurityModule(securitySettings) <%_ } } _%> .AddProblemDetailsModule(Environment) @@ -89,11 +89,11 @@ namespace <%= namespace %> // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public virtual void Configure(IApplicationBuilder app, IHostEnvironment env, IServiceProvider serviceProvider, - ApplicationDatabaseContext context, IOptions jhipsterSettingsOptions) + ApplicationDatabaseContext context, IOptions securitySettingsOptions) { - var jhipsterSettings = jhipsterSettingsOptions.Value; + var securitySettings = securitySettingsOptions.Value; app - .UseApplicationSecurity(jhipsterSettings) + .UseApplicationSecurity(securitySettings) .UseApplicationProblemDetails() .UseApplicationSwagger() .UseApplicationWeb(env) diff --git a/generators/server/templates/dotnetcore/src/Project/appsettings.Development.json.ejs b/generators/server/templates/dotnetcore/src/Project/appsettings.Development.json.ejs index 05e99557b..c37b113eb 100644 --- a/generators/server/templates/dotnetcore/src/Project/appsettings.Development.json.ejs +++ b/generators/server/templates/dotnetcore/src/Project/appsettings.Development.json.ejs @@ -55,4 +55,7 @@ }, <%_ break; }_%> + "Security": { + "EnforceHttps": false, + } } diff --git a/generators/server/templates/dotnetcore/src/Project/appsettings.Production.json.ejs b/generators/server/templates/dotnetcore/src/Project/appsettings.Production.json.ejs index e3a882f18..ad14084a3 100644 --- a/generators/server/templates/dotnetcore/src/Project/appsettings.Production.json.ejs +++ b/generators/server/templates/dotnetcore/src/Project/appsettings.Production.json.ejs @@ -65,4 +65,7 @@ }, <%_ break; }_%> + "Security": { + "EnforceHttps": true, + } } diff --git a/generators/server/templates/dotnetcore/src/Project/appsettings.json.ejs b/generators/server/templates/dotnetcore/src/Project/appsettings.json.ejs index 73fe3e94b..bb66f9a03 100644 --- a/generators/server/templates/dotnetcore/src/Project/appsettings.json.ejs +++ b/generators/server/templates/dotnetcore/src/Project/appsettings.json.ejs @@ -65,32 +65,30 @@ <%_ } _%> }, <%_ } _%> - "jhipster": { - "Security": { - "Authentication": { - <%_ if (authenticationType === 'jwt') { _%> - "Jwt": { - "Base64Secret": "bXktc2VjcmV0LWtleS13aGljaC1zaG91bGQtYmUtY2hhbmdlZC1pbi1wcm9kdWN0aW9uLWFuZC1iZS1iYXNlNjQtZW5jb2RlZAo=", - "TokenValidityInSeconds": 86400, - "TokenValidityInSecondsForRememberMe": 2592000 - } - <%_ } else { _%> - "OAuth2": { - "Provider": { - "IssuerUri": "http://localhost:9080/auth/realms/jhipster", - "LogOutUri": "http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/logout", - "ClientId": "web_app", - "ClientSecret": "web_app" - } - //"Provider": { - // "IssuerUri": "https://{yourOktaDomain}/oauth2/default", - // "LogOutUri": "https://{yourOktaDomain}/oauth2/default/v1/logout", - // "ClientId": "client_id", - // "ClientSecret": "client_secret" - //} - } - <%_ } _%> + "Security": { + "Authentication": { + <%_ if (authenticationType === 'jwt') { _%> + "Jwt": { + "Base64Secret": "bXktc2VjcmV0LWtleS13aGljaC1zaG91bGQtYmUtY2hhbmdlZC1pbi1wcm9kdWN0aW9uLWFuZC1iZS1iYXNlNjQtZW5jb2RlZAo=", + "TokenValidityInSeconds": 86400, + "TokenValidityInSecondsForRememberMe": 2592000 } + <%_ } else { _%> + "OAuth2": { + "Provider": { + "IssuerUri": "http://localhost:9080/auth/realms/jhipster", + "LogOutUri": "http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/logout", + "ClientId": "web_app", + "ClientSecret": "web_app" + } + //"Provider": { + // "IssuerUri": "https://{yourOktaDomain}/oauth2/default", + // "LogOutUri": "https://{yourOktaDomain}/oauth2/default/v1/logout", + // "ClientId": "client_id", + // "ClientSecret": "client_secret" + //} + } + <%_ } _%> }, "Cors": { "AllowedOrigins": "*", diff --git a/generators/server/templates/dotnetcore/test/Project.Test/Controllers/AccountResourceIntTest.cs.ejs b/generators/server/templates/dotnetcore/test/Project.Test/Controllers/AccountResourceIntTest.cs.ejs index 0ff29fb7f..8048a012d 100644 --- a/generators/server/templates/dotnetcore/test/Project.Test/Controllers/AccountResourceIntTest.cs.ejs +++ b/generators/server/templates/dotnetcore/test/Project.Test/Controllers/AccountResourceIntTest.cs.ejs @@ -37,10 +37,10 @@ namespace <%= namespace %>.Test.Controllers { public AccountResourceIntTest() { - _factory = new NhipsterWebApplicationFactory(); + _factory = new AppWebApplicationFactory(); } - private readonly NhipsterWebApplicationFactory _factory; + private readonly AppWebApplicationFactory _factory; [Fact] public async Task TestActivateAccount() diff --git a/generators/server/templates/dotnetcore/test/Project.Test/Controllers/ProfileInfoControllerIntTest.cs.ejs b/generators/server/templates/dotnetcore/test/Project.Test/Controllers/ProfileInfoControllerIntTest.cs.ejs index 8cc45fc3b..684324b4b 100644 --- a/generators/server/templates/dotnetcore/test/Project.Test/Controllers/ProfileInfoControllerIntTest.cs.ejs +++ b/generators/server/templates/dotnetcore/test/Project.Test/Controllers/ProfileInfoControllerIntTest.cs.ejs @@ -25,11 +25,11 @@ namespace <%= namespace %>.Test.Controllers public class ProfileInfoControllerIntTest { - private readonly NhipsterWebApplicationFactory _factory; + private readonly AppWebApplicationFactory _factory; public ProfileInfoControllerIntTest() { - _factory = new NhipsterWebApplicationFactory(); + _factory = new AppWebApplicationFactory(); } [Fact] diff --git a/generators/server/templates/dotnetcore/test/Project.Test/Controllers/UserJwtControllerIntTest.cs.ejs b/generators/server/templates/dotnetcore/test/Project.Test/Controllers/UserJwtControllerIntTest.cs.ejs index f37ddca7e..a3fcbb41c 100644 --- a/generators/server/templates/dotnetcore/test/Project.Test/Controllers/UserJwtControllerIntTest.cs.ejs +++ b/generators/server/templates/dotnetcore/test/Project.Test/Controllers/UserJwtControllerIntTest.cs.ejs @@ -31,14 +31,14 @@ namespace <%= namespace %>.Test.Controllers { public UserJwtControllerIntTest() { - _factory = new NhipsterWebApplicationFactory(); + _factory = new AppWebApplicationFactory(); _client = _factory.CreateClient(); _userManager = _factory.GetRequiredService>(); _passwordHasher = _factory.GetRequiredService>(); } - private readonly NhipsterWebApplicationFactory _factory; + private readonly AppWebApplicationFactory _factory; private readonly HttpClient _client; private readonly UserManager _userManager; diff --git a/generators/server/templates/dotnetcore/test/Project.Test/Controllers/UserResourceIntTest.cs.ejs b/generators/server/templates/dotnetcore/test/Project.Test/Controllers/UserResourceIntTest.cs.ejs index 86795468f..7c3bbd0f4 100644 --- a/generators/server/templates/dotnetcore/test/Project.Test/Controllers/UserResourceIntTest.cs.ejs +++ b/generators/server/templates/dotnetcore/test/Project.Test/Controllers/UserResourceIntTest.cs.ejs @@ -35,7 +35,7 @@ namespace <%= namespace %>.Test.Controllers { public UserResourceIntTest() { - _factory = new NhipsterWebApplicationFactory().WithMockUser("test", new HashSet { RolesConstants.ADMIN }); + _factory = new AppWebApplicationFactory().WithMockUser("test", new HashSet { RolesConstants.ADMIN }); _client = _factory.CreateClient(); _userManager = _factory.GetRequiredService>(); _passwordHasher = _userManager.PasswordHasher; @@ -73,7 +73,7 @@ namespace <%= namespace %>.Test.Controllers private const string DefaultLangkey = "en"; private const string UpdatedLangkey = "fr"; - private readonly NhipsterWebApplicationFactory _factory; + private readonly AppWebApplicationFactory _factory; private readonly HttpClient _client; diff --git a/generators/server/templates/dotnetcore/test/Project.Test/Fixme.cs.ejs b/generators/server/templates/dotnetcore/test/Project.Test/Fixme.cs.ejs index 354be0cb9..d282607c6 100644 --- a/generators/server/templates/dotnetcore/test/Project.Test/Fixme.cs.ejs +++ b/generators/server/templates/dotnetcore/test/Project.Test/Fixme.cs.ejs @@ -20,7 +20,7 @@ namespace <%= namespace %>.Test { public static class Fixme { - public static User ReloadUser(NhipsterWebApplicationFactory factory, User user) + public static User ReloadUser(AppWebApplicationFactory factory, User user) where TEntryPoint : class { var applicationDatabaseContext = factory.GetRequiredService(); diff --git a/generators/server/templates/dotnetcore/test/Project.Test/Setup/NhipsterWebApplicationFactory.cs.ejs b/generators/server/templates/dotnetcore/test/Project.Test/Setup/AppWebApplicationFactory.cs.ejs similarity index 94% rename from generators/server/templates/dotnetcore/test/Project.Test/Setup/NhipsterWebApplicationFactory.cs.ejs rename to generators/server/templates/dotnetcore/test/Project.Test/Setup/AppWebApplicationFactory.cs.ejs index d57e90a31..b6fa8457d 100644 --- a/generators/server/templates/dotnetcore/test/Project.Test/Setup/NhipsterWebApplicationFactory.cs.ejs +++ b/generators/server/templates/dotnetcore/test/Project.Test/Setup/AppWebApplicationFactory.cs.ejs @@ -31,7 +31,7 @@ using Microsoft.IdentityModel.JsonWebTokens; namespace <%= namespace %>.Test.Setup { - public class NhipsterWebApplicationFactory : WebApplicationFactory + public class AppWebApplicationFactory : WebApplicationFactory where TEntryPoint : class { private IServiceProvider _serviceProvider; @@ -64,7 +64,7 @@ namespace <%= namespace %>.Test.Setup return _serviceProvider.GetRequiredService(); } - public NhipsterWebApplicationFactory WithMockUser(string name = "user", + public AppWebApplicationFactory WithMockUser(string name = "user", IEnumerable roles = null, string authenticationType = "MockAuthenticationType") { _user = BuildClaimsPrincipal(name, roles, authenticationType); diff --git a/generators/server/templates/dotnetcore/test/Project.Test/Setup/TestStartup.cs.ejs b/generators/server/templates/dotnetcore/test/Project.Test/Setup/TestStartup.cs.ejs index fcf8b4242..943b8dfb8 100644 --- a/generators/server/templates/dotnetcore/test/Project.Test/Setup/TestStartup.cs.ejs +++ b/generators/server/templates/dotnetcore/test/Project.Test/Setup/TestStartup.cs.ejs @@ -32,9 +32,9 @@ namespace <%= namespace %>.Test.Setup } public override void Configure(IApplicationBuilder app, IHostEnvironment env, IServiceProvider serviceProvider, - ApplicationDatabaseContext context, IOptions jhipsterSettingsOptions) + ApplicationDatabaseContext context, IOptions securitySettingsOptions) { - base.Configure(app, env, serviceProvider, context, jhipsterSettingsOptions); + base.Configure(app, env, serviceProvider, context, securitySettingsOptions); } public override void ConfigureServices(IServiceCollection services) diff --git a/test-integration/samples/csharp-di-test/ExtendedServiceRegistrationTest.cs b/test-integration/samples/csharp-di-test/ExtendedServiceRegistrationTest.cs index d899d461b..dee991982 100644 --- a/test-integration/samples/csharp-di-test/ExtendedServiceRegistrationTest.cs +++ b/test-integration/samples/csharp-di-test/ExtendedServiceRegistrationTest.cs @@ -10,12 +10,12 @@ public class ExtendedServiceRegistrationTest { public ExtendedServiceRegistrationTest() { - _factory = new NhipsterWebApplicationFactory().WithMockUser(); + _factory = new AppWebApplicationFactory().WithMockUser(); _countryService = _factory.GetRequiredService(); _departmentService = _factory.GetRequiredService(); } - private readonly NhipsterWebApplicationFactory _factory; + private readonly AppWebApplicationFactory _factory; private readonly ICountryService _countryService; private readonly IDepartmentService _departmentService;