Skip to content

Commit

Permalink
[ELY-2362] Small fixes for bearer-only support
Browse files Browse the repository at this point in the history
  • Loading branch information
fjuma committed Jul 27, 2022
1 parent 8def1a1 commit d950ffa
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
Expand Up @@ -207,6 +207,9 @@ private HttpConstants() {

/**
* Bearer token pattern.
* The Bearer token authorization header is of the form "Bearer", followed by optional whitespace, followed by
* the token itself, followed by optional whitespace. The token itself must be one or more characters and must
* not contain any whitespace.
*/
public static final Pattern BEARER_TOKEN_PATTERN = Pattern.compile("^Bearer *([^ ]+) *$", Pattern.CASE_INSENSITIVE);

Expand Down
Expand Up @@ -34,7 +34,7 @@
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @author <a href="mailto:fjuma@redhat.com">Farah Juma</a>
*/
public class BasicAuthRequestAuthenticator extends BearerTokenRequestAuthenticator {
class BasicAuthRequestAuthenticator extends BearerTokenRequestAuthenticator {

private static final String CHALLENGE_PREFIX = "Basic ";

Expand Down
Expand Up @@ -40,7 +40,7 @@
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @author <a href="mailto:fjuma@redhat.com">Farah Juma</a>
*/
public class BearerTokenRequestAuthenticator {
class BearerTokenRequestAuthenticator {
protected OidcHttpFacade facade;
protected OidcClientConfiguration oidcClientConfiguration;
protected AuthChallenge challenge;
Expand Down
Expand Up @@ -24,7 +24,7 @@
* @author <a href="mailto:john.ament@spartasystems.com">John D. Ament</a>
* @author <a href="mailto:fjuma@redhat.com">Farah Juma</a>
*/
public class QueryParameterTokenRequestAuthenticator extends BearerTokenRequestAuthenticator {
class QueryParameterTokenRequestAuthenticator extends BearerTokenRequestAuthenticator {
public static final String ACCESS_TOKEN = "access_token";

public QueryParameterTokenRequestAuthenticator(OidcHttpFacade facade, OidcClientConfiguration oidcClientConfiguration) {
Expand Down
Expand Up @@ -152,7 +152,7 @@ private AuthOutcome doAuthenticate() {
log.debug("NOT_ATTEMPTED: bearer only");
return AuthOutcome.NOT_ATTEMPTED;
}
if (isAutodetectedBearerOnly(facade.getRequest())) {
if (isAutodetectedBearerOnly()) {
challenge = bearer.getChallenge();
log.debug("NOT_ATTEMPTED: Treating as bearer only");
return AuthOutcome.NOT_ATTEMPTED;
Expand Down Expand Up @@ -214,7 +214,7 @@ protected void completeAuthentication(BearerTokenRequestAuthenticator bearer) {
log.debugv("User ''{0}'' invoking ''{1}'' on client ''{2}''", principal.getName(), facade.getRequest().getURI(), deployment.getResourceName());
}

protected boolean isAutodetectedBearerOnly(OidcHttpFacade.Request request) {
protected boolean isAutodetectedBearerOnly() {
if (! deployment.isAutodetectBearerOnly()) return false;

String headerValue = facade.getRequest().getHeader(X_REQUESTED_WITH);
Expand Down
Expand Up @@ -269,14 +269,8 @@ public static AccessAndIDTokenResponse getBearerToken(OidcClientConfiguration oi
if (entity == null) {
throw log.noMessageEntity();
}
InputStream is = entity.getContent();
try {
try (InputStream is = entity.getContent()) {
tokenResponse = JsonSerialization.readValue(is, AccessAndIDTokenResponse.class);
} finally {
try {
is.close();
} catch (java.io.IOException ignored) {
}
}
return tokenResponse;
}
Expand Down

0 comments on commit d950ffa

Please sign in to comment.