@@ -92,6 +92,7 @@ typedef struct AuthResponse_tag {
92
92
union {
93
93
SAFAuthStatus safStatus ;
94
94
} responseDetails ;
95
+ bool authDataFound ;
95
96
} AuthResponse ;
96
97
97
98
/* FIX THIS: a temporary "low profile" way of hiding printfs. Improves
@@ -2485,6 +2486,7 @@ static int safAuthenticate(HttpService *service, HttpRequest *request, AuthRespo
2485
2486
2486
2487
authResponse -> type = AUTH_TYPE_RACF ;
2487
2488
authResponse -> responseDetails .safStatus = status .safStatus ;
2489
+ authResponse -> authDataFound = (bool )authDataFound ;
2488
2490
2489
2491
if (pwdCheckRC != 0 ) {
2490
2492
#ifdef DEBUG_AUTH
@@ -2868,7 +2870,7 @@ static int serviceAuthNativeWithSessionToken(HttpService *service, HttpRequest *
2868
2870
response -> sessionCookie = NULL ;
2869
2871
2870
2872
AUTH_TRACE ("AUTH: tokenCookieText: %s\n" ,(tokenCookieText ? tokenCookieText : "<noAuthToken>" ));
2871
-
2873
+ authResponse -> authDataFound = authDataFound || ( tokenCookieText != NULL );
2872
2874
if (tokenCookieText ){
2873
2875
zowelog (NULL , LOG_COMP_HTTPSERVER , ZOWE_LOG_DEBUG3 ,
2874
2876
"serviceAuthNativeWithSessionToken: tokenCookieText: %s\n" ,
@@ -2933,7 +2935,8 @@ static int serviceAuthNativeWithSessionToken(HttpService *service, HttpRequest *
2933
2935
2934
2936
static int serviceAuthWithJwt (HttpService * service ,
2935
2937
HttpRequest * request ,
2936
- HttpResponse * response ) {
2938
+ HttpResponse * response ,
2939
+ AuthResponse * authResponse ) {
2937
2940
HttpHeader * const authorizationHeader = getHeader (request , "Authorization" );
2938
2941
char * jwtTokenText = getCookieValue (request ,JWT_COOKIE_NAME );
2939
2942
@@ -2971,6 +2974,7 @@ static int serviceAuthWithJwt(HttpService *service,
2971
2974
if (request -> authToken == NULL ) {
2972
2975
return FALSE;
2973
2976
}
2977
+ authResponse -> authDataFound = TRUE;
2974
2978
2975
2979
JwtContext * const jwtContext = service -> server -> config -> jwtContext ;
2976
2980
if (jwtContext == NULL ) {
@@ -3232,12 +3236,12 @@ static int handleHttpService(HttpServer *server,
3232
3236
3233
3237
int clearSessionToken = FALSE;
3234
3238
3235
- AuthResponse authResponse ;
3239
+ AuthResponse authResponse = { 0 } ;
3236
3240
3237
3241
switch (service -> authType ){
3238
3242
3239
3243
case SERVICE_AUTH_NONE :
3240
- request -> authenticated = TRUE ;
3244
+ request -> authenticated = FALSE ;
3241
3245
break ;
3242
3246
case SERVICE_AUTH_SAF :
3243
3247
/* SAF Authentication just checks that user is known at ALL to SAF.
@@ -3259,7 +3263,7 @@ static int handleHttpService(HttpServer *server,
3259
3263
switch (server -> config -> authTokenType ) {
3260
3264
case SERVICE_AUTH_TOKEN_TYPE_JWT :
3261
3265
case SERVICE_AUTH_TOKEN_TYPE_JWT_WITH_LEGACY_FALLBACK :
3262
- request -> authenticated = serviceAuthWithJwt (service , request , response );
3266
+ request -> authenticated = serviceAuthWithJwt (service , request , response , & authResponse );
3263
3267
3264
3268
if (request -> authenticated ||
3265
3269
service -> server -> config -> authTokenType
@@ -3275,9 +3279,18 @@ static int handleHttpService(HttpServer *server,
3275
3279
#ifdef DEBUG
3276
3280
printf ("service=%s authenticated=%d\n" ,service -> name ,request -> authenticated );
3277
3281
#endif
3282
+ bool isAuthOptional = service -> authFlags & SERVICE_AUTH_FLAG_OPTIONAL ;
3283
+ bool allowUnauthenticated = (service -> authType == SERVICE_AUTH_NONE ) ||
3284
+ (isAuthOptional && !authResponse .authDataFound );
3285
+ AUTH_TRACE ("authType %d, authenticated %s, authFlagOptional %s, authDataFound %s, allowUnauthenticated %s\n" ,
3286
+ service -> authType ,
3287
+ request -> authenticated ? "true" : "false" ,
3288
+ isAuthOptional ? "true" : "false" ,
3289
+ authResponse .authDataFound ? "true" : "false" ,
3290
+ allowUnauthenticated ? "true" : "false"
3291
+ );
3278
3292
if (request -> authenticated == FALSE){
3279
- if (service -> authFlags & SERVICE_AUTH_FLAG_OPTIONAL ) {
3280
- // Allow the service to decide when to respond with HTTP 401
3293
+ if (allowUnauthenticated ) {
3281
3294
serveRequest (service , response , request );
3282
3295
} else {
3283
3296
respondWithAuthError (response , & authResponse );
0 commit comments