Skip to content

Commit

Permalink
Rename class to HttpHeaderValues
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Sep 11, 2018
1 parent 7bc612f commit 74e597e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 32 deletions.
14 changes: 0 additions & 14 deletions http/src/main/java/io/micronaut/http/HttpHeaderAuthorization.java

This file was deleted.

36 changes: 36 additions & 0 deletions http/src/main/java/io/micronaut/http/HttpHeaderValues.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2017-2018 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.micronaut.http;

/**
* Interface for common HTTP header values.
*
* @author graemerocher
* @since 1.0
*/
public interface HttpHeaderValues {

/**
* {@code "Bearer "}.
*/
String AUTHORIZATION_PREFIX_BEARER = "Bearer";

/**
* {@code "Basic "}.
*/
String AUTHORIZATION_PREFIX_BASIC = "Basic";
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ default MutableHttpHeaders auth(String username, String password) {
*/
default MutableHttpHeaders auth(String userInfo) {
StringBuilder sb = new StringBuilder();
sb.append(HttpHeaderAuthorization.AUTHORIZATION_PREFIX_BASIC);
sb.append(HttpHeaderValues.AUTHORIZATION_PREFIX_BASIC);
sb.append(" ");
sb.append(Base64.getEncoder().encodeToString((userInfo).getBytes(StandardCharsets.ISO_8859_1)));
String token = sb.toString();
Expand Down
15 changes: 9 additions & 6 deletions http/src/main/java/io/micronaut/http/MutableHttpMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,22 @@ default MutableHttpMessage<B> basicAuth(CharSequence username, CharSequence pass
sb.append(":");
sb.append(password);
final StringBuilder value = new StringBuilder();
value.append(HttpHeaderAuthorization.AUTHORIZATION_PREFIX_BASIC);
value.append(HttpHeaderValues.AUTHORIZATION_PREFIX_BASIC);
value.append(" ");
value.append(new String(Base64.getEncoder().encode(sb.toString().getBytes())));
header(HttpHeaders.AUTHORIZATION, value.toString());
return this;
}

/**
* Set an {@link HttpHeaders#AUTHORIZATION} header, with value: "Bearer token".
*
* @param token The token
* @return This response
*/
default MutableHttpMessage<B> bearerAuth(CharSequence token) {
final StringBuilder sb = new StringBuilder();
sb.append(HttpHeaderAuthorization.AUTHORIZATION_PREFIX_BEARER);
sb.append(" ");
sb.append(token);
header(HttpHeaders.AUTHORIZATION, sb.toString());
String sb = HttpHeaderValues.AUTHORIZATION_PREFIX_BEARER + " " + token;
header(HttpHeaders.AUTHORIZATION, sb);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.micronaut.security.token.jwt.bearer;

import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.http.HttpHeaderAuthorization;
import io.micronaut.http.HttpHeaderValues;
import io.micronaut.http.HttpHeaders;
import io.micronaut.security.token.jwt.config.JwtConfigurationProperties;

Expand All @@ -36,7 +36,7 @@ public class BearerTokenConfigurationProperties implements BearerTokenConfigurat

private boolean enabled = DEFAULT_ENABLED;
private String headerName = HttpHeaders.AUTHORIZATION;
private String prefix = HttpHeaderAuthorization.AUTHORIZATION_PREFIX_BEARER;
private String prefix = HttpHeaderValues.AUTHORIZATION_PREFIX_BEARER;

@Override
public boolean isEnabled() {
Expand Down Expand Up @@ -73,7 +73,7 @@ public void setHeaderName(String headerName) {
}

/**
* Sets the prefix to use for the auth token. Default value {@value io.micronaut.http.HttpHeaderAuthorization#AUTHORIZATION_PREFIX_BEARER}
* Sets the prefix to use for the auth token. Default value {@value HttpHeaderValues#AUTHORIZATION_PREFIX_BEARER}
* @param prefix The prefix to use
*/
public void setPrefix(String prefix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.micronaut.security.token.jwt.render;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.http.HttpHeaderAuthorization;
import io.micronaut.http.HttpHeaderValues;

import java.util.Collection;
import java.util.List;
Expand All @@ -36,7 +36,7 @@ public class BearerAccessRefreshToken extends AccessRefreshToken {
private Integer expiresIn;

@JsonProperty("token_type")
private String tokenType = HttpHeaderAuthorization.AUTHORIZATION_PREFIX_BEARER;
private String tokenType = HttpHeaderValues.AUTHORIZATION_PREFIX_BEARER;

/**
* Necessary for JSON serialization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.context.annotation.Requires;
import io.micronaut.http.HttpHeaderAuthorization;
import io.micronaut.http.HttpHeaderValues;
import io.micronaut.http.HttpHeaders;
import io.micronaut.security.token.config.TokenConfigurationProperties;

Expand All @@ -42,7 +42,7 @@ public class BasicAuthTokenReaderConfigurationProperties implements BasicAuthTok

private boolean enabled = DEFAULT_ENABLED;
private String headerName = HttpHeaders.AUTHORIZATION;
private String prefix = HttpHeaderAuthorization.AUTHORIZATION_PREFIX_BASIC;
private String prefix = HttpHeaderValues.AUTHORIZATION_PREFIX_BASIC;

@Override
public boolean isEnabled() {
Expand Down Expand Up @@ -78,7 +78,7 @@ public void setHeaderName(String headerName) {
}

/**
* Http Header value prefix. Default value {@value io.micronaut.http.HttpHeaderAuthorization#AUTHORIZATION_PREFIX_BASIC}.
* Http Header value prefix. Default value {@value HttpHeaderValues#AUTHORIZATION_PREFIX_BASIC}.
* @param prefix The prefix to use
*/
public void setPrefix(String prefix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.micronaut.security.token.writer;

import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.http.HttpHeaderAuthorization;
import io.micronaut.http.HttpHeaderValues;
import io.micronaut.http.HttpHeaders;
import io.micronaut.security.token.config.TokenConfigurationProperties;

Expand All @@ -37,7 +37,7 @@ public class HttpHeaderTokenWriterConfigurationProperties implements HttpHeaderT
@SuppressWarnings("WeakerAccess")
public static final boolean DEFAULT_ENABLED = true;

private String prefix = HttpHeaderAuthorization.AUTHORIZATION_PREFIX_BEARER;
private String prefix = HttpHeaderValues.AUTHORIZATION_PREFIX_BEARER;
private String headerName = HttpHeaders.AUTHORIZATION;
private boolean enabled = DEFAULT_ENABLED;

Expand All @@ -55,7 +55,7 @@ public void setEnabled(boolean enabled) {
}

/**
* Value prefix for Http Header. Default value {@value io.micronaut.http.HttpHeaderAuthorization#AUTHORIZATION_PREFIX_BEARER}
* Value prefix for Http Header. Default value {@value HttpHeaderValues#AUTHORIZATION_PREFIX_BEARER}
* @param prefix preffix before the header value
*/
public void setPrefix(String prefix) {
Expand Down

0 comments on commit 74e597e

Please sign in to comment.