// Path: keycloak-dropwizard/src/main/java/de/ahus1/keycloak/dropwizard/User.java
// public class User extends AbstractUser {
// 
//     public User(KeycloakSecurityContext securityContext, HttpServletRequest request,
//                 KeycloakConfiguration keycloakConfiguration) {
//         super(request, securityContext, keycloakConfiguration);
//     }
// 
//     public void checkUserInRole(String role) {
//         if (!getRoles().contains(role)) {
//             throw new ForbiddenException();
//         }
//     }
// 
//     @Override
//     public String getName() {
//         return securityContext.getToken().getName();
//     }
// 
// }


import de.ahus1.keycloak.dropwizard.User;
import io.dropwizard.auth.Auth;
import javax.annotation.security.RolesAllowed;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.*;
package de.ahus1.lottery.adapter.dropwizard.resource;



/**
 * Ressourcce to show the name of the user ("Who am I").
 * This is a simple resource that offers a GET request to test the redirect on accessing a protected resource.
 * This will work only in non-bearer-only mode.
 */
@Path("/")
@Produces(MediaType.TEXT_HTML)
public class WhoamiRessource {

    private final boolean logoutShouldRemoveCookie;

    public WhoamiRessource(boolean logoutShouldRemoveCookie) {
        this.logoutShouldRemoveCookie = logoutShouldRemoveCookie;
    }

    @Context
    private HttpServletRequest request;

    @GET
    @Path("/whoami")
    @RolesAllowed("user")
    public WhoamiView whoami(@Auth User user) {
        WhoamiBean whoami = new WhoamiBean();
        whoami.setName(user.getName());
        return new WhoamiView(whoami);
    }

    @GET
    @Path("/logout")
// Path: keycloak-dropwizard/src/main/java/de/ahus1/keycloak/dropwizard/User.java
// public class User extends AbstractUser {
// 
//     public User(KeycloakSecurityContext securityContext, HttpServletRequest request,
//                 KeycloakConfiguration keycloakConfiguration) {
//         super(request, securityContext, keycloakConfiguration);
//     }
// 
//     public void checkUserInRole(String role) {
//         if (!getRoles().contains(role)) {
//             throw new ForbiddenException();
//         }
//     }
// 
//     @Override
//     public String getName() {
//         return securityContext.getToken().getName();
//     }
// 
// }


// Path: keycloak-dropwizard-bearermodule/src/main/java/de/ahus1/lottery/adapter/dropwizard/resource/WhoamiRessource.java
import de.ahus1.keycloak.dropwizard.User;
import io.dropwizard.auth.Auth;
import javax.annotation.security.RolesAllowed;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.*;

package de.ahus1.lottery.adapter.dropwizard.resource;



/**
 * Ressourcce to show the name of the user ("Who am I").
 * This is a simple resource that offers a GET request to test the redirect on accessing a protected resource.
 * This will work only in non-bearer-only mode.
 */
@Path("/")
@Produces(MediaType.TEXT_HTML)
public class WhoamiRessource {

    private final boolean logoutShouldRemoveCookie;

    public WhoamiRessource(boolean logoutShouldRemoveCookie) {
        this.logoutShouldRemoveCookie = logoutShouldRemoveCookie;
    }

    @Context
    private HttpServletRequest request;

    @GET
    @Path("/whoami")
    @RolesAllowed("user")
    public WhoamiView whoami(@Auth User user) {
        WhoamiBean whoami = new WhoamiBean();
        whoami.setName(user.getName());
        return new WhoamiView(whoami);
    }

    @GET
    @Path("/logout")
    public Response logout(@Context SecurityContext context) throws ServletException {