Index: petals-bc-rest/pom.xml
===================================================================
--- petals-bc-rest/pom.xml	(revision 42213)
+++ petals-bc-rest/pom.xml	(working copy)
@@ -70,7 +70,11 @@
             <!-- Conflicts between jjwt and jersey libs -->
             <version>${jackson.version}</version>
          </dependency>
-         
+         <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+            <version>${jackson.version}</version>
+         </dependency>
          <!-- We include patch about Apache HTTP Client Async -->
          <dependency>
             <groupId>org.apache.httpcomponents</groupId>
@@ -82,6 +86,11 @@
             <artifactId>httpcore-nio</artifactId>
             <version>4.4.8</version>
          </dependency>
+         <dependency>
+            <groupId>commons-validator</groupId>
+            <artifactId>commons-validator</artifactId>
+            <version>1.6</version>
+         </dependency>
       </dependencies>
    </dependencyManagement>
 
@@ -277,7 +286,7 @@
          <artifactId>bcprov-jdk15on</artifactId>
          <version>1.58</version>
       </dependency>
- 
+
       <dependency>
          <groupId>org.ow2.petals</groupId>
          <artifactId>petals-junit-external-resources</artifactId>
@@ -325,6 +334,10 @@
          <!-- Scope set to compile because used explicitly in unit tests, and is required at runtime -->
       </dependency>
       <dependency>
+         <groupId>com.fasterxml.jackson.core</groupId>
+         <artifactId>jackson-databind</artifactId>
+      </dependency>
+      <dependency>
          <groupId>org.apache.mina</groupId>
          <artifactId>mina-core</artifactId>
          <version>2.0.4</version>
@@ -349,6 +362,30 @@
          <artifactId>gson</artifactId>
          <scope>test</scope>
       </dependency>
+      <dependency>
+         <groupId>org.slf4j</groupId>
+         <artifactId>slf4j-api</artifactId>
+      </dependency>
+
+      <dependency>
+         <groupId>commons-validator</groupId>
+         <artifactId>commons-validator</artifactId>
+         <exclusions>
+            <exclusion>
+               <!-- In petals we relies on slf4j and
+                    its bridge which implements commons-logging -->
+               <groupId>commons-logging</groupId>
+               <artifactId>commons-logging</artifactId>
+            </exclusion>
+            <exclusion>
+               <!-- In petals we relies on slf4j and
+                    its bridge which implements commons-logging -->
+               <groupId>commons-collections</groupId>
+               <artifactId>commons-collections</artifactId>
+            </exclusion>
+         </exclusions>
+      </dependency>
+
    </dependencies>
 
    <build>
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/AuthenticationBuilder.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/AuthenticationBuilder.java	(revision 42213)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/AuthenticationBuilder.java	(working copy)
@@ -1,16 +1,16 @@
 /**
  * Copyright (c) 2017-2018 Linagora
- * 
+ *
  * This program/library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
  * the Free Software Foundation, either version 2.1 of the License, or (at your
  * option) any later version.
- * 
+ *
  * This program/library is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  * for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public License
  * along with this program/library; If not, see http://www.gnu.org/licenses/
  * for the GNU Lesser General Public License version 2.1.
@@ -32,6 +32,8 @@
 import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.UnsupportedAuthenticationException;
 import org.ow2.petals.binding.rest.exchange.outgoing.auth.jwt.JwtAuthentication;
 import org.ow2.petals.binding.rest.exchange.outgoing.auth.ntlm.NTLMAuthentication;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.Oauth2Authentication;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 
 import com.ebmwebsourcing.easycommons.xml.XMLHelper;
@@ -38,12 +40,12 @@
 
 /**
  * A builder to create the right authentication implementation according to configuration
- * 
+ *
  * @author Christophe DENEUX - Linagora
  *
  */
 public class AuthenticationBuilder {
-
+private final static org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AuthenticationBuilder.class);
     private AuthenticationBuilder() {
         // Utility class --> No constructor
     }
@@ -64,14 +66,13 @@
             final Element typeAuthElement = typeAuthElements.get(0);
             final String typeAuthEltName = typeAuthElement.getLocalName();
             if (BasicAuthentication.XML_TAG_NAME.equals(typeAuthEltName)) {
-                return BasicAuthentication.build(typeAuthElement, operationName, xPathEvaluator, componentPlaceholders,
-                        logger);
+                return BasicAuthentication.build(typeAuthElement, operationName, xPathEvaluator, componentPlaceholders, logger);
             } else if (NTLMAuthentication.XML_TAG_NAME.equals(typeAuthEltName)) {
-                return NTLMAuthentication.build(typeAuthElement, operationName, xPathEvaluator, componentPlaceholders,
-                        logger);
+                return NTLMAuthentication.build(typeAuthElement, operationName, xPathEvaluator, componentPlaceholders, logger);
             } else if (JwtAuthentication.XML_TAG_NAME.equals(typeAuthEltName)) {
-                return JwtAuthentication.build(typeAuthElement, operationName, xPathEvaluator, componentPlaceholders,
-                        logger);
+                return JwtAuthentication.build(typeAuthElement, operationName, xPathEvaluator, componentPlaceholders, logger);
+            } else if (Oauth2Authentication.XML_TAG_NAME.equals(typeAuthEltName)) {
+                return Oauth2Authentication.build(typeAuthElement, operationName, xPathEvaluator, componentPlaceholders, logger);
             } else {
                 throw new UnsupportedAuthenticationException(typeAuthEltName, operationName);
             }
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Authentication.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Authentication.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Authentication.java	(working copy)
@@ -0,0 +1,226 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPath;
+
+import org.apache.commons.validator.routines.UrlValidator;
+import org.apache.http.Consts;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.Credentials;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.AbstractTargetHostAuthentication;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.Authentication;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.AuthenticationConfigException;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.AuthenticationRuntimeException;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception.NoAuthenticationUrlOauthException;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception.NoPasswordOauthException;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception.NoUserNameOauthException;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception.OnlyOneAuthenticationUrlOauthException;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception.OnlyOnePasswordOauthException;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception.OnlyOneUsernameOauthException;
+import org.ow2.petals.binding.rest.utils.CachedExchange;
+import org.ow2.petals.binding.rest.utils.extractor.value.ValueExtractorBuilder;
+import org.ow2.petals.binding.rest.utils.extractor.value.XMLPayloadValueExtractor;
+import org.ow2.petals.binding.rest.utils.extractor.value.exception.ValueExtractorConfigException;
+import org.ow2.petals.binding.rest.utils.extractor.value.exception.ValueExtractorRuntimeException;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Oauth v2 Authentication RFC : https://tools.ietf.org/html/rfc6749
+ *
+ * @author Guillaume Laplace - AUSY
+ */
+public class Oauth2Authentication extends AbstractTargetHostAuthentication implements Authentication {
+    public static final String XML_TAG_NAME = "oauth2";
+
+    private static final String USERNAME_FIELD = "username";
+
+    private static final String MOT_DE_PASSE = "password";
+
+    private static final String AUTHENTICATION_URL = "authenticationUrl";
+
+    private final XMLPayloadValueExtractor username;
+
+    private final XMLPayloadValueExtractor pwd;
+
+    private final XMLPayloadValueExtractor authenticationUrl;
+
+    private Oauth2Authentication(Properties componentPlaceholders, Logger logger, XMLPayloadValueExtractor username,
+            XMLPayloadValueExtractor pwd, XMLPayloadValueExtractor authenticationUrl) {
+        super(componentPlaceholders, logger);
+        this.username = username;
+        this.pwd = pwd;
+        this.authenticationUrl = authenticationUrl;
+    }
+
+    /**
+     * Extract parameters from XML configuration
+     *
+     * @param authElt
+     * @param operationName
+     * @param xPathEvaluator
+     * @param componentPlaceholders
+     * @param logger
+     * @return
+     * @throws AuthenticationConfigException
+     */
+    public static Oauth2Authentication build(final Element authElt, final QName operationName,
+            final XPath xPathEvaluator, final Properties componentPlaceholders, final Logger logger)
+            throws AuthenticationConfigException {
+        try {
+            final String namespaceURI = authElt.getNamespaceURI();
+
+            final XMLPayloadValueExtractor username;
+            final NodeList usernameAuthElements = authElt.getElementsByTagNameNS(namespaceURI, USERNAME_FIELD);
+            if (usernameAuthElements.getLength() > 1) {
+                throw new OnlyOneUsernameOauthException(operationName);
+            } else if (usernameAuthElements.getLength() == 0) {
+                throw new NoUserNameOauthException(operationName);
+            } else {
+                username = ValueExtractorBuilder.build(((Element) usernameAuthElements.item(0)), xPathEvaluator,
+                        componentPlaceholders, logger);
+            }
+
+            final XMLPayloadValueExtractor pwd;
+            final NodeList pwdAuthElements = authElt.getElementsByTagNameNS(namespaceURI, MOT_DE_PASSE);
+            if (pwdAuthElements.getLength() > 1) {
+                throw new OnlyOnePasswordOauthException(operationName);
+            } else if (pwdAuthElements.getLength() == 0) {
+                throw new NoPasswordOauthException(operationName);
+            } else {
+                pwd = ValueExtractorBuilder.build(((Element) pwdAuthElements.item(0)), xPathEvaluator,
+                        componentPlaceholders, logger);
+            }
+
+            final XMLPayloadValueExtractor url;
+            final NodeList urlAuthElements = authElt.getElementsByTagNameNS(namespaceURI, AUTHENTICATION_URL);
+            if (urlAuthElements.getLength() > 1) {
+                throw new OnlyOneAuthenticationUrlOauthException(operationName);
+            } else if (urlAuthElements.getLength() == 0) {
+                throw new NoAuthenticationUrlOauthException(operationName);
+            } else {
+                url = ValueExtractorBuilder.build(((Element) urlAuthElements.item(0)), xPathEvaluator,
+                        componentPlaceholders, logger);
+            }
+
+            return new Oauth2Authentication(componentPlaceholders, logger, username, pwd, url);
+        } catch (ValueExtractorConfigException e) {
+            throw new AuthenticationConfigException(e);
+        }
+    }
+
+    @Override
+    protected AuthScheme getAuthScheme() {
+        return new Oauth2Scheme();
+    }
+
+    @Override
+    protected Credentials getCredentials(CachedExchange jbiExchange) throws AuthenticationRuntimeException {
+        try {
+            final UrlValidator urlValidator = new UrlValidator();
+            final String url = authenticationUrl.extractAsString(jbiExchange);
+            if (!urlValidator.isValid(url)) {
+                throw new IllegalArgumentException("authenticationUrl mal formed [" + url + "]");
+            }
+            HttpPost post = new HttpPost(url);
+            post.addHeader("Accept", "application/json");
+            post.addHeader("Content-type", "application/x-www-form-urlencoded");
+
+            List<NameValuePair> form = new ArrayList<>();
+            form.add(new BasicNameValuePair(USERNAME_FIELD, username.extractAsString(jbiExchange)));
+            form.add(new BasicNameValuePair(MOT_DE_PASSE, pwd.extractAsString(jbiExchange)));
+            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, Consts.UTF_8);
+
+            post.setEntity(entity);
+            ResponseHandler<Oauth2Response> responseHandler = createResponseHandler();
+            Oauth2Response response;
+            try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
+                response = httpClient.execute(post, responseHandler);
+            }
+
+            if (response == null) {
+                throw new AuthenticationRuntimeException(new Exception("Unexpected response"));
+            }
+
+            return new Oauth2Credentials(response.getToken(), response.getType());
+        } catch (IOException | ValueExtractorRuntimeException | IllegalArgumentException e) {
+            throw new AuthenticationRuntimeException(e);
+        }
+    }
+
+    /**
+     * Create response handler for parse Oauth 2 http response (JSON -> object)
+     * <p>
+     * Throwing ClientProtocolException if response http statut is 401 or 404
+     *
+     * @return
+     */
+    private ResponseHandler<Oauth2Response> createResponseHandler() {
+        return new ResponseHandler<Oauth2Response>() {
+            @Override
+            public Oauth2Response handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
+                int status = response.getStatusLine().getStatusCode();
+                if (status == 200) {
+                    final HttpEntity responseEntity = response.getEntity();
+                    String json = EntityUtils.toString(responseEntity);
+                    Oauth2Response retour = null;
+                    if (json != null) {
+                        retour = new ObjectMapper().readerFor(Oauth2Response.class).readValue(json);
+                    }
+                    return retour;
+                } else if (status == 401) {
+                    throw new ClientProtocolException("Wrong user and password");
+                } else if (status == 404) {
+                    throw new ClientProtocolException("Authentification url not found");
+                } else {
+                    throw new ClientProtocolException("Unexpected response status: " + status);
+                }
+            }
+        };
+    }
+
+    @Override
+    public void log(String prefix) {
+        this.logger.log(Level.CONFIG, "{}- Oauth2 authentication: ", prefix);
+        this.logger.log(Level.CONFIG, "{}\t- Username:" + username, prefix);
+        this.logger.log(Level.CONFIG, "{}\t- url: " + authenticationUrl, prefix);
+    }
+
+}
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Credentials.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Credentials.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Credentials.java	(working copy)
@@ -0,0 +1,62 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+import org.apache.http.annotation.Contract;
+import org.apache.http.annotation.ThreadingBehavior;
+import org.apache.http.auth.Credentials;
+
+/**
+ * @author Guillaume Laplace - AUSY
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public class Oauth2Credentials implements Credentials, Serializable {
+    private static final long serialVersionUID = -7105638858129399524L;
+
+    private final String token;
+
+    private final String tokenType;
+
+    public Oauth2Credentials(String token, String tokenType) {
+        this.token = token;
+        this.tokenType = tokenType;
+    }
+
+    @Override
+    public Principal getUserPrincipal() {
+        throw new RuntimeException(
+                "Oauth2Credentials.getUserPrincipal() unsupported: no principal exists for Oauth2Credentials !!!");
+    }
+
+    @Override
+    public String getPassword() {
+        throw new RuntimeException(
+                "Oauth2Credentials.getPassword() unsupported: no password information exists for Oauth2Credentials !!!");
+    }
+
+    public String getToken() {
+        return token;
+    }
+
+    public String getTokenType() {
+        return tokenType;
+    }
+}
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Response.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Response.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Response.java	(working copy)
@@ -0,0 +1,91 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * oauth2 response (from RFC https://tools.ietf.org/html/rfc6749#section-5.1 )
+ *
+ * @author Guillaume Laplace - AUSY
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Oauth2Response {
+
+    @JsonProperty("access_token")
+    private String token;
+
+    @JsonProperty("token_type")
+    private String type;
+
+    @JsonProperty("expire_in")
+    private Long expireIn;
+
+    @JsonProperty("refresh_token")
+    private String refreshToken;
+
+    @JsonProperty("scope")
+    private String scope;
+
+    public String getToken() {
+        return token;
+    }
+
+    public void setToken(String token) {
+        this.token = token;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public Long getExpireIn() {
+        return expireIn;
+    }
+
+    public void setExpireIn(Long expireIn) {
+        this.expireIn = expireIn;
+    }
+
+    public String getRefreshToken() {
+        return refreshToken;
+    }
+
+    public void setRefreshToken(String refreshToken) {
+        this.refreshToken = refreshToken;
+    }
+
+    public String getScope() {
+        return scope;
+    }
+
+    public void setScope(String scope) {
+        this.scope = scope;
+    }
+
+    @Override
+    public String toString() {
+        return "Oauth2Response{" + "token='" + token + '\'' + ", type='" + type + '\'' + ", expireIn=" + expireIn
+                + ", refreshToken='" + refreshToken + '\'' + ", scope='" + scope + '\'' + '}';
+    }
+}
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Scheme.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Scheme.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2Scheme.java	(working copy)
@@ -0,0 +1,145 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2;
+
+import java.nio.charset.Charset;
+
+import org.apache.http.Consts;
+import org.apache.http.Header;
+import org.apache.http.HttpRequest;
+import org.apache.http.auth.AUTH;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.InvalidCredentialsException;
+import org.apache.http.auth.MalformedChallengeException;
+import org.apache.http.impl.auth.RFC2617Scheme;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+
+/**
+ * @author Guillaume Laplace - AUSY
+ */
+public class Oauth2Scheme extends RFC2617Scheme {
+
+    private static final long serialVersionUID = 7988460819983275185L;
+
+    /**
+     * Whether the basic authentication process is complete
+     */
+    private boolean complete;
+
+    public Oauth2Scheme(final Charset credentialsCharset) {
+        super(credentialsCharset);
+        this.complete = false;
+    }
+
+    public Oauth2Scheme() {
+        this(Consts.ASCII);
+    }
+
+    /**
+     * Returns textual designation of the Oauth2 authentication scheme.
+     *
+     * @return {@code Oauth2}
+     */
+    @Override
+    public String getSchemeName() {
+        return "oauth2";
+    }
+
+    /**
+     * Processes the Oauth2 challenge.
+     *
+     * @param header
+     *            the challenge header
+     * @throws MalformedChallengeException
+     *             is thrown if the authentication challenge is malformed
+     */
+    @Override
+    public void processChallenge(final Header header) throws MalformedChallengeException {
+        super.processChallenge(header);
+        this.complete = true;
+    }
+
+    /**
+     * Tests if the Oauth2 authentication process has been completed.
+     *
+     * @return {@code true} if Oauth2 authorization has been processed, {@code false} otherwise.
+     */
+    @Override
+    public boolean isComplete() {
+        return this.complete;
+    }
+
+    /**
+     * Returns {@code false}. Oauth2 authentication scheme is request based.
+     *
+     * @return {@code false}.
+     */
+    @Override
+    public boolean isConnectionBased() {
+        return false;
+    }
+
+    /**
+     * Produces Oauth2 authorization header for the given set of {@link Credentials}.
+     *
+     * @param credentials
+     *            The set of credentials to be used for authentication
+     * @param request
+     *            The request being authenticated
+     * @return a Oauth2 authorization string
+     * @throws InvalidCredentialsException
+     *             if authentication credentials are not valid or not applicable for this authentication scheme
+     * @throws AuthenticationException
+     *             if authorization string cannot be generated due to an authentication failure
+     */
+    @Override
+    public Header authenticate(final Credentials credentials, final HttpRequest request, final HttpContext context)
+            throws AuthenticationException {
+
+        Args.notNull(credentials, "Credentials");
+        Args.notNull(request, "HTTP request");
+
+        if (credentials instanceof Oauth2Credentials) {
+            Oauth2Credentials cred = (Oauth2Credentials) credentials;
+            return new BasicHeader(AUTH.WWW_AUTH_RESP, cred.getTokenType() + " " + cred.getToken());
+
+        } else {
+            throw new InvalidCredentialsException(
+                    "Credentials cannot be used for Oauth2 authentication: " + credentials.getClass().getName());
+        }
+    }
+
+    @Override
+    public String toString() {
+        return new StringBuilder("Oauth2 [complete=").append(this.complete).append("]").toString();
+    }
+
+    /**
+     * @deprecated (Apache HTTP CLI 4.2) Use
+     *             {@link org.apache.http.auth.ContextAwareAuthScheme#authenticate(Credentials, HttpRequest, HttpContext)}
+     */
+    @Override
+    @Deprecated
+    public Header authenticate(Credentials credentials, HttpRequest request) throws AuthenticationException {
+        return this.authenticate(credentials, request, new BasicHttpContext());
+    }
+}
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/NoAuthenticationUrlOauthException.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/NoAuthenticationUrlOauthException.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/NoAuthenticationUrlOauthException.java	(working copy)
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception;
+
+import javax.xml.namespace.QName;
+
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.AuthenticationConfigException;
+
+/**
+ * @author Guillaume Laplace - AUSY
+ */
+public class NoAuthenticationUrlOauthException extends AuthenticationConfigException {
+
+    private static final long serialVersionUID = -4243007009913739170L;
+    private static final String MESSAGE_PATTERN = "No authentication url defined for Oauth v2 authentication of operation '%s'.";
+
+    public NoAuthenticationUrlOauthException(final QName operation) {
+        super(String.format(MESSAGE_PATTERN, operation.toString()));
+    }
+}
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/NoPasswordOauthException.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/NoPasswordOauthException.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/NoPasswordOauthException.java	(working copy)
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception;
+
+import javax.xml.namespace.QName;
+
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.AuthenticationConfigException;
+
+public class NoPasswordOauthException extends AuthenticationConfigException {
+
+    private static final long serialVersionUID = 7004878746543963758L;
+    private static final String MESSAGE_PATTERN = "No password defined for Oauth v2 authentication of operation '%s'.";
+
+    public NoPasswordOauthException(final QName operation) {
+        super(String.format(MESSAGE_PATTERN, operation.toString()));
+    }
+}
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/NoUserNameOauthException.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/NoUserNameOauthException.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/NoUserNameOauthException.java	(working copy)
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception;
+
+import javax.xml.namespace.QName;
+
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.AuthenticationConfigException;
+
+/**
+ * @author Guillaume Laplace - AUSY
+ */
+public class NoUserNameOauthException extends AuthenticationConfigException {
+
+    private static final long serialVersionUID = -1338985186102840957L;
+    private static final String MESSAGE_PATTERN = "No username defined for Oauth v2 authentication of operation '%s'.";
+
+    public NoUserNameOauthException(final QName operation) {
+        super(String.format(MESSAGE_PATTERN, operation.toString()));
+    }
+}
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/Oauth2ConfigurationException.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/Oauth2ConfigurationException.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/Oauth2ConfigurationException.java	(working copy)
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception;
+
+import javax.xml.namespace.QName;
+
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.AuthenticationConfigException;
+
+/**
+ * @author Guillaume Laplace - AUSY
+ */
+public class Oauth2ConfigurationException extends AuthenticationConfigException {
+
+    private static final long serialVersionUID = 3921331221942320558L;
+    private static final String MESSAGE_PATTERN = "Only one and non empty of %s parameter is allowed in operation %s";
+
+    public Oauth2ConfigurationException(String parameterName, QName operation) {
+        super(String.format(MESSAGE_PATTERN, parameterName, operation.toString()));
+    }
+}
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/OnlyOneAuthenticationUrlOauthException.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/OnlyOneAuthenticationUrlOauthException.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/OnlyOneAuthenticationUrlOauthException.java	(working copy)
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception;
+
+import javax.xml.namespace.QName;
+
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.AuthenticationConfigException;
+
+/**
+ * @author Guillaume Laplace - AUSY
+ */
+public class OnlyOneAuthenticationUrlOauthException extends AuthenticationConfigException {
+
+    private static final long serialVersionUID = -1264356542593046520L;
+    private static final String MESSAGE_PATTERN = "Only one authenticationURl definition per Oauth v2 authentication configuration can be set for operation '%s'.";
+
+    public OnlyOneAuthenticationUrlOauthException(final QName operation) {
+        super(String.format(MESSAGE_PATTERN, operation.toString()));
+    }
+}
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/OnlyOnePasswordOauthException.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/OnlyOnePasswordOauthException.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/OnlyOnePasswordOauthException.java	(working copy)
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception;
+
+import javax.xml.namespace.QName;
+
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.AuthenticationConfigException;
+
+/**
+ * @author Guillaume Laplace - AUSY
+ */
+public class OnlyOnePasswordOauthException extends AuthenticationConfigException {
+
+    private static final long serialVersionUID = 2546958215822426096L;
+    private static final String MESSAGE_PATTERN = "Only one password definition per Oauth v2 authentication configuration can be set for operation '%s'.";
+
+    public OnlyOnePasswordOauthException(final QName operation) {
+        super(String.format(MESSAGE_PATTERN, operation.toString()));
+    }
+}
Index: petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/OnlyOneUsernameOauthException.java
===================================================================
--- petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/OnlyOneUsernameOauthException.java	(nonexistent)
+++ petals-bc-rest/src/main/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/exception/OnlyOneUsernameOauthException.java	(working copy)
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception;
+
+import javax.xml.namespace.QName;
+
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.AuthenticationConfigException;
+
+/**
+ * @author Guillaume Laplace - AUSY
+ */
+public class OnlyOneUsernameOauthException extends AuthenticationConfigException {
+
+    private static final long serialVersionUID = -954922437499910375L;
+    private static final String MESSAGE_PATTERN = "Only one username definition per Oauth v2 authentication configuration can be set for operation '%s'.";
+
+    public OnlyOneUsernameOauthException(final QName operation) {
+        super(String.format(MESSAGE_PATTERN, operation.toString()));
+    }
+}
Index: petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/AuthenticationBuilderTest.java
===================================================================
--- petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/AuthenticationBuilderTest.java	(revision 42213)
+++ petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/AuthenticationBuilderTest.java	(working copy)
@@ -1,16 +1,16 @@
 /**
  * Copyright (c) 2017-2018 Linagora
- * 
+ *
  * This program/library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
  * the Free Software Foundation, either version 2.1 of the License, or (at your
  * option) any later version.
- * 
+ *
  * This program/library is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  * for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public License
  * along with this program/library; If not, see http://www.gnu.org/licenses/
  * for the GNU Lesser General Public License version 2.1.
@@ -27,12 +27,13 @@
 import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.OnlyOneAuthenticationException;
 import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.UnsupportedAuthenticationException;
 import org.ow2.petals.binding.rest.exchange.outgoing.auth.ntlm.NTLMAuthentication;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.Oauth2Authentication;
 import org.xml.sax.SAXException;
 
 /**
  * Unit test of {@link AuthenticationBuilder} about error management. Nominal use cases are tested with service
  * executions (see {@link RestProvideServiceSecuredTest}
- * 
+ *
  * @author Christophe DENEUX - Linagora
  *
  */
@@ -62,6 +63,12 @@
         assertTrue(this.build("auth/ntlm-auth-configured.xml") instanceof NTLMAuthentication);
     }
 
+    @Test
+    public void validOauthv2() throws Exception {
+
+        assertTrue(this.build("auth/oauth2-auth-configured.xml") instanceof Oauth2Authentication);
+    }
+
     private Authentication build(final String authXmlConfig)
             throws SAXException, IOException, AuthenticationConfigException {
 
Index: petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2AuthenticationTest.java
===================================================================
--- petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2AuthenticationTest.java	(nonexistent)
+++ petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2AuthenticationTest.java	(working copy)
@@ -0,0 +1,107 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2;
+
+import org.apache.http.auth.AuthScheme;
+import org.junit.Test;
+import org.ow2.petals.binding.rest.exchange.outgoing.RestProvideServiceSecuredTest;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.AbstractTest;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.Authentication;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.exception.AuthenticationConfigException;
+import org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2.exception.*;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Unit test of {@link Oauth2Authentication} loading its configuration. Runtime use cases are tested with service
+ * executions (see {@link RestProvideServiceSecuredTest}
+ *
+ * @author Guillaume Laplace - AUSY
+ */
+public class Oauth2AuthenticationTest extends AbstractTest {
+
+    @Test(expected = NoUserNameOauthException.class)
+    public void noUserNameDefined() throws Exception {
+        this.build("auth/oauth2/no-username-configured.xml");
+    }
+
+    @Test(expected = NoPasswordOauthException.class)
+    public void noPasswordDefined() throws Exception {
+        this.build("auth/oauth2/no-password-configured.xml");
+    }
+
+    @Test(expected = NoAuthenticationUrlOauthException.class)
+    public void noAuthenticationUrlDefined() throws Exception {
+        this.build("auth/oauth2/no-authentication-url-configured.xml");
+    }
+
+    @Test(expected = OnlyOneUsernameOauthException.class)
+    public void severalUserNameDefined() throws Exception {
+        this.build("auth/oauth2/two-usernames-configured.xml");
+    }
+
+    @Test(expected = OnlyOnePasswordOauthException.class)
+    public void severalPasswordDefined() throws Exception {
+        this.build("auth/oauth2/two-password-configured.xml");
+    }
+
+    @Test(expected = OnlyOneAuthenticationUrlOauthException.class)
+    public void severalAnthenticationUrlConfiguration() throws Exception {
+        this.build("auth/oauth2/two-authentication-url-configured.xml");
+    }
+
+    @Test
+    public void getAuthScheme() throws SAXException, IOException, AuthenticationConfigException {
+
+        final Authentication auth = this.build("auth/oauth2-auth-configured.xml");
+        assertTrue(auth instanceof Oauth2Authentication);
+        final Oauth2Authentication oauth = (Oauth2Authentication) auth;
+
+        final AuthScheme authSheme = oauth.getAuthScheme();
+        assertNotNull(authSheme);
+        assertTrue(authSheme instanceof Oauth2Scheme);
+        assertEquals("oauth2", authSheme.getSchemeName());
+
+    }
+
+    // non testable sans un mock pour récupérer la requête http
+    @Test
+    public void getCredentials() {
+        assertTrue(true);
+    }
+
+
+    private Authentication build(final String authXmlConfig)
+        throws SAXException, IOException, AuthenticationConfigException {
+
+        return this.build(authXmlConfig, COMPONENT_PLACEHOLDERS);
+    }
+
+    private Authentication build(final String authXmlConfig, final Properties placeholders)
+        throws SAXException, IOException, AuthenticationConfigException {
+
+        return Oauth2Authentication.build(this.loadDocument(authXmlConfig).getDocumentElement(),
+            OPERATION, XPATH_EVALUATOR, placeholders, LOG);
+    }
+}
\ No newline at end of file
Index: petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2CredentialsTest.java
===================================================================
--- petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2CredentialsTest.java	(nonexistent)
+++ petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2CredentialsTest.java	(working copy)
@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Guillaume Laplace - AUSY
+ */
+public class Oauth2CredentialsTest {
+
+    private static final String TOKEN_TYPE = "bearer";
+    private static final String TOKEN = "the token";
+    private Oauth2Credentials oauth2Credentials;
+
+    @Before
+    public void setUp() throws Exception {
+        oauth2Credentials = new Oauth2Credentials(TOKEN, TOKEN_TYPE);
+    }
+
+    @Test(expected = RuntimeException.class)
+    public void getUserPrincipal() {
+        oauth2Credentials.getUserPrincipal();
+    }
+
+    @Test(expected = RuntimeException.class)
+    public void getPassword() {
+        oauth2Credentials.getPassword();
+    }
+
+    @Test
+    public void getToken() {
+        assertEquals(TOKEN,oauth2Credentials.getToken());
+    }
+
+    @Test
+    public void getTokenType() {
+        assertEquals(TOKEN_TYPE,oauth2Credentials.getTokenType());
+
+    }
+}
\ No newline at end of file
Index: petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2SchemeTest.java
===================================================================
--- petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2SchemeTest.java	(nonexistent)
+++ petals-bc-rest/src/test/java/org/ow2/petals/binding/rest/exchange/outgoing/auth/oauth2/Oauth2SchemeTest.java	(working copy)
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2017-2018 Linagora
+ *
+ * This program/library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This program/library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program/library; If not, see http://www.gnu.org/licenses/
+ * for the GNU Lesser General Public License version 2.1.
+ */
+package org.ow2.petals.binding.rest.exchange.outgoing.auth.oauth2;
+
+import org.apache.http.Header;
+import org.apache.http.auth.AUTH;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.Credentials;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.protocol.BasicHttpContext;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Guillaume Laplace - AUSY
+ */
+public class Oauth2SchemeTest {
+
+    private Oauth2Scheme oauth2Scheme;
+
+    @Before
+    public void setUp() throws Exception {
+        oauth2Scheme = new Oauth2Scheme();
+    }
+
+    @Test
+    public void getSchemeName() {
+        assertEquals("oauth2", oauth2Scheme.getSchemeName());
+    }
+
+
+    @Test
+    public void isConnectionBased() {
+        assertFalse(oauth2Scheme.isConnectionBased());
+    }
+
+    @Test
+    public void authenticate() throws AuthenticationException {
+        final String tokenType = "bearer";
+        final String token = "123azer456tyui789op";
+
+        final Credentials credentials = new Oauth2Credentials(token, tokenType);
+        final Header header = oauth2Scheme.authenticate(credentials, new BasicHttpRequest("POST", "/auth"), new BasicHttpContext());
+
+        assertNotNull(header);
+        assertTrue(header instanceof BasicHeader);
+        assertEquals(AUTH.WWW_AUTH_RESP, header.getName());
+        assertEquals(tokenType + " " + token, header.getValue());
+
+    }
+
+}
\ No newline at end of file
Index: petals-bc-rest/src/test/resources/auth/oauth2/malformed-authentication-url-configured.xml
===================================================================
--- petals-bc-rest/src/test/resources/auth/oauth2/malformed-authentication-url-configured.xml	(nonexistent)
+++ petals-bc-rest/src/test/resources/auth/oauth2/malformed-authentication-url-configured.xml	(working copy)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017-2018 Linagora
+
+ This program/library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This program/library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program/library; If not, see http://www.gnu.org/licenses/
+ for the GNU Lesser General Public License version 2.1.
+-->
+<auth:authentication xmlns:auth="http://petals.ow2.org/auth">
+   <auth:oauth2>
+      <auth:username>
+         <auth:constant>username</auth:constant>
+      </auth:username>
+      <auth:password>
+         <auth:constant>password</auth:constant>
+      </auth:password>
+      <auth:authenticationUrl>
+         <auth:constant>url</auth:constant>
+      </auth:authenticationUrl>
+   </auth:oauth2>
+</auth:authentication>
\ No newline at end of file
Index: petals-bc-rest/src/test/resources/auth/oauth2/no-authentication-url-configured.xml
===================================================================
--- petals-bc-rest/src/test/resources/auth/oauth2/no-authentication-url-configured.xml	(nonexistent)
+++ petals-bc-rest/src/test/resources/auth/oauth2/no-authentication-url-configured.xml	(working copy)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017-2018 Linagora
+
+ This program/library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This program/library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program/library; If not, see http://www.gnu.org/licenses/
+ for the GNU Lesser General Public License version 2.1.
+-->
+<auth:authentication xmlns:auth="http://petals.ow2.org/auth">
+   <auth:oauth2>
+      <auth:username>
+         <auth:constant>username</auth:constant>
+      </auth:username>
+      <auth:password>
+         <auth:constant>password</auth:constant>
+      </auth:password>
+   </auth:oauth2>
+</auth:authentication>
\ No newline at end of file
Index: petals-bc-rest/src/test/resources/auth/oauth2/no-password-configured.xml
===================================================================
--- petals-bc-rest/src/test/resources/auth/oauth2/no-password-configured.xml	(nonexistent)
+++ petals-bc-rest/src/test/resources/auth/oauth2/no-password-configured.xml	(working copy)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017-2018 Linagora
+
+ This program/library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This program/library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program/library; If not, see http://www.gnu.org/licenses/
+ for the GNU Lesser General Public License version 2.1.
+-->
+<auth:authentication xmlns:auth="http://petals.ow2.org/auth">
+   <auth:oauth2>
+      <auth:username>
+         <auth:constant>username</auth:constant>
+      </auth:username>
+      <auth:authenticationUrl>
+         <auth:constant>domain</auth:constant>
+      </auth:authenticationUrl>
+   </auth:oauth2>
+</auth:authentication>
\ No newline at end of file
Index: petals-bc-rest/src/test/resources/auth/oauth2/no-username-configured.xml
===================================================================
--- petals-bc-rest/src/test/resources/auth/oauth2/no-username-configured.xml	(nonexistent)
+++ petals-bc-rest/src/test/resources/auth/oauth2/no-username-configured.xml	(working copy)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017-2018 Linagora
+
+ This program/library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This program/library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program/library; If not, see http://www.gnu.org/licenses/
+ for the GNU Lesser General Public License version 2.1.
+-->
+<auth:authentication xmlns:auth="http://petals.ow2.org/auth">
+   <auth:oauth2>
+      <auth:password>
+         <auth:constant>password</auth:constant>
+      </auth:password>
+      <auth:authenticationUrl>
+         <auth:constant>domain</auth:constant>
+      </auth:authenticationUrl>
+   </auth:oauth2>
+</auth:authentication>
\ No newline at end of file
Index: petals-bc-rest/src/test/resources/auth/oauth2/two-authentication-url-configured.xml
===================================================================
--- petals-bc-rest/src/test/resources/auth/oauth2/two-authentication-url-configured.xml	(nonexistent)
+++ petals-bc-rest/src/test/resources/auth/oauth2/two-authentication-url-configured.xml	(working copy)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017-2018 Linagora
+
+ This program/library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This program/library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program/library; If not, see http://www.gnu.org/licenses/
+ for the GNU Lesser General Public License version 2.1.
+-->
+<auth:authentication xmlns:auth="http://petals.ow2.org/auth">
+   <auth:oauth2>
+      <auth:username>
+         <auth:constant>username</auth:constant>
+      </auth:username>
+      <auth:password>
+         <auth:constant>password</auth:constant>
+      </auth:password>
+      <auth:authenticationUrl>
+         <auth:constant>http://url.com/auth</auth:constant>
+      </auth:authenticationUrl>
+      <auth:authenticationUrl>
+         <auth:constant>http://url.com/auth/v2</auth:constant>
+      </auth:authenticationUrl>
+   </auth:oauth2>
+</auth:authentication>
\ No newline at end of file
Index: petals-bc-rest/src/test/resources/auth/oauth2/two-password-configured.xml
===================================================================
--- petals-bc-rest/src/test/resources/auth/oauth2/two-password-configured.xml	(nonexistent)
+++ petals-bc-rest/src/test/resources/auth/oauth2/two-password-configured.xml	(working copy)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017-2018 Linagora
+
+ This program/library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This program/library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program/library; If not, see http://www.gnu.org/licenses/
+ for the GNU Lesser General Public License version 2.1.
+-->
+<auth:authentication xmlns:auth="http://petals.ow2.org/auth">
+   <auth:oauth2>
+      <auth:username>
+         <auth:constant>username</auth:constant>
+      </auth:username>
+      <auth:password>
+         <auth:constant>password</auth:constant>
+      </auth:password>
+      <auth:password>
+         <auth:constant>password 2</auth:constant>
+      </auth:password>
+      <auth:authenticationUrl>
+         <auth:constant>http://url.com/auth</auth:constant>
+      </auth:authenticationUrl>
+   </auth:oauth2>
+</auth:authentication>
\ No newline at end of file
Index: petals-bc-rest/src/test/resources/auth/oauth2/two-usernames-configured.xml
===================================================================
--- petals-bc-rest/src/test/resources/auth/oauth2/two-usernames-configured.xml	(nonexistent)
+++ petals-bc-rest/src/test/resources/auth/oauth2/two-usernames-configured.xml	(working copy)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017-2018 Linagora
+
+ This program/library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This program/library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program/library; If not, see http://www.gnu.org/licenses/
+ for the GNU Lesser General Public License version 2.1.
+-->
+<auth:authentication xmlns:auth="http://petals.ow2.org/auth">
+   <auth:oauth2>
+      <auth:username>
+         <auth:constant>username</auth:constant>
+      </auth:username>
+      <auth:username>
+         <auth:constant>username 2</auth:constant>
+      </auth:username>
+      <auth:password>
+         <auth:constant>password</auth:constant>
+      </auth:password>
+      <auth:authenticationUrl>
+         <auth:constant>http://url.com/auth</auth:constant>
+      </auth:authenticationUrl>
+   </auth:oauth2>
+</auth:authentication>
\ No newline at end of file
Index: petals-bc-rest/src/test/resources/auth/oauth2-auth-configured.xml
===================================================================
--- petals-bc-rest/src/test/resources/auth/oauth2-auth-configured.xml	(nonexistent)
+++ petals-bc-rest/src/test/resources/auth/oauth2-auth-configured.xml	(working copy)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017-2018 Linagora
+
+ This program/library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This program/library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program/library; If not, see http://www.gnu.org/licenses/
+ for the GNU Lesser General Public License version 2.1.
+-->
+<auth:authentication xmlns:auth="http://petals.ow2.org/auth">
+   <auth:oauth2>
+      <auth:username>
+         <auth:constant>username</auth:constant>
+      </auth:username>
+      <auth:password>
+         <auth:constant>password</auth:constant>
+      </auth:password>
+      <auth:authenticationUrl>
+         <auth:constant>http://url.com/auth</auth:constant>
+      </auth:authenticationUrl>
+   </auth:oauth2>
+</auth:authentication>
\ No newline at end of file
