public static String getBasicAuthHeader(String userName, String passwd, boolean useIso8859) { String userAndPass = userName + ":" + passwd; byte[] authBytes = useIso8859 ? userAndPass.getBytes(StandardCharsets.ISO_8859_1) : userAndPass.getBytes(); return "Basic " + Base64Utility.encode(authBytes); }
public String getAuthorization(AuthorizationPolicy authPolicy, URI currentURI, Message message) { if (!HttpAuthHeader.AUTH_TYPE_NEGOTIATE.equals(authPolicy.getAuthorizationType())) { return null; } try { String spn = getCompleteServicePrincipalName(currentURI); boolean useKerberosOid = MessageUtils.getContextualBoolean(message, PROPERTY_USE_KERBEROS_OID); Oid oid = new Oid(useKerberosOid ? KERBEROS_OID : SPNEGO_OID); byte[] token = getToken(authPolicy, spn, oid, message); return HttpAuthHeader.AUTH_TYPE_NEGOTIATE + " " + Base64Utility.encode(token); } catch (LoginException | GSSException e) { throw new RuntimeException(e.getMessage(), e); } }
public static String encodeCertificate(Certificate cert) { try { return Base64Utility.encode(cert.getEncoded()); } catch (Exception ex) { throw new SecurityException(ex); } } public static Certificate decodeCertificate(String encodedCert) {
public static String getBasicAuthHeader(String userName, String passwd, boolean useIso8859) { String userAndPass = userName + ":" + passwd; byte[] authBytes = useIso8859 ? userAndPass.getBytes(StandardCharsets.ISO_8859_1) : userAndPass.getBytes(); return "Basic " + Base64Utility.encode(authBytes); }
private static String generateNonce() { byte[] randomBytes = new byte[20]; new SecureRandom().nextBytes(randomBytes); return Base64Utility.encode(randomBytes); }
private static String generateNonce() { byte[] randomBytes = new byte[20]; new SecureRandom().nextBytes(randomBytes); return Base64Utility.encode(randomBytes); }
public static String encodeCertificate(Certificate cert) { try { return Base64Utility.encode(cert.getEncoded()); } catch (Exception ex) { throw new SecurityException(ex); } } public static Certificate decodeCertificate(String encodedCert) {
public static InputStream getStreamFromSecureConnection(URL url, String authorizationValue) throws IOException { HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("GET"); String encodedAuth = "Basic " + Base64Utility.encode(authorizationValue.getBytes()); conn.setRequestProperty("Authorization", encodedAuth); return conn.getInputStream(); } }
protected String encodeToken(String assertion) throws Base64Exception { byte[] tokenBytes = assertion.getBytes(StandardCharsets.UTF_8); if (useDeflateEncoding) { tokenBytes = new DeflateEncoderDecoder().deflateToken(tokenBytes); } StringWriter writer = new StringWriter(); Base64Utility.encode(tokenBytes, 0, tokenBytes.length, writer); return writer.toString(); } }
protected String encodeResponse(Element response) throws IOException { String responseMessage = DOM2Writer.nodeToString(response); LOG.debug("Created Response: {}", responseMessage); if (supportDeflateEncoding) { DeflateEncoderDecoder encoder = new DeflateEncoderDecoder(); byte[] deflatedBytes = encoder.deflateToken(responseMessage.getBytes(StandardCharsets.UTF_8)); return Base64Utility.encode(deflatedBytes); } return Base64Utility.encode(responseMessage.getBytes()); }
protected String encodeToken(String assertion) throws Base64Exception { byte[] tokenBytes = assertion.getBytes(StandardCharsets.UTF_8); if (useDeflateEncoding) { tokenBytes = CompressionUtils.deflate(tokenBytes, getDeflateLevel(), true); } StringWriter writer = new StringWriter(); Base64Utility.encode(tokenBytes, 0, tokenBytes.length, writer); return writer.toString(); }
protected String encodeToken(String assertion) throws Base64Exception { byte[] tokenBytes = assertion.getBytes(StandardCharsets.UTF_8); if (useDeflateEncoding) { tokenBytes = new DeflateEncoderDecoder().deflateToken(tokenBytes); } StringWriter writer = new StringWriter(); Base64Utility.encode(tokenBytes, 0, tokenBytes.length, writer); return writer.toString(); } }
private String createUserPass(String usr, String pwd) { String userpass = usr + ":" + pwd; String token = Base64Utility.encode(userpass.getBytes()); return "Basic " + token; }
public static String encode( String uid, String password ) { return "Basic " + Base64Utility.encode( ( uid + ":" + password ).getBytes() ); }
protected String encodeAuthnRequest(Element authnRequest) throws IOException { String requestMessage = DOM2Writer.nodeToString(authnRequest); byte[] deflatedBytes = null; // Not correct according to the spec but required by some IDPs. if (useDeflateEncoding) { DeflateEncoderDecoder encoder = new DeflateEncoderDecoder(); deflatedBytes = encoder.deflateToken(requestMessage.getBytes(StandardCharsets.UTF_8)); } else { deflatedBytes = requestMessage.getBytes(StandardCharsets.UTF_8); } return Base64Utility.encode(deflatedBytes); }
public static String encodeHmacString(String macSecret, String macAlgoJavaName, String data, boolean urlSafe) { byte[] bytes = computeHmac(macSecret, macAlgoJavaName, data); return urlSafe ? Base64UrlUtility.encode(bytes) : Base64Utility.encode(bytes); }
protected String encodeAuthnRequest(Element authnRequest) throws IOException { String requestMessage = DOM2Writer.nodeToString(authnRequest); DeflateEncoderDecoder encoder = new DeflateEncoderDecoder(); byte[] deflatedBytes = encoder.deflateToken(requestMessage.getBytes(StandardCharsets.UTF_8)); return Base64Utility.encode(deflatedBytes); }
private void verifyAttachment(List<Element> atts, String contentId, String value) { for (Element expElem : atts) { String child = expElem.getFirstChild().getNodeValue(); String contentIdVal = expElem.getAttribute("contentId"); if (contentId.equals(contentIdVal) && (Base64Utility.encode(value.getBytes()).equals(child) || Base64Utility.encode((value + "\n").getBytes()).equals(child))) { return; } } fail("No encoded attachment with id " + contentId + " found"); } }
private String encodeToken(String assertion) throws Base64Exception { byte[] tokenBytes = assertion.getBytes(StandardCharsets.UTF_8); tokenBytes = new DeflateEncoderDecoder().deflateToken(tokenBytes); StringWriter writer = new StringWriter(); Base64Utility.encode(tokenBytes, 0, tokenBytes.length, writer); return writer.toString(); } }
private void registerCert(Client client) throws Exception { Certificate cert = loadCert(); String encodedCert = Base64Utility.encode(cert.getEncoded()); client.setApplicationCertificates(Collections.singletonList(encodedCert)); }