@@ -448,8 +448,6 @@ static apr_byte_t oidc_authz_skip_to_content_handler(request_rec *r) {
448448 return FALSE;
449449}
450450
451- #if HAVE_APACHE_24
452-
453451/*
454452 * Apache >=2.4 authorization routine: match the claims from the authenticated user against the Require primitive
455453 */
@@ -635,192 +633,3 @@ authz_status oidc_authz_24_checker_claims_expr(request_rec *r, const char *requi
635633 return oidc_authz_24_checker (r , require_args , parsed_require_args , oidc_authz_match_claims_expr );
636634}
637635#endif
638-
639- #else
640-
641- /*
642- * Apache <2.4 authorization routine: match the claims from the authenticated user against the Require primitive
643- */
644- static int oidc_authz_22_worker (request_rec * r , json_t * claims , const require_line * const reqs , int nelts ) {
645- const int m = r -> method_number ;
646- const char * token ;
647- const char * requirement ;
648- int i ;
649- int have_oauthattr = 0 ;
650- int count_oauth_claims = 0 ;
651- oidc_authz_match_claim_fn_type match_claim_fn = NULL ;
652-
653- /* go through applicable Require directives */
654- for (i = 0 ; i < nelts ; ++ i ) {
655-
656- /* ignore this Require if it's in a <Limit> section that exclude this method */
657- if (!(reqs [i ].method_mask & (AP_METHOD_BIT << m ))) {
658- continue ;
659- }
660-
661- /* ignore if it's not a "Require claim ..." */
662- requirement = reqs [i ].requirement ;
663-
664- token = ap_getword_white (r -> pool , & requirement );
665-
666- /* see if we've got anything meant for us */
667- if (_oidc_strnatcasecmp (token , OIDC_REQUIRE_CLAIM_NAME ) == 0 ) {
668- match_claim_fn = oidc_authz_match_claim ;
669- #ifdef USE_LIBJQ
670- } else if (_oidc_strnatcasecmp (token , OIDC_REQUIRE_CLAIMS_EXPR_NAME ) == 0 ) {
671- match_claim_fn = oidc_authz_match_claims_expr ;
672- #endif
673- } else {
674- continue ;
675- }
676-
677- /* ok, we have a "Require claim/claims_expr" to satisfy */
678- have_oauthattr = 1 ;
679-
680- /*
681- * If we have an applicable claim, but no claims were sent in the request, then we can
682- * just stop looking here, because it's not satisfiable. The code after this loop will
683- * give the appropriate response.
684- */
685- if (!claims ) {
686- break ;
687- }
688-
689- /*
690- * iterate over the claim specification strings in this require directive searching
691- * for a specification that matches one of the claims/expressions.
692- */
693- while (* requirement ) {
694- token = ap_getword_conf (r -> pool , & requirement );
695- count_oauth_claims ++ ;
696-
697- oidc_debug (r , "evaluating claim/expr specification: %s" , token );
698-
699- if (match_claim_fn (r , token , claims ) == TRUE) {
700-
701- /* if *any* claim matches, then authorization has succeeded and all of the others are
702- * ignored */
703- oidc_debug (r , "require claim/expr '%s' matched" , token );
704- return OK ;
705- }
706- }
707-
708- oidc_authz_error_add (r , requirement );
709- }
710-
711- /* if there weren't any "Require claim" directives, we're irrelevant */
712- if (!have_oauthattr ) {
713- oidc_debug (r , "no claim/expr statements found, not performing authz" );
714- return DECLINED ;
715- }
716- /* if there was a "Require claim", but no actual claims, that's cause to warn the admin of an iffy configuration
717- */
718- if (count_oauth_claims == 0 ) {
719- oidc_warn (r , "'require claim/expr' missing specification(s) in configuration, declining" );
720- return DECLINED ;
721- }
722-
723- /* log the event, also in Apache speak */
724- oidc_debug (r , "authorization denied for require claims (0/%d): '%s'" , nelts ,
725- nelts > 0 ? reqs [0 ].requirement : "(none)" );
726-
727- ap_note_auth_failure (r );
728-
729- return HTTP_UNAUTHORIZED ;
730- }
731-
732- /*
733- * find out which action we need to take when encountering an unauthorized request
734- */
735- static int oidc_authz_22_unauthorized_user (request_rec * r ) {
736-
737- oidc_cfg_t * c = ap_get_module_config (r -> server -> module_config , & auth_openidc_module );
738-
739- if (_oidc_strnatcasecmp ((const char * )ap_auth_type (r ), OIDC_AUTH_TYPE_OPENID_OAUTH20 ) == 0 ) {
740- OIDC_METRICS_COUNTER_INC (r , c , OM_AUTHZ_ERROR_OAUTH20 );
741- oidc_proto_return_www_authenticate (r , "insufficient_scope" ,
742- "Different scope(s) or other claims required" );
743- return HTTP_UNAUTHORIZED ;
744- }
745-
746- /* see if we've configured OIDCUnAutzAction for this path */
747- switch (oidc_cfg_dir_unautz_action_get (r )) {
748- case OIDC_UNAUTZ_RETURN403 :
749- OIDC_METRICS_COUNTER_INC (r , c , OM_AUTHZ_ACTION_403 );
750- if (oidc_cfg_dir_unauthz_arg_get (r ))
751- oidc_util_html_send (r , "Authorization Error" , NULL , NULL , oidc_cfg_dir_unauthz_arg_get (r ),
752- HTTP_FORBIDDEN );
753- return HTTP_FORBIDDEN ;
754- case OIDC_UNAUTZ_RETURN401 :
755- OIDC_METRICS_COUNTER_INC (r , c , OM_AUTHZ_ACTION_401 );
756- if (oidc_cfg_dir_unauthz_arg_get (r ))
757- oidc_util_html_send (r , "Authorization Error" , NULL , NULL , oidc_cfg_dir_unauthz_arg_get (r ),
758- HTTP_UNAUTHORIZED );
759- return HTTP_UNAUTHORIZED ;
760- case OIDC_UNAUTZ_RETURN302 :
761- OIDC_METRICS_COUNTER_INC (r , c , OM_AUTHZ_ACTION_302 );
762- oidc_http_hdr_out_location_set (r , oidc_cfg_dir_unauthz_arg_get (r ));
763- return HTTP_MOVED_TEMPORARILY ;
764- case OIDC_UNAUTZ_AUTHENTICATE :
765- /*
766- * exception handling: if this looks like a XMLHttpRequest call we
767- * won't redirect the user and thus avoid creating a state cookie
768- * for a non-browser (= Javascript) call that will never return from the OP
769- */
770- if (oidc_is_auth_capable_request (r ) == FALSE) {
771- OIDC_METRICS_COUNTER_INC (r , c , OM_AUTHZ_ACTION_401 );
772- return HTTP_UNAUTHORIZED ;
773- }
774-
775- OIDC_METRICS_COUNTER_INC (r , c , OM_AUTHZ_ACTION_AUTH );
776- }
777-
778- return oidc_request_authenticate_user (r , c , NULL , oidc_util_url_cur (r , oidc_cfg_x_forwarded_headers_get (c )),
779- NULL , NULL , NULL , oidc_cfg_dir_path_auth_request_params_get (r ),
780- oidc_cfg_dir_path_scope_get (r ));
781- }
782-
783- /*
784- * generic Apache <2.4 authorization hook for this module
785- * handles both OpenID Connect and OAuth 2.0 in the same way, based on the claims stored in the request context
786- */
787- int oidc_authz_22_checker (request_rec * r ) {
788-
789- /* check for anonymous access and PASS mode */
790- if ((r -> user != NULL ) && (_oidc_strlen (r -> user ) == 0 )) {
791- r -> user = NULL ;
792- if (oidc_cfg_dir_unauth_action_get (r ) == OIDC_UNAUTH_PASS )
793- return OK ;
794- if (oidc_authz_skip_to_content_handler (r ) == TRUE)
795- return OK ;
796- if (r -> method_number == M_OPTIONS )
797- return OK ;
798- }
799-
800- /* get the set of claims from the request state (they've been set in the authentication part earlier */
801- json_t * claims = oidc_authz_merge_claims (r );
802-
803- /* get the Require statements */
804- const apr_array_header_t * const reqs_arr = ap_requires (r );
805-
806- /* see if we have any */
807- const require_line * const reqs = reqs_arr ? (require_line * )reqs_arr -> elts : NULL ;
808- if (!reqs_arr ) {
809- oidc_debug (r , "no require statements found, so declining to perform authorization." );
810- return DECLINED ;
811- }
812-
813- /* dispatch to the <2.4 specific authz routine */
814- int rc = oidc_authz_22_worker (r , claims , reqs , reqs_arr -> nelts );
815-
816- /* cleanup */
817- if (claims )
818- json_decref (claims );
819-
820- if ((rc == HTTP_UNAUTHORIZED ) && ap_auth_type (r ))
821- rc = oidc_authz_22_unauthorized_user (r );
822-
823- return rc ;
824- }
825-
826- #endif
0 commit comments