Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit 566388d

Browse files
committed
ASP.NET Core 3.1
1 parent cdeeac6 commit 566388d

20 files changed

Lines changed: 225 additions & 72 deletions

build/build.bat

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11

22
echo Restore nuget dep's
3-
dotnet build "../src/Backend/JPProject.Admin.Api"
3+
dotnet build "../src/Backend/Jp.UserManagement"
4+
dotnet build "../src/Frontend/Jp.UI.SSO"
5+
6+
CLS
7+
echo Build UserManagement
8+
start /d "../src/Frontend/Jp.UserManagement" npm install
49

510
echo Build AdminUi
611
start /d "../src/Frontend/Jp.AdminUI" npm install

build/docker-compose.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
version: "3"
2+
3+
services:
4+
5+
#############################
6+
# Database
7+
#############################
8+
jpdatabase:
9+
image: mysql
10+
container_name: jp-internal-db
11+
command: --default-authentication-plugin=mysql_native_password
12+
restart: always
13+
environment:
14+
MYSQL_ROOT_PASSWORD: root
15+
MYSQL_USER: jp
16+
MYSQL_DATABASE: jpproject
17+
MYSQL_PASSWORD: 10203040
18+
19+
#############################
20+
# Server SSO
21+
#############################
22+
jpproject-sso:
23+
image: bhdebrito/jpproject-sso:3.1.0
24+
container_name: jpproject-sso
25+
depends_on:
26+
- jpdatabase
27+
environment:
28+
ASPNETCORE_ENVIRONMENT: Development
29+
ASPNETCORE_URLS: http://+:5001
30+
CUSTOMCONNSTR_SSOConnection: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
31+
ApplicationSettings:EnableExternalProviders: "false" # Because Auth url is http://jpproject (modified by host to point to 127.0.0.1), then Google and Facebook reject it.
32+
ApplicationSettings:DatabaseType: MySql
33+
ApplicationSettings:DefaultUser: bruno
34+
ApplicationSettings:DefaultPass: Pa$$word123
35+
ApplicationSettings:DefaultEmail: bhdebrito@gmail.com
36+
ApplicationSettings:UserManagementURL: http://localhost:4200
37+
ApplicationSettings:IS4AdminUi: http://localhost:4300
38+
ApplicationSettings:ResourceServerURL: http://localhost:5002
39+
CertificateOptions:Type: Temporary
40+
41+
#############################
42+
# Management API
43+
#############################
44+
jpproject-api:
45+
image: bhdebrito/jpproject-api:3.1.0
46+
container_name: jpproject-api
47+
depends_on:
48+
- jpdatabase
49+
environment:
50+
ASPNETCORE_ENVIRONMENT: "Development"
51+
ASPNETCORE_URLS: http://+
52+
CUSTOMCONNSTR_SSOConnection: "server=jpdatabase,port=3306;database=jpproject;user=jp;password=10203040"
53+
ApplicationSettings:Authority: "http://jpproject-sso:5001"
54+
ApplicationSettings:DatabaseType: MySql
55+
56+
#############################
57+
# User management UI
58+
#############################
59+
jpproject-users:
60+
image: bhdebrito/jpproject-user-management-ui:3.0.2
61+
container_name: jpproject-users
62+
depends_on:
63+
- jpproject-api
64+
- jpproject-sso
65+
66+
#############################
67+
# Admin Ui
68+
#############################
69+
jpproject-admin-ui:
70+
image: bhdebrito/jpproject-admin-ui:3.0.2
71+
container_name: jpproject-admin-ui
72+
depends_on:
73+
- jpproject-api
74+
- jpproject-sso
75+
76+
77+
#############################
78+
# Reverse proxy
79+
#############################
80+
reverse-proxy:
81+
image: bhdebrito/jpproject-reverse-proxy:3.1.0
82+
container_name: jpproject-reverse-proxy
83+
ports:
84+
- '5001:5001'
85+
- '5002:5002'
86+
- '4200:4200'
87+
- '4300:4300'
88+
depends_on:
89+
- 'jpproject-api'
90+
- 'jpproject-users'
91+
- 'jpproject-sso'
92+
- 'jpproject-admin-ui'

build/jpproject-docker-windows.zip

-1.59 KB
Binary file not shown.

build/jpproject-docker.zip

1.68 KB
Binary file not shown.

build/update-host.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ ECHO.
55

66
SET NEWLINE=^& echo.
77
ECHO Carrying out requested modifications to your HOSTS file
8-
FIND /C /I "jpproject" %WINDIR%\system32\drivers\etc\hosts
8+
FIND /C /I "jpproject-sso" %WINDIR%\system32\drivers\etc\hosts
99
IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%>>%WINDIR%\system32\drivers\etc\hosts
10-
IF %ERRORLEVEL% NEQ 0 ECHO 127.0.0.1 jpproject>>%WINDIR%\system32\drivers\etc\hosts
10+
IF %ERRORLEVEL% NEQ 0 ECHO 127.0.0.1 jpproject-sso>>%WINDIR%\system32\drivers\etc\hosts
1111
ECHO Finished
1212
ECHO.
1313
EXIT
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
3+
namespace JPProject.Admin.Api.Configuration.Authorization
4+
{
5+
public class AccountRequirement : IAuthorizationRequirement
6+
{
7+
}
8+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Http;
3+
using System;
4+
using System.Threading.Tasks;
5+
6+
namespace JPProject.Admin.Api.Configuration.Authorization
7+
{
8+
public class AccountRequirementHandler : AuthorizationHandler<AccountRequirement>
9+
{
10+
private readonly IHttpContextAccessor _httpContextAccessor;
11+
12+
public AccountRequirementHandler(IHttpContextAccessor httpContextAccessor)
13+
{
14+
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
15+
}
16+
protected override Task HandleRequirementAsync(
17+
AuthorizationHandlerContext context,
18+
AccountRequirement requirement)
19+
{
20+
21+
var httpMethod = _httpContextAccessor.HttpContext.Request.Method;
22+
23+
if (HttpMethods.IsGet(httpMethod) || HttpMethods.IsHead(httpMethod))
24+
{
25+
if (context.User.Identity.IsAuthenticated)
26+
{
27+
context.Succeed(requirement);
28+
return Task.CompletedTask;
29+
}
30+
}
31+
else
32+
{
33+
if (context.User.HasClaim("is4-rights", "manager") ||
34+
context.User.IsInRole("Administrator"))
35+
{
36+
context.Succeed(requirement);
37+
return Task.CompletedTask;
38+
}
39+
}
40+
context.Fail();
41+
return Task.CompletedTask;
42+
}
43+
}
44+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
namespace JPProject.Admin.Api.Configuration.Authorization
5+
{
6+
public static class ConfigurePolicy
7+
{
8+
public static void AddPolicies(this IServiceCollection services)
9+
{
10+
services.AddAuthorization(options =>
11+
{
12+
options.AddPolicy("Default",
13+
policy => policy.Requirements.Add(new AccountRequirement()));
14+
});
15+
services.AddSingleton<IAuthorizationHandler, AccountRequirementHandler>();
16+
}
17+
}
18+
}

src/Backend/JPProject.Admin.Api/Configuration/ConfigurePolicy.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Backend/JPProject.Admin.Api/Controllers/ApiResourceController.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace JPProject.Admin.Api.Controllers
1515
{
16-
[Route("api-resources"), Authorize(Policy = "ReadOnly")]
16+
[Route("api-resources"), Authorize(Policy = "Default")]
1717
public class ApiResourcesController : ApiController
1818
{
1919
private readonly IApiResourceAppService _apiResourceAppService;
@@ -40,7 +40,7 @@ public async Task<ActionResult<ApiResource>> Details(string resource)
4040
return ResponseGet(irs);
4141
}
4242

43-
[HttpPost(""), Authorize(Policy = "Admin")]
43+
[HttpPost("")]
4444
public async Task<ActionResult<ApiResource>> Save([FromBody] ApiResource model)
4545
{
4646
if (!ModelState.IsValid)
@@ -54,7 +54,7 @@ public async Task<ActionResult<ApiResource>> Save([FromBody] ApiResource model)
5454
return ResponsePost(nameof(Details), new { resource = model.Name }, apires);
5555
}
5656

57-
[HttpPut("{resource}"), Authorize(Policy = "Admin")]
57+
[HttpPut("{resource}")]
5858
public async Task<ActionResult<bool>> Update(string resource, [FromBody] ApiResource model)
5959
{
6060
if (!ModelState.IsValid)
@@ -67,7 +67,7 @@ public async Task<ActionResult<bool>> Update(string resource, [FromBody] ApiReso
6767
return ResponsePutPatch();
6868
}
6969

70-
[HttpPatch("{resource}"), Authorize(Policy = "Admin")]
70+
[HttpPatch("{resource}")]
7171
public async Task<ActionResult<bool>> PartialUpdate(string resource, [FromBody] JsonPatchDocument<ApiResource> model)
7272
{
7373
if (!ModelState.IsValid)
@@ -87,7 +87,7 @@ public async Task<ActionResult<bool>> PartialUpdate(string resource, [FromBody]
8787
return ResponsePutPatch();
8888
}
8989

90-
[HttpDelete("{resource}"), Authorize(Policy = "Admin")]
90+
[HttpDelete("{resource}")]
9191
public async Task<ActionResult<bool>> Remove(string resource)
9292
{
9393
var model = new RemoveApiResourceViewModel(resource);
@@ -102,7 +102,7 @@ public async Task<ActionResult<IEnumerable<SecretViewModel>>> Secrets(string res
102102
return ResponseGet(clients);
103103
}
104104

105-
[HttpDelete("{resource}/secrets/{secretId:int}"), Authorize(Policy = "Admin")]
105+
[HttpDelete("{resource}/secrets/{secretId:int}")]
106106
public async Task<ActionResult<bool>> RemoveSecret(string resource, int secretId)
107107
{
108108
var model = new RemoveApiSecretViewModel(resource, secretId);
@@ -111,7 +111,7 @@ public async Task<ActionResult<bool>> RemoveSecret(string resource, int secretId
111111
}
112112

113113

114-
[HttpPost("{resource}/secrets"), Authorize(Policy = "Admin")]
114+
[HttpPost("{resource}/secrets")]
115115
public async Task<ActionResult<IEnumerable<SecretViewModel>>> SaveSecret(string resource, [FromBody] SaveApiSecretViewModel model)
116116
{
117117
if (!ModelState.IsValid)
@@ -133,7 +133,7 @@ public async Task<ActionResult<IEnumerable<ScopeViewModel>>> Scopes(string resou
133133
return ResponseGet(clients);
134134
}
135135

136-
[HttpDelete("{resource}/scopes/{scopeId:int}"), Authorize(Policy = "Admin")]
136+
[HttpDelete("{resource}/scopes/{scopeId:int}")]
137137
public async Task<ActionResult> RemoveScope(string resource, int scopeId)
138138
{
139139
var model = new RemoveApiScopeViewModel(resource, scopeId);
@@ -142,7 +142,7 @@ public async Task<ActionResult> RemoveScope(string resource, int scopeId)
142142
}
143143

144144

145-
[HttpPost("{resource}/scopes"), Authorize(Policy = "Admin")]
145+
[HttpPost("{resource}/scopes")]
146146
public async Task<ActionResult<IEnumerable<ScopeViewModel>>> SaveScope(string resource, [FromBody] SaveApiScopeViewModel model)
147147
{
148148
if (!ModelState.IsValid)

0 commit comments

Comments
 (0)