/** * @return the password, decoded format * @throws UnsupportedEncodingException Shouldn't be thrown since * constructor already checks for it. */ public String decodePassword() throws UnsupportedEncodingException { if (password.startsWith("{base64}")) { return new String(Base64.decode(password.substring("{base64}".length()).toCharArray()), "UTF-8"); } else { return password; } }
/** * Saves the authentication information. * @param username user name * @param password password, may be encoded in the following formats: * - None, don't prefix at all * - Encoded using base64, prefix with {base64} * @throws UnsupportedEncodingException If password is not base64 encoded UTF-8 */ public AuthenticationInformation(String username, String password) throws UnsupportedEncodingException { if (password.startsWith("{base64}")) { try { new String(Base64.decode(password.substring("{base64}".length()).toCharArray()), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new UnsupportedEncodingException("The given password is not a UTF-8 string encoded in base64"); } } else { logger.log(BasicLevel.WARN, "The password for the user " + username + " is in clear text!"); } this.password = password; this.username = username; }