Return JSON instead of 401 unauthorized page in PAS OE

Posted by christian.bryan@capita.co.uk on 07-Feb-2018 03:46

Hi All 

Is it possible to override the PAS and Spring framework to send back JSON on a 401 unauthorized instead of the default page?

Thanks

Christian.

Posted by knavneet on 07-Feb-2018 04:49

Hi Christian,

If you set Accept header to application/json, I believe you will be returned a json instead of default page.

Thanks,

Navneet

All Replies

Posted by knavneet on 07-Feb-2018 04:49

Hi Christian,

If you set Accept header to application/json, I believe you will be returned a json instead of default page.

Thanks,

Navneet

Posted by brianlafertewk on 07-Feb-2018 07:34

This may not apply, but I'd like to add that if you are accessing the PAS OE instance through IIS using the AJP13 protocol (via BonCode or the Apache AJP13 connector for IIS), you will need to add the following to the <system.webServer> section of the web.config file for the IIS site, to have the JSON pass through to the client.  Otherwise, IIS intercepts the response and replaces the body with it's default error body for the response 'Status Code'.

       <httpErrors existingResponse="PassThrough" />

Posted by christian.bryan@capita.co.uk on 09-Feb-2018 08:57

Thanks for the tip. I have noticed it sends back malformed JSON in OE 11.6.4.

exception_class bwing invalid

e.g.

{ "error_code": 401

, "status_text": "401 - Unauthorized: authentication failed due to bad credentials - GET /web/Catalog/OEAA.Repairs.Params.JobAbandonReasonBusinessEntity"

, "error_details": {"remote_user": "null", "user_principal": "null", "url_scheme": "https", "remote_addr": "127.0.0.1", "server_name": "localhost", "product_type": "dev", "http_status": 401 , "error_detail": "Full authentication is required to access this resource"}

, "debug_details": {  "http_method": "GET", "web_application": "/ROOT", "transport": "OEWebServlet", "request_url": "/web/Catalog/OEAA.Repairs.Params.JobAbandonReasonBusinessEntity", "path_info": "null", "servlet": "OEWebServlet", "uri": "/web/Catalog/OEAA.Repairs.Params.JobAbandonReasonBusinessEntity", "exception_class": "" "exception_message": "", "exception_stack_trace": }

}

This thread is closed