package Ġorg . cloudfoundry . cred hub . auth Ċ Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ import Ġorg . cloudfoundry . cred hub . Error Messages Ċ import Ġorg . cloudfoundry . cred hub . auth . X 5 0 9 Authentication Provider . Companion . CLIENT _ AUTH _ EXT ENDED _ KEY _ USAGE Ċ import Ġorg . cloudfoundry . cred hub . views . ResponseError Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . security . core . Authentication Exception Ċ import Ġorg . springframework . security . web . authentication . Authentication Failure Handler Ċ import Ġorg . springframework . stereotype . Component Ċ import Ġorg . springframework . util . MimeType Utils . APPLICATION _ JSON Ċ import Ġjava . io . IOException Ċ import Ġjavax . servlet . http . HttpServletRequest Ċ import Ġjavax . servlet . http . HttpServletResponse Ċ Ċ @ Component Ċ class ĠX 5 0 9 Authentication Failure Handler Ġ@ Autowired Ċ internal Ġconstructor ( ĊĠĠĠ Ġprivate Ġval ĠobjectMapper : ĠObjectMapper Ċ ) Ġ: ĠAuthentication Failure Handler Ġ{ ĊĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġoverride Ġfun Ġon Authentication Failure ( ĊĠĠĠĠĠĠĠ Ġrequest : ĠHttpServletRequest , ĊĠĠĠĠĠĠĠ Ġresponse : ĠHttpServletResponse , ĊĠĠĠĠĠĠĠ Ġexception : ĠAuthentication Exception ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( exception . message . toString (). contains ( INVALID _ DN _ MESSAGE )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwrite Unauthorized Response ( response , ĠINVALID _ MT LS _ ID _ RESPONSE ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġif Ġ( exception . message . toString (). contains (" Certificate Ġdoes Ġnot Ġcontain : Ġ$ CLIENT _ AUTH _ EXT ENDED _ KEY _ USAGE ")) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwrite Unauthorized Response ( response , ĠINVALID _ CLIENT _ AUTH _ RESPONSE ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġprivate Ġfun Ġwrite Unauthorized Response ( response : ĠHttpServletResponse , Ġmessage : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresponse Error Ġ= ĠResponse Error ( message ) ĊĊĠĠĠĠĠĠĠ Ġresponse . status Ġ= ĠHttpStatus . UN AUTHORIZ ED . value () ĊĠĠĠĠĠĠĠ Ġresponse . contentType Ġ= ĠAP PLICATION _ JSON . type ĊĠĠĠĠĠĠĠ Ġresponse . writer . write ( object Mapper . writeValue AsString ( response Error )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠINVALID _ DN _ MESSAGE Ġ= Ġ" No Ġmatching Ġpattern Ġwas Ġfound Ġin Ġsubject DN " ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠINVALID _ MT LS _ ID _ RESPONSE Ġ= ĠError Messages . Auth . INVALID _ MT LS _ IDENTITY ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠINVALID _ CLIENT _ AUTH _ RESPONSE Ġ= ĠError Messages . Auth . MT LS _ NOT _ CLIENT _ AUTH ĊĠĠĠ Ġ} Ċ } Ċ