Skip to content

Commit 5bba20f

Browse files
fitekoneaarturobernalg
authored andcommitted
Add SCRAM-SHA-256 (RFC 7804)
Implements HTTP SCRAM with SCRAM-SHA-256 per RFC 7804 and SCRAM mechanics per RFC 5802/7677.
1 parent 72a00a0 commit 5bba20f

File tree

13 files changed

+1996
-4
lines changed

13 files changed

+1996
-4
lines changed

httpclient5/src/main/java/org/apache/hc/client5/http/auth/StandardAuthScheme.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,12 @@ private StandardAuthScheme() {
8282
@Deprecated
8383
public static final String KERBEROS = "Kerberos";
8484

85+
86+
/**
87+
* SCRAM with SHA-256 as defined by RFC 7804 / RFC 7677.
88+
*
89+
* @since 5.6
90+
*/
91+
public static final String SCRAM_SHA_256 = "SCRAM-SHA-256";
92+
8593
}

httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ public class DefaultAuthenticationStrategy implements AuthenticationStrategy {
6767
public static final DefaultAuthenticationStrategy INSTANCE = new DefaultAuthenticationStrategy();
6868

6969
private static final List<String> DEFAULT_SCHEME_PRIORITY =
70-
Collections.unmodifiableList(Arrays.asList(
71-
StandardAuthScheme.BEARER,
72-
StandardAuthScheme.DIGEST,
73-
StandardAuthScheme.BASIC));
70+
Collections.unmodifiableList(Arrays.asList(
71+
StandardAuthScheme.BEARER,
72+
StandardAuthScheme.SCRAM_SHA_256,
73+
StandardAuthScheme.DIGEST,
74+
StandardAuthScheme.BASIC));
7475

7576
protected List<String> getSchemePriority() {
7677
return DEFAULT_SCHEME_PRIORITY;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* ====================================================================
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
* ====================================================================
20+
*
21+
* This software consists of voluntary contributions made by many
22+
* individuals on behalf of the Apache Software Foundation. For more
23+
* information on the Apache Software Foundation, please see
24+
* <http://www.apache.org/>.
25+
*
26+
*/
27+
28+
package org.apache.hc.client5.http.impl;
29+
30+
import org.apache.hc.client5.http.auth.AuthenticationException;
31+
32+
/**
33+
* Represents an exception that occurs during SCRAM (Salted Challenge Response Authentication Mechanism) authentication.
34+
* <p>
35+
* SCRAM is a family of SASL mechanisms used for secure authentication. This exception is thrown when
36+
* an error or issue is encountered during the SCRAM authentication process.
37+
* </p>
38+
*
39+
* @since 5.6
40+
*/
41+
public class ScramException extends AuthenticationException {
42+
43+
private static final long serialVersionUID = 2491660491058647342L;
44+
45+
/**
46+
* Constructs a new {@code ScramException} with {@code null} as its detail message.
47+
* The cause is not initialized and may be subsequently initialized by a call to {@link #initCause}.
48+
*/
49+
public ScramException() {
50+
super();
51+
}
52+
53+
/**
54+
* Constructs a new {@code ScramException} with the specified detail message.
55+
* The cause is not initialized and may be subsequently initialized by a call to {@link #initCause}.
56+
*
57+
* @param message the detail message, saved for later retrieval by the {@link #getMessage()} method.
58+
*/
59+
public ScramException(final String message) {
60+
super(message);
61+
}
62+
63+
/**
64+
* Constructs a new {@code ScramException} with the specified detail message and cause.
65+
*
66+
* @param message the detail message, saved for later retrieval by the {@link #getMessage()} method.
67+
* @param cause the cause, saved for later retrieval by the {@link #getCause()} method.
68+
* A {@code null} value indicates that the cause is nonexistent or unknown.
69+
*/
70+
public ScramException(final String message, final Throwable cause) {
71+
super(message, cause);
72+
}
73+
}

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.apache.hc.client5.http.impl.auth.BasicSchemeFactory;
6161
import org.apache.hc.client5.http.impl.auth.BearerSchemeFactory;
6262
import org.apache.hc.client5.http.impl.auth.DigestSchemeFactory;
63+
import org.apache.hc.client5.http.impl.auth.ScramSchemeFactory;
6364
import org.apache.hc.client5.http.impl.auth.SystemDefaultCredentialsProvider;
6465
import org.apache.hc.client5.http.impl.nio.MultihomeConnectionInitiator;
6566
import org.apache.hc.client5.http.impl.routing.DefaultRoutePlanner;
@@ -898,6 +899,7 @@ public CloseableHttpAsyncClient build() {
898899
.register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE)
899900
.register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE)
900901
.register(StandardAuthScheme.BEARER, BearerSchemeFactory.INSTANCE)
902+
.register(StandardAuthScheme.SCRAM_SHA_256, ScramSchemeFactory.INSTANCE)
901903
.build();
902904
}
903905
Lookup<CookieSpecFactory> cookieSpecRegistryCopy = this.cookieSpecRegistry;

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.apache.hc.client5.http.impl.auth.BasicSchemeFactory;
7070
import org.apache.hc.client5.http.impl.auth.BearerSchemeFactory;
7171
import org.apache.hc.client5.http.impl.auth.DigestSchemeFactory;
72+
import org.apache.hc.client5.http.impl.auth.ScramSchemeFactory;
7273
import org.apache.hc.client5.http.impl.auth.SystemDefaultCredentialsProvider;
7374
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
7475
import org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner;
@@ -1172,6 +1173,7 @@ public CloseableHttpAsyncClient build() {
11721173
.register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE)
11731174
.register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE)
11741175
.register(StandardAuthScheme.BEARER, BearerSchemeFactory.INSTANCE)
1176+
.register(StandardAuthScheme.SCRAM_SHA_256, ScramSchemeFactory.INSTANCE)
11751177
.build();
11761178
}
11771179
Lookup<CookieSpecFactory> cookieSpecRegistryCopy = this.cookieSpecRegistry;

0 commit comments

Comments
 (0)