Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[guava2java] Use java.util.Base64 with java 8 #487

Merged
merged 1 commit into from
Jan 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Waffle (https://github.com/Waffle/waffle)
*
* Copyright (c) 2010-2016 Application Security, Inc.
* Copyright (c) 2010-2017 Application Security, Inc.
*
* All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at
Expand All @@ -14,6 +14,7 @@
import java.io.IOException;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Iterator;
import java.util.List;

Expand All @@ -23,8 +24,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.io.BaseEncoding;

import waffle.util.AuthorizationHeader;
import waffle.util.NtlmServletRequest;
import waffle.windows.auth.IWindowsAuthProvider;
Expand Down Expand Up @@ -146,7 +145,7 @@ public IWindowsIdentity doFilter(final HttpServletRequest request, final HttpSer

final byte[] continueTokenBytes = securityContext.getToken();
if (continueTokenBytes != null && continueTokenBytes.length > 0) {
final String continueToken = BaseEncoding.base64().encode(continueTokenBytes);
final String continueToken = Base64.getEncoder().encodeToString(continueTokenBytes);
NegotiateSecurityFilterProvider.LOGGER.debug("continue token: {}", continueToken);
response.addHeader(NegotiateSecurityFilterProvider.WWW_AUTHENTICATE, securityPackage + " " + continueToken);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Waffle (https://github.com/Waffle/waffle)
*
* Copyright (c) 2010-2016 Application Security, Inc.
* Copyright (c) 2010-2017 Application Security, Inc.
*
* All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at
Expand All @@ -11,13 +11,13 @@
*/
package waffle.util;

import java.util.Base64;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.io.BaseEncoding;

/**
* Authorization header.
*
Expand Down Expand Up @@ -104,7 +104,7 @@ public String getToken() {
*/
public byte[] getTokenBytes() {
try {
return BaseEncoding.base64().decode(this.getToken());
return Base64.getDecoder().decode(this.getToken());
} catch (final IllegalArgumentException e) {
AuthorizationHeader.LOGGER.debug("", e);
throw new RuntimeException("Invalid authorization header.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Waffle (https://github.com/Waffle/waffle)
*
* Copyright (c) 2010-2016 Application Security, Inc.
* Copyright (c) 2010-2017 Application Security, Inc.
*
* All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at
Expand Down Expand Up @@ -59,7 +59,7 @@
*
* <pre>
* <code>
* java -cp "jna.jar;waffle-core.jar;waffle-api.jar;jna-platform.jar;guava-17.0.jar" waffle.util.WaffleInfo
* java -cp "jna.jar;waffle-core.jar;waffle-api.jar;jna-platform.jar;guava-21.0.jar" waffle.util.WaffleInfo
* </code>
* </pre>
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Waffle (https://github.com/Waffle/waffle)
*
* Copyright (c) 2010-2016 Application Security, Inc.
* Copyright (c) 2010-2017 Application Security, Inc.
*
* All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at
Expand All @@ -13,6 +13,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

/**
Expand All @@ -37,8 +38,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.io.BaseEncoding;

import waffle.util.AuthorizationHeader;
import waffle.util.NtlmServletRequest;

Expand Down Expand Up @@ -120,7 +119,7 @@ protected boolean isRememberMe(final ServletRequest request) {
protected AuthenticationToken createToken(final ServletRequest request, final ServletResponse response) {
final String authorization = this.getAuthzHeader(request);
final String[] elements = authorization.split(" ");
final byte[] inToken = BaseEncoding.base64().decode(elements[1]);
final byte[] inToken = Base64.getDecoder().decode(elements[1]);

// maintain a connection-based session for NTLM tokens
// TODO see about changing this parameter to ServletRequest in waffle
Expand Down Expand Up @@ -392,7 +391,7 @@ private void sendUnauthorized(final List<String> protocols, final byte[] out, fi
if (out == null || out.length == 0) {
response.addHeader("WWW-Authenticate", protocol);
} else {
response.setHeader("WWW-Authenticate", protocol + " " + BaseEncoding.base64().encode(out));
response.setHeader("WWW-Authenticate", protocol + " " + Base64.getEncoder().encodeToString(out));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Waffle (https://github.com/Waffle/waffle)
*
* Copyright (c) 2010-2016 Application Security, Inc.
* Copyright (c) 2010-2017 Application Security, Inc.
*
* All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at
Expand All @@ -11,6 +11,7 @@
*/
package waffle.shiro.negotiate;

import java.util.Base64;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;
Expand All @@ -21,7 +22,6 @@
import org.mockito.Mockito;

import com.google.common.base.Joiner;
import com.google.common.io.BaseEncoding;

import mockit.Deencapsulation;
import mockit.Tested;
Expand Down Expand Up @@ -74,7 +74,7 @@ public void testSendChallengeDuringNegotiate() {

this.negAuthFilter.sendChallengeDuringNegotiate(myProtocol, this.response, this.out);

Assert.assertEquals(Joiner.on(" ").join(myProtocol, BaseEncoding.base64().encode(this.out)),
Assert.assertEquals(Joiner.on(" ").join(myProtocol, Base64.getEncoder().encodeToString(this.out)),
this.response.headers.get("WWW-Authenticate"));

Assert.assertEquals("keep-alive", this.response.headers.get("Connection"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Waffle (https://github.com/Waffle/waffle)
*
* Copyright (c) 2010-2016 Application Security, Inc.
* Copyright (c) 2010-2017 Application Security, Inc.
*
* All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at
Expand All @@ -14,6 +14,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
Expand All @@ -32,8 +33,6 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;

import com.google.common.io.BaseEncoding;

import waffle.mock.http.SimpleFilterChain;
import waffle.mock.http.SimpleHttpRequest;
import waffle.mock.http.SimpleHttpResponse;
Expand Down Expand Up @@ -101,8 +100,8 @@ public void testNegotiate() throws IOException, ServletException {
final SimpleFilterChain filterChain = new SimpleFilterChain();
final SimpleHttpRequest request = new SimpleHttpRequest();

final String clientToken = BaseEncoding.base64()
.encode(WindowsAccountImpl.getCurrentUsername().getBytes(StandardCharsets.UTF_8));
final String clientToken = Base64.getEncoder()
.encodeToString(WindowsAccountImpl.getCurrentUsername().getBytes(StandardCharsets.UTF_8));
request.addHeader("Authorization", securityPackage + " " + clientToken);

final SimpleHttpResponse response = new SimpleHttpResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
package waffle.spring;

import com.google.common.io.BaseEncoding;
import com.sun.jna.WString;
import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.LMAccess;
Expand All @@ -37,6 +36,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.Principal;
import java.util.Base64;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
Expand Down Expand Up @@ -104,7 +104,7 @@ public void testImpersonateEnabled() throws IOException, ServletException {
request.setMethod("GET");
final String userHeaderValue = MockWindowsAccount.TEST_USER_NAME + ":" + MockWindowsAccount.TEST_PASSWORD;
final String basicAuthHeader = "Basic "
+ BaseEncoding.base64().encode(userHeaderValue.getBytes(StandardCharsets.UTF_8));
+ Base64.getEncoder().encodeToString(userHeaderValue.getBytes(StandardCharsets.UTF_8));
request.addHeader("Authorization", basicAuthHeader);

final SimpleHttpResponse response = new SimpleHttpResponse();
Expand Down Expand Up @@ -146,7 +146,7 @@ public void testImpersonateDisabled() throws IOException, ServletException {
request.setMethod("GET");
final String userHeaderValue = MockWindowsAccount.TEST_USER_NAME + ":" + MockWindowsAccount.TEST_PASSWORD;
final String basicAuthHeader = "Basic "
+ BaseEncoding.base64().encode(userHeaderValue.getBytes(StandardCharsets.UTF_8));
+ Base64.getEncoder().encodeToString(userHeaderValue.getBytes(StandardCharsets.UTF_8));
request.addHeader("Authorization", basicAuthHeader);
final SimpleHttpResponse response = new SimpleHttpResponse();
final RecordUserNameFilterChain filterChain = new RecordUserNameFilterChain();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Waffle (https://github.com/Waffle/waffle)
*
* Copyright (c) 2010-2016 Application Security, Inc.
* Copyright (c) 2010-2017 Application Security, Inc.
*
* All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at
Expand All @@ -14,6 +14,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
Expand All @@ -32,8 +33,6 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;

import com.google.common.io.BaseEncoding;

import waffle.mock.http.SimpleFilterChain;
import waffle.mock.http.SimpleHttpRequest;
import waffle.mock.http.SimpleHttpResponse;
Expand Down Expand Up @@ -136,8 +135,8 @@ public void testNegotiate() throws IOException, ServletException {
final SimpleFilterChain filterChain = new SimpleFilterChain();
final SimpleHttpRequest request = new SimpleHttpRequest();

final String clientToken = BaseEncoding.base64()
.encode(WindowsAccountImpl.getCurrentUsername().getBytes(StandardCharsets.UTF_8));
final String clientToken = Base64.getEncoder()
.encodeToString(WindowsAccountImpl.getCurrentUsername().getBytes(StandardCharsets.UTF_8));
request.addHeader("Authorization", securityPackage + " " + clientToken);

final SimpleHttpResponse response = new SimpleHttpResponse();
Expand Down Expand Up @@ -194,7 +193,7 @@ public void testGuestIsDisabled() throws IOException, ServletException {
final SimpleFilterChain filterChain = new SimpleFilterChain();
final SimpleHttpRequest request = new SimpleHttpRequest();

final String clientToken = BaseEncoding.base64().encode("Guest".getBytes(StandardCharsets.UTF_8));
final String clientToken = Base64.getEncoder().encodeToString("Guest".getBytes(StandardCharsets.UTF_8));
request.addHeader("Authorization", securityPackage + " " + clientToken);

final SimpleHttpResponse response = new SimpleHttpResponse();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Waffle (https://github.com/Waffle/waffle)
*
* Copyright (c) 2010-2016 Application Security, Inc.
* Copyright (c) 2010-2017 Application Security, Inc.
*
* All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at
Expand All @@ -13,6 +13,7 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

import javax.security.auth.Subject;
import javax.servlet.FilterChain;
Expand All @@ -24,8 +25,6 @@
import org.junit.Before;
import org.junit.Test;

import com.google.common.io.BaseEncoding;

import waffle.mock.MockWindowsAuthProvider;
import waffle.mock.http.SimpleFilterChain;
import waffle.mock.http.SimpleHttpRequest;
Expand Down Expand Up @@ -78,7 +77,7 @@ public void testBasicAuth() throws IOException, ServletException {

final String userHeaderValue = WindowsAccountImpl.getCurrentUsername() + ":password";
final String basicAuthHeader = "Basic "
+ BaseEncoding.base64().encode(userHeaderValue.getBytes(StandardCharsets.UTF_8));
+ Base64.getEncoder().encodeToString(userHeaderValue.getBytes(StandardCharsets.UTF_8));
request.addHeader("Authorization", basicAuthHeader);

final SimpleHttpResponse response = new SimpleHttpResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.Principal;
import java.util.Base64;

import javax.security.auth.Subject;
import javax.servlet.ServletException;
Expand All @@ -23,7 +24,6 @@
import org.junit.Before;
import org.junit.Test;

import com.google.common.io.BaseEncoding;
import com.sun.jna.WString;
import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.LMAccess;
Expand Down Expand Up @@ -104,7 +104,7 @@ public void testImpersonateEnabled() throws IOException, ServletException {
request.setMethod("GET");
final String userHeaderValue = MockWindowsAccount.TEST_USER_NAME + ":" + MockWindowsAccount.TEST_PASSWORD;
final String basicAuthHeader = "Basic "
+ BaseEncoding.base64().encode(userHeaderValue.getBytes(StandardCharsets.UTF_8));
+ Base64.getEncoder().encodeToString(userHeaderValue.getBytes(StandardCharsets.UTF_8));
request.addHeader("Authorization", basicAuthHeader);

final SimpleHttpResponse response = new SimpleHttpResponse();
Expand Down Expand Up @@ -151,7 +151,7 @@ public void testImpersonateDisabled() throws IOException, ServletException {
request.setMethod("GET");
final String userHeaderValue = MockWindowsAccount.TEST_USER_NAME + ":" + MockWindowsAccount.TEST_PASSWORD;
final String basicAuthHeader = "Basic "
+ BaseEncoding.base64().encode(userHeaderValue.getBytes(StandardCharsets.UTF_8));
+ Base64.getEncoder().encodeToString(userHeaderValue.getBytes(StandardCharsets.UTF_8));
request.addHeader("Authorization", basicAuthHeader);
final SimpleHttpResponse response = new SimpleHttpResponse();
final RecordUserNameFilterChain filterChain = new RecordUserNameFilterChain();
Expand Down
Loading