/** * Decode credentials encoded in base 64 (in the form of "username:password"), as they have been * sent by a RemoteObject. * * @param credentials base 64 encoded credentials. * @return an array containing two decoded Strings, username and password. * @throws IllegalArgumentException if credentials isn't a String. * @throws SecurityServiceException if credentials are invalid (bad encoding or missing ':'). */ protected String[] decodeBase64Credentials(Object credentials, String charset) { if (!(credentials instanceof String)) throw new IllegalArgumentException("Credentials should be a non null String: " + (credentials != null ? credentials.getClass().getName() : null)); if (charset == null) charset = "ISO-8859-1"; byte[] bytes = Base64.decode((String)credentials); String decoded; try { decoded = new String(bytes, charset); } catch (UnsupportedEncodingException e) { throw SecurityServiceException.newInvalidCredentialsException("ISO-8859-1 encoding not supported ???"); } int colon = decoded.indexOf(':'); if (colon == -1) throw SecurityServiceException.newInvalidCredentialsException("No colon"); return new String[] {decoded.substring(0, colon), decoded.substring(colon + 1)}; }