// Path: core/src/main/java/org/pac4j/jax/rs/filters/SecurityFilter.java
// @Priority(Priorities.AUTHENTICATION)
// public class SecurityFilter extends AbstractFilter {
// 
//     private SecurityLogic<Object, JaxRsContext> securityLogic;
// 
//     private String clients;
// 
//     private String authorizers;
// 
//     private String matchers;
// 
//     private Boolean multiProfile;
// 
//     public SecurityFilter(Providers providers) {
//         super(providers);
//     }
// 
//     @Override
//     protected void filter(JaxRsContext context) throws IOException {
// 
//         Config config = getConfig();
// 
//         // Note: basically, there is two possible outcomes:
//         // either the access is granted or there was an error or a redirect!
//         // For the former, we do nothing (see SecurityGrantedAccessOutcome comments)
//         // For the later, we interpret the error and abort the request using jax-rs abstractions
//         buildLogic(config).perform(context, config, new SecurityGrantedAccessOutcome(), adapter(config), clients,
//                 authorizers, matchers, multiProfile);
//     }
// 
//     protected SecurityLogic<Object, JaxRsContext> buildLogic(Config config) {
//         if (securityLogic != null) {
//             return securityLogic;
//         } else if (config.getSecurityLogic() != null) {
//             return config.getSecurityLogic();
//         } else {
//             DefaultSecurityLogic<Object, JaxRsContext> logic = new DefaultSecurityLogic<>();
//             logic.setProfileManagerFactory(ctx -> new JaxRsProfileManager((JaxRsContext) ctx));
//             return logic;
//         }
//     }
// 
//     public String getClients() {
//         return clients;
//     }
// 
//     public void setClients(String clients) {
//         this.clients = clients;
//     }
// 
//     public String getAuthorizers() {
//         return authorizers;
//     }
// 
//     public void setAuthorizers(String authorizers) {
//         this.authorizers = authorizers;
//     }
// 
//     public String getMatchers() {
//         return matchers;
//     }
// 
//     public void setMatchers(String matchers) {
//         this.matchers = matchers;
//     }
// 
//     public boolean getMultiProfile() {
//         return multiProfile;
//     }
// 
//     public void setMultiProfile(Boolean multiProfile) {
//         this.multiProfile = multiProfile;
//     }
// 
//     public SecurityLogic<Object, JaxRsContext> getSecurityLogic() {
//         return securityLogic;
//     }
// 
//     public void setSecurityLogic(SecurityLogic<Object, JaxRsContext> securityLogic) {
//         this.securityLogic = securityLogic;
//     }
// 
//     private static class SecurityGrantedAccessOutcome implements SecurityGrantedAccessAdapter<Object, JaxRsContext> {
//         @Override
//         public Object adapt(JaxRsContext context, Collection<UserProfile> profiles, Object... parameters) {
//             SecurityContext original = context.getRequestContext().getSecurityContext();
//             context.getRequestContext().setSecurityContext(new Pac4JSecurityContext(original, context, profiles));
//             return null;
//         }
//     }
// }


import javax.ws.rs.core.Context;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.ext.Providers;
import org.pac4j.jax.rs.filters.SecurityFilter;
package org.pac4j.jax.rs.features;



/**
 * 
 * Registers a global {@link SecurityFilter} to protect all the URLs served by the JAX-RS runtime.
 * 
 * TODO Normally we would want to register directly {@link SecurityFilter} but because of
 * https://java.net/jira/browse/JERSEY-3167, we can't make it implement {@link Feature}. This is why we need this
 * {@link Feature} in order to handle the injection when we want to register a {@link SecurityFilter} as a global
 * {@link Feature}.
 * 
 * @author Victor Noel - Linagora
 * @since 1.0.0
 *
 */
public class Pac4JSecurityFilterFeature implements Feature {

    @Context
    private Providers providers;

    private final Boolean skipResponse;

    private final String authorizers;

    private final String clients;

    private final String matchers;

    private final Boolean multiProfile;

    public Pac4JSecurityFilterFeature() {
        this(null, null, null, null, null);
    }

    public Pac4JSecurityFilterFeature(Boolean skipResponse, String authorizers, String clients, String matchers,
            Boolean multiProfile) {
        this.skipResponse = skipResponse;
        this.authorizers = authorizers;
        this.clients = clients;
        this.matchers = matchers;
        this.multiProfile = multiProfile;
    }

    @Override
    public boolean configure(FeatureContext context) {
// Path: core/src/main/java/org/pac4j/jax/rs/filters/SecurityFilter.java
// @Priority(Priorities.AUTHENTICATION)
// public class SecurityFilter extends AbstractFilter {
// 
//     private SecurityLogic<Object, JaxRsContext> securityLogic;
// 
//     private String clients;
// 
//     private String authorizers;
// 
//     private String matchers;
// 
//     private Boolean multiProfile;
// 
//     public SecurityFilter(Providers providers) {
//         super(providers);
//     }
// 
//     @Override
//     protected void filter(JaxRsContext context) throws IOException {
// 
//         Config config = getConfig();
// 
//         // Note: basically, there is two possible outcomes:
//         // either the access is granted or there was an error or a redirect!
//         // For the former, we do nothing (see SecurityGrantedAccessOutcome comments)
//         // For the later, we interpret the error and abort the request using jax-rs abstractions
//         buildLogic(config).perform(context, config, new SecurityGrantedAccessOutcome(), adapter(config), clients,
//                 authorizers, matchers, multiProfile);
//     }
// 
//     protected SecurityLogic<Object, JaxRsContext> buildLogic(Config config) {
//         if (securityLogic != null) {
//             return securityLogic;
//         } else if (config.getSecurityLogic() != null) {
//             return config.getSecurityLogic();
//         } else {
//             DefaultSecurityLogic<Object, JaxRsContext> logic = new DefaultSecurityLogic<>();
//             logic.setProfileManagerFactory(ctx -> new JaxRsProfileManager((JaxRsContext) ctx));
//             return logic;
//         }
//     }
// 
//     public String getClients() {
//         return clients;
//     }
// 
//     public void setClients(String clients) {
//         this.clients = clients;
//     }
// 
//     public String getAuthorizers() {
//         return authorizers;
//     }
// 
//     public void setAuthorizers(String authorizers) {
//         this.authorizers = authorizers;
//     }
// 
//     public String getMatchers() {
//         return matchers;
//     }
// 
//     public void setMatchers(String matchers) {
//         this.matchers = matchers;
//     }
// 
//     public boolean getMultiProfile() {
//         return multiProfile;
//     }
// 
//     public void setMultiProfile(Boolean multiProfile) {
//         this.multiProfile = multiProfile;
//     }
// 
//     public SecurityLogic<Object, JaxRsContext> getSecurityLogic() {
//         return securityLogic;
//     }
// 
//     public void setSecurityLogic(SecurityLogic<Object, JaxRsContext> securityLogic) {
//         this.securityLogic = securityLogic;
//     }
// 
//     private static class SecurityGrantedAccessOutcome implements SecurityGrantedAccessAdapter<Object, JaxRsContext> {
//         @Override
//         public Object adapt(JaxRsContext context, Collection<UserProfile> profiles, Object... parameters) {
//             SecurityContext original = context.getRequestContext().getSecurityContext();
//             context.getRequestContext().setSecurityContext(new Pac4JSecurityContext(original, context, profiles));
//             return null;
//         }
//     }
// }


// Path: core/src/main/java/org/pac4j/jax/rs/features/Pac4JSecurityFilterFeature.java
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.ext.Providers;
import org.pac4j.jax.rs.filters.SecurityFilter;

package org.pac4j.jax.rs.features;



/**
 * 
 * Registers a global {@link SecurityFilter} to protect all the URLs served by the JAX-RS runtime.
 * 
 * TODO Normally we would want to register directly {@link SecurityFilter} but because of
 * https://java.net/jira/browse/JERSEY-3167, we can't make it implement {@link Feature}. This is why we need this
 * {@link Feature} in order to handle the injection when we want to register a {@link SecurityFilter} as a global
 * {@link Feature}.
 * 
 * @author Victor Noel - Linagora
 * @since 1.0.0
 *
 */
public class Pac4JSecurityFilterFeature implements Feature {

    @Context
    private Providers providers;

    private final Boolean skipResponse;

    private final String authorizers;

    private final String clients;

    private final String matchers;

    private final Boolean multiProfile;

    public Pac4JSecurityFilterFeature() {
        this(null, null, null, null, null);
    }

    public Pac4JSecurityFilterFeature(Boolean skipResponse, String authorizers, String clients, String matchers,
            Boolean multiProfile) {
        this.skipResponse = skipResponse;
        this.authorizers = authorizers;
        this.clients = clients;
        this.matchers = matchers;
        this.multiProfile = multiProfile;
    }

    @Override
    public boolean configure(FeatureContext context) {
        final SecurityFilter filter = new SecurityFilter(providers);