// Path: src/main/java/gluu/scim2/client/ClientMap.java
// public class ClientMap {
// 
//     private static ClientMap map = new ClientMap();
// 
//     private static Map<Client, String> mappings = new HashMap<>();
// 
//     private ClientMap() {
//     }
// 
//     /**
//      * Puts a new client/value pair in the map. If client already exists, the value is replaced.
//      *
//      * @param client RestEasy client
//      * @param value  Value to associate to this client - normally an access token
//      */
//     public static void update(Client client, String value) {
//         mappings.put(client, value);
//     }
// 
//     /**
//      * Removes a client from the map and then calls its close method to free resources.
//      *
//      * @param client Client to remove
//      */
//     public static void remove(Client client) {
//         //Frees the resources associated to this RestEasy client
//         client.close();
//         mappings.remove(client);
//     }
// 
//     /**
//      * Gets the value associated to this client in the map.
//      *
//      * @param client RestEasy client
//      * @return A string value. If there is no entry for client in the map, returns null
//      */
//     public static String getValue(Client client) {
//         return mappings.get(client);
//     }
// 
//     /**
//      * Flushes the client/value map (it will be empty after invocation).
//      * Call this method when your application is being shut-down.
//      */
//     public static void clean() {
//         for (Client client : mappings.keySet()) {
//             remove(client);
//         }
//     }
// 
// }


import gluu.scim2.client.ClientMap;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;
package gluu.scim2.client.rest.provider;



/**
 * A Client-side filter employed to "inject" headers to the outgoing request. This filter applies only for
 * requests issued by concrete instances of {@link gluu.scim2.client.AbstractScimClient AbstractScimClient} class.
 * <p>Developers do not need to manipulate this class for their SCIM applications.</p>
 */
/*
 * Created by jgomer on 2017-11-25.
 */
@Provider
public class AuthorizationInjectionFilter implements ClientRequestFilter {

    private Logger logger = LogManager.getLogger(getClass());

    public void filter(ClientRequestContext context) {

        MultivaluedMap<String, Object> headers = context.getHeaders();
// Path: src/main/java/gluu/scim2/client/ClientMap.java
// public class ClientMap {
// 
//     private static ClientMap map = new ClientMap();
// 
//     private static Map<Client, String> mappings = new HashMap<>();
// 
//     private ClientMap() {
//     }
// 
//     /**
//      * Puts a new client/value pair in the map. If client already exists, the value is replaced.
//      *
//      * @param client RestEasy client
//      * @param value  Value to associate to this client - normally an access token
//      */
//     public static void update(Client client, String value) {
//         mappings.put(client, value);
//     }
// 
//     /**
//      * Removes a client from the map and then calls its close method to free resources.
//      *
//      * @param client Client to remove
//      */
//     public static void remove(Client client) {
//         //Frees the resources associated to this RestEasy client
//         client.close();
//         mappings.remove(client);
//     }
// 
//     /**
//      * Gets the value associated to this client in the map.
//      *
//      * @param client RestEasy client
//      * @return A string value. If there is no entry for client in the map, returns null
//      */
//     public static String getValue(Client client) {
//         return mappings.get(client);
//     }
// 
//     /**
//      * Flushes the client/value map (it will be empty after invocation).
//      * Call this method when your application is being shut-down.
//      */
//     public static void clean() {
//         for (Client client : mappings.keySet()) {
//             remove(client);
//         }
//     }
// 
// }


// Path: src/main/java/gluu/scim2/client/rest/provider/AuthorizationInjectionFilter.java
import gluu.scim2.client.ClientMap;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;

package gluu.scim2.client.rest.provider;



/**
 * A Client-side filter employed to "inject" headers to the outgoing request. This filter applies only for
 * requests issued by concrete instances of {@link gluu.scim2.client.AbstractScimClient AbstractScimClient} class.
 * <p>Developers do not need to manipulate this class for their SCIM applications.</p>
 */
/*
 * Created by jgomer on 2017-11-25.
 */
@Provider
public class AuthorizationInjectionFilter implements ClientRequestFilter {

    private Logger logger = LogManager.getLogger(getClass());

    public void filter(ClientRequestContext context) {

        MultivaluedMap<String, Object> headers = context.getHeaders();
        String authzHeader = ClientMap.getValue(context.getClient());