public String toIdentityString() { StringBuilder refString = new StringBuilder(); refString.append(IDENTITY_VERSION_1); refString.append(IDENTITY_SEPARATOR); refString.append(Base64.encode(accountUuid)); refString.append(IDENTITY_SEPARATOR); refString.append(Base64.encode(folderServerId)); refString.append(IDENTITY_SEPARATOR); refString.append(Base64.encode(uid)); if (flag != null) { refString.append(IDENTITY_SEPARATOR); refString.append(flag.name()); } return refString.toString(); }
private void saslAuthExternal() throws MessagingException, IOException { executeCommand("AUTH EXTERNAL %s", Base64.encode(username)); }
public static String encode(String s) { if (s == null) { return null; } byte[] encoded = new Base64().encode(s.getBytes()); return new String(encoded); }
/** * Encodes an Object using the base64 algorithm. This method is provided in order to satisfy the requirements of the * Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[]. * * @param pObject * Object to encode * @return An object (of type byte[]) containing the base64 encoded data which corresponds to the byte[] supplied. * @throws EncoderException * if the parameter supplied is not of type byte[] */ public Object encode(Object pObject) throws EncoderException { if (!(pObject instanceof byte[])) { throw new EncoderException("Parameter supplied to Base64 encode is not a byte[]"); } return encode((byte[]) pObject); }
authString = "Basic " + Base64.encode(username + ":" + password);
/** * Closes this output stream, flushing any remaining bytes that must be encoded. The * underlying stream is flushed but not closed. */ @Override public void close() throws IOException { // Notify encoder of EOF (-1). if (doEncode) { base64.encode(singleByte, 0, -1); } else { base64.decode(singleByte, 0, -1); } flush(); }
/** * Writes <code>len</code> bytes from the specified * <code>b</code> array starting at <code>offset</code> to * this output stream. * * @param b source byte array * @param offset where to start reading the bytes * @param len maximum number of bytes to write * * @throws IOException if an I/O error occurs. * @throws NullPointerException if the byte array parameter is null * @throws IndexOutOfBoundsException if offset, len or buffer size are invalid */ @Override public void write(byte b[], int offset, int len) throws IOException { if (b == null) { throw new NullPointerException(); } else if (offset < 0 || len < 0 || offset + len < 0) { throw new IndexOutOfBoundsException(); } else if (offset > b.length || offset + len > b.length) { throw new IndexOutOfBoundsException(); } else if (len > 0) { if (doEncode) { base64.encode(b, offset, len); } else { base64.decode(b, offset, len); } flush(false); } }
private void saslAuthLogin() throws MessagingException, IOException { try { executeCommand("AUTH LOGIN"); executeSensitiveCommand(Base64.encode(username)); executeSensitiveCommand(Base64.encode(password)); } catch (NegativeSmtpReplyException exception) { if (exception.getReplyCode() == SMTP_AUTHENTICATION_FAILURE_ERROR_CODE) { throw new AuthenticationFailedException("AUTH LOGIN failed (" + exception.getMessage() + ")"); } else { throw exception; } } }
private void authExternal() throws MessagingException { try { executeSimpleCommand( String.format("AUTH EXTERNAL %s", Base64.encode(settings.getUsername())), false); } catch (Pop3ErrorResponse e) { /* * Provide notification to the user of a problem authenticating * using client certificates. We don't use an * AuthenticationFailedException because that would trigger a * "Username or password incorrect" notification in * AccountSetupCheckSettings. */ throw new CertificateValidationException( "POP3 client certificate authentication failed: " + e.getMessage(), e); } }
private void saslAuthPlain() throws MessagingException, IOException { String data = Base64.encode("\000" + username + "\000" + password); try { executeSensitiveCommand("AUTH PLAIN %s", data); } catch (NegativeSmtpReplyException exception) { if (exception.getReplyCode() == SMTP_AUTHENTICATION_FAILURE_ERROR_CODE) { throw new AuthenticationFailedException("AUTH PLAIN failed (" + exception.getMessage() + ")"); } else { throw exception; } } }
private List<ImapResponse> saslAuthExternal() throws IOException, MessagingException { try { String command = Commands.AUTHENTICATE_EXTERNAL + " " + Base64.encode(settings.getUsername()); return executeSimpleCommand(command, false); } catch (NegativeImapResponseException e) { /* * Provide notification to the user of a problem authenticating * using client certificates. We don't use an * AuthenticationFailedException because that would trigger a * "Username or password incorrect" notification in * AccountSetupCheckSettings. */ throw new CertificateValidationException(e.getMessage()); } }
URI newUri = new URI(uri.getScheme(), newUserInfo, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); String newTransportUriStr = Base64.encode(newUri.toString()); migrationsHelper.writeValue(db, uuid + ".transportUri", newTransportUriStr); URI newUri = new URI(uri.getScheme(), newUserInfo, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); String newStoreUriStr = Base64.encode(newUri.toString()); migrationsHelper.writeValue(db, uuid + ".storeUri", newStoreUriStr);
@Test public void checkSettings_withInitialUnauthorizedResponse_shouldPerformBasicAuthentication() throws Exception { configureHttpResponses(UNAUTHORIZED_401_RESPONSE, OK_200_RESPONSE); webDavStore.checkSettings(); List<HttpGeneric> requests = requestCaptor.getAllValues(); assertEquals(2, requests.size()); assertEquals("GET", requests.get(0).getMethod()); assertEquals("GET", requests.get(1).getMethod()); assertEquals("Basic " + Base64.encode("user:password"), requests.get(1).getHeaders("Authorization")[0].getValue()); }
BackendManager backendManager = DI.get(BackendManager.class); String storeUri = backendManager.createStoreUri(incoming); putString(editor, accountKeyPrefix + AccountPreferenceSerializer.STORE_URI_KEY, Base64.encode(storeUri)); putString(editor, accountKeyPrefix + AccountPreferenceSerializer.TRANSPORT_URI_KEY, Base64.encode(transportUri));
@Test public void open_withCramMd5AuthExtension() throws Exception { MockSmtpServer server = new MockSmtpServer(); server.output("220 localhost Simple Mail Transfer Service Ready"); server.expect("EHLO [127.0.0.1]"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH CRAM-MD5"); server.expect("AUTH CRAM-MD5"); server.output(Base64.encode("<24609.1047914046@localhost>")); server.expect("dXNlciA3NmYxNWEzZmYwYTNiOGI1NzcxZmNhODZlNTcyMDk2Zg=="); server.output("235 2.7.0 Authentication successful"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.CRAM_MD5, ConnectionSecurity.NONE); transport.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); }
@Test public void open_withAutomaticAuthAndNoTransportSecurityAndAuthCramMd5Extension_shouldUseAuthCramMd5() throws Exception { MockSmtpServer server = new MockSmtpServer(); server.output("220 localhost Simple Mail Transfer Service Ready"); server.expect("EHLO [127.0.0.1]"); server.output("250-localhost Hello client.localhost"); server.output("250 AUTH CRAM-MD5"); server.expect("AUTH CRAM-MD5"); server.output(Base64.encode("<24609.1047914046@localhost>")); server.expect("dXNlciA3NmYxNWEzZmYwYTNiOGI1NzcxZmNhODZlNTcyMDk2Zg=="); server.output("235 2.7.0 Authentication successful"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.AUTOMATIC, ConnectionSecurity.NONE); transport.open(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); }