use of org.apache.commons.codec.binary.Base64.encodeBase64String in project archiva by apache.
the class RssFeedServletTest method testInvalidAuthenticationRequest.
@Test
public void testInvalidAuthenticationRequest() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/feeds/unauthorized-repo");
request.addHeader("User-Agent", "Apache Archiva unit test");
request.setMethod("GET");
Encoder encoder = new Base64();
String userPass = "unauthUser:unauthPass";
String encodedUserPass = new String((byte[]) encoder.encode(userPass.getBytes()));
request.addHeader("Authorization", "BASIC " + encodedUserPass);
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
rssFeedServlet.doGet(request, mockHttpServletResponse);
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus());
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project archiva by apache.
the class RssFeedServletTest method testRequestNewArtifactsInRepo.
@Test
public void testRequestNewArtifactsInRepo() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/feeds/test-repo");
request.addHeader("User-Agent", "Apache Archiva unit test");
request.setMethod("GET");
Base64 encoder = new Base64(0, new byte[0]);
String userPass = "user1:password1";
String encodedUserPass = encoder.encodeToString(userPass.getBytes());
request.addHeader("Authorization", "BASIC " + encodedUserPass);
MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
rssFeedServlet.doGet(request, mockHttpServletResponse);
assertEquals(RssFeedServlet.MIME_TYPE, mockHttpServletResponse.getHeader("CONTENT-TYPE"));
assertNotNull("Should have recieved a response", mockHttpServletResponse.getContentAsString());
assertEquals("Should have been an OK response code.", HttpServletResponse.SC_OK, mockHttpServletResponse.getStatus());
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project oozie by apache.
the class TestAuthFilterAuthOozieClient method computeSignature.
// Borrowed from org.apache.hadoop.security.authentication.util.Signer#computeSignature
private static String computeSignature(byte[] secret, String str) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(str.getBytes());
md.update(secret);
byte[] digest = md.digest();
return new Base64(0).encodeToString(digest);
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project light-4j by networknt.
the class HashUtil method generateUUID.
public static String generateUUID() {
UUID id = UUID.randomUUID();
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(id.getMostSignificantBits());
bb.putLong(id.getLeastSignificantBits());
Base64 base64 = new Base64();
return base64.encodeBase64URLSafeString(bb.array());
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project CBEC-B2B by A-Cubic.
the class Util method decryptBASE64.
public static byte[] decryptBASE64(String strBase64) throws Exception {
Base64 base64 = new Base64();
String newStr = strBase64.replaceAll("^(data:\\s*image\\/(\\w+);base64,)", "");
// data:application/pdf;base64,
byte[] debytes = base64.decode(newStr);
return debytes;
// Decoder decoder = Base64.getDecoder();
// byte[] buffer = decoder.decode(newStr);
// return buffer;
}
Aggregations