# Logging of the Authentication mechanism in PAYARA

**URL:** https://forum.payara.fish/t/logging-of-the-authentication-mechanism-in-payara/148
**Category:** Technical Discussion
**Created:** [November 29, 2021, 4:44pm UTC](https://forum.payara.fish/t/logging-of-the-authentication-mechanism-in-payara/148 "2021-11-29T16:44:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zied](https://avatars.discourse-cdn.com/v4/letter/z/7ea924/32.png) [@zied](https://forum.payara.fish/u/zied)
#### Post date: [November 29, 2021, 4:44pm UTC](https://forum.payara.fish/t/logging-of-the-authentication-mechanism-in-payara/148/1 "2021-11-29T16:44:43Z")

</div>

Hi everyone,  
im using Payara Server 5.2020.4 and i want to log the Authentication mecanisme from Payara.  
im Using JWT and REST. i want to log the user and his Role when the Authentication failed.  
how can i do this?

---

<div class="post-metadata">

### Author: ![pdudits](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.payara.fish/pdudits/32/49_2.png) [@pdudits](https://forum.payara.fish/u/pdudits)
#### Post date: [December 9, 2021, 10:06am UTC](https://forum.payara.fish/t/logging-of-the-authentication-mechanism-in-payara/148/2 "2021-12-09T10:06:24Z")

</div>

From top of my head (and copying from more general handler), I suppose you could add an ExceptionMapper for `ForbiddenException`:

```auto
public class AuthFailedHandler implements ExceptionMapper<ForbiddenException> {

    @Context
    HttpServletRequest request;

    @Override
    public Response toResponse(ForbiddenException exception) {
       // check request principal here
      return exception.getResponse();
    }
}

```

You can check the caller principal and check his roles from the request. Don’t forget to include it in your application by including it in `Set` of `Application`'s classes or annoating it `@Provider`.
