// Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsProfileManager.java
// public static class Pac4JSecurityContext implements SecurityContext {
// 
//     private final SecurityContext original;
// 
//     /**
//      * If this is null, it means we are not logged in!
//      */
//     private Principal principal;
// 
//     private final Collection<UserProfile> profiles;
// 
//     private final JaxRsContext context;
// 
//     public Pac4JSecurityContext(SecurityContext original, JaxRsContext context,
//             Collection<UserProfile> profiles) {
//         this.original = original;
//         this.context = context;
//         this.profiles = profiles;
//         this.principal = ProfileHelper.flatIntoOneProfile(profiles).map(Pac4JPrincipal::new).orElse(null);
//     }
// 
//     public Optional<Collection<UserProfile>> getProfiles() {
//         if (principal != null) {
//             return Optional.of(Collections.unmodifiableCollection(profiles));
//         } else if (original instanceof Pac4JSecurityContext) {
//             return ((Pac4JSecurityContext) original).getProfiles();
//         } else {
//             return Optional.empty();
//         }
//     }
// 
//     public JaxRsContext getContext() {
//         // even after logout we can access the context
//         return this.context;
//     }
// 
//     @Override
//     public Principal getUserPrincipal() {
//         if (principal != null) {
//             return principal;
//         } else {
//             return original != null ? original.getUserPrincipal() : null;
//         }
//     }
// 
//     @Override
//     public boolean isUserInRole(String role) {
//         if (principal != null) {
//             return profiles.stream().anyMatch(p -> p.getRoles().contains(role));
//         } else {
//             return original != null && original.isUserInRole(role);
//         }
//     }
// 
//     @Override
//     public boolean isSecure() {
//         return original != null && original.isSecure();
//     }
// 
//     @Override
//     public String getAuthenticationScheme() {
//         if (principal != null) {
//             return "PAC4J";
//         } else {
//             return original != null ? original.getAuthenticationScheme() : null;
//         }
//     }
// }


import java.util.Optional;
import org.pac4j.core.profile.ProfileHelper;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.pac4j.JaxRsProfileManager.Pac4JSecurityContext;
package org.pac4j.jax.rs.helpers;



/**
 * @author Victor Noel
 * @since 2.2.0
 */
public class RequestUserProfile {

    private final RequestPac4JSecurityContext context;

    public RequestUserProfile(RequestPac4JSecurityContext context) {
        this.context = context;
    }

    public Optional<UserProfile> profile() {
        return context.context()
// Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsProfileManager.java
// public static class Pac4JSecurityContext implements SecurityContext {
// 
//     private final SecurityContext original;
// 
//     /**
//      * If this is null, it means we are not logged in!
//      */
//     private Principal principal;
// 
//     private final Collection<UserProfile> profiles;
// 
//     private final JaxRsContext context;
// 
//     public Pac4JSecurityContext(SecurityContext original, JaxRsContext context,
//             Collection<UserProfile> profiles) {
//         this.original = original;
//         this.context = context;
//         this.profiles = profiles;
//         this.principal = ProfileHelper.flatIntoOneProfile(profiles).map(Pac4JPrincipal::new).orElse(null);
//     }
// 
//     public Optional<Collection<UserProfile>> getProfiles() {
//         if (principal != null) {
//             return Optional.of(Collections.unmodifiableCollection(profiles));
//         } else if (original instanceof Pac4JSecurityContext) {
//             return ((Pac4JSecurityContext) original).getProfiles();
//         } else {
//             return Optional.empty();
//         }
//     }
// 
//     public JaxRsContext getContext() {
//         // even after logout we can access the context
//         return this.context;
//     }
// 
//     @Override
//     public Principal getUserPrincipal() {
//         if (principal != null) {
//             return principal;
//         } else {
//             return original != null ? original.getUserPrincipal() : null;
//         }
//     }
// 
//     @Override
//     public boolean isUserInRole(String role) {
//         if (principal != null) {
//             return profiles.stream().anyMatch(p -> p.getRoles().contains(role));
//         } else {
//             return original != null && original.isUserInRole(role);
//         }
//     }
// 
//     @Override
//     public boolean isSecure() {
//         return original != null && original.isSecure();
//     }
// 
//     @Override
//     public String getAuthenticationScheme() {
//         if (principal != null) {
//             return "PAC4J";
//         } else {
//             return original != null ? original.getAuthenticationScheme() : null;
//         }
//     }
// }


// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
import java.util.Optional;
import org.pac4j.core.profile.ProfileHelper;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.pac4j.JaxRsProfileManager.Pac4JSecurityContext;

package org.pac4j.jax.rs.helpers;



/**
 * @author Victor Noel
 * @since 2.2.0
 */
public class RequestUserProfile {

    private final RequestPac4JSecurityContext context;

    public RequestUserProfile(RequestPac4JSecurityContext context) {
        this.context = context;
    }

    public Optional<UserProfile> profile() {
        return context.context()
                .flatMap(Pac4JSecurityContext::getProfiles)