@@ -31,6 +31,7 @@ public Startup(IHostingEnvironment env, IConfiguration configuration)
3131
3232 public void ConfigureServices ( IServiceCollection services )
3333 {
34+ var files = Directory . EnumerateFiles ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "Cmmns" ) , "*.cmmn" ) . ToList ( ) ;
3435 services . AddMvc ( opts => opts . EnableEndpointRouting = false ) . AddNewtonsoftJson ( ) ;
3536 services . AddAuthentication ( options =>
3637 {
@@ -53,7 +54,23 @@ public void ConfigureServices(IServiceCollection services)
5354 "http://simpleidserver.northeurope.cloudapp.azure.com/openid"
5455 }
5556 } ;
56- } ) ;
57+ } )
58+ . AddJwtBearer ( "OAuthScheme" , options =>
59+ {
60+ options . TokenValidationParameters = new TokenValidationParameters
61+ {
62+ IssuerSigningKey = ExtractKey ( "oauth_puk.txt" ) ,
63+ ValidAudiences = new List < string >
64+ {
65+ "humanTaskClient"
66+ } ,
67+ ValidIssuers = new List < string >
68+ {
69+ "http://localhost:60001" ,
70+ "http://simpleidserver.northeurope.cloudapp.azure.com/oauth"
71+ }
72+ } ;
73+ } ) ; ;
5774 services . AddAuthorization ( policy =>
5875 {
5976 // Case file
@@ -73,7 +90,31 @@ public void ConfigureServices(IServiceCollection services)
7390 policy . AddPolicy ( "resume_caseplaninstance" , p => p . RequireAuthenticatedUser ( ) ) ;
7491 policy . AddPolicy ( "terminate_caseplaninstance" , p => p . RequireAuthenticatedUser ( ) ) ;
7592 policy . AddPolicy ( "activate_caseplaninstance" , p => p . RequireAuthenticatedUser ( ) ) ;
76- policy . AddPolicy ( "complete_caseplaninstance" , p => p . RequireAuthenticatedUser ( ) ) ;
93+ policy . AddPolicy ( "complete_caseplaninstance" , p =>
94+ {
95+ p . AddAuthenticationSchemes ( "OAuthScheme" ) ;
96+ p . RequireAssertion ( _ =>
97+ {
98+ if ( _ . User == null || _ . User . Claims == null || ! _ . User . Claims . Any ( ) )
99+ {
100+ return false ;
101+ }
102+
103+ var cl = _ . User . Claims . FirstOrDefault ( _ => _ . Type == "scope" && _ . Value == "complete_humantask" ) ;
104+ if ( cl != null )
105+ {
106+ return true ;
107+ }
108+
109+ cl = _ . User . Claims . FirstOrDefault ( _ => _ . Type == "sub" ) ;
110+ if ( cl != null )
111+ {
112+ return true ;
113+ }
114+
115+ return false ;
116+ } ) ;
117+ } ) ;
77118 // Case plan
78119 policy . AddPolicy ( "get_caseplan" , p => p . RequireAuthenticatedUser ( ) ) ;
79120 // Case worker task
@@ -84,7 +125,11 @@ public void ConfigureServices(IServiceCollection services)
84125 . AllowAnyHeader ( ) ) ) ;
85126 services . AddHostedService < CMMNJobServerHostedService > ( ) ;
86127 services . AddCaseApi ( ) ;
87- services . AddCaseJobServer ( ) ;
128+ services . AddCaseJobServer ( callback : opt =>
129+ {
130+ opt . CallbackUrl = "http://localhost:60005/case-plan-instances/{id}/complete/{eltId}" ;
131+ opt . WSHumanTaskAPI = "http://localhost:60006" ;
132+ } ) . AddDefinitions ( files ) ;
88133 services . AddSwaggerGen ( ) ;
89134 services . Configure < ForwardedHeadersOptions > ( options =>
90135 {
0 commit comments