org.apache.commons.httpclient.auth.AuthenticationException.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(87)

本文整理了Java中org.apache.commons.httpclient.auth.AuthenticationException.<init>()方法的一些代码示例,展示了AuthenticationException.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AuthenticationException.<init>()方法的具体详情如下:
包路径:org.apache.commons.httpclient.auth.AuthenticationException
类名称:AuthenticationException
方法名:<init>

AuthenticationException.<init>介绍

[英]Creates a new AuthenticationException with a null detail message.
[中]使用空详细信息消息创建新的AuthenticationException。

代码示例

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Encrypt the data.
 * @param key The key.
 * @param bytes The data
 * @return byte[] The encrypted data
 * @throws HttpException If {@link Cipher.doFinal(byte[])} fails
 */
private byte[] encrypt(byte[] key, byte[] bytes)
  throws AuthenticationException {
  Cipher ecipher = getCipher(key);
  try {
    byte[] enc = ecipher.doFinal(bytes);
    return enc;
  } catch (IllegalBlockSizeException e) {
    throw new AuthenticationException("Invalid block size for DES encryption.", e);
  } catch (BadPaddingException e) {
    throw new AuthenticationException("Data not padded correctly for DES encryption.", e);
  }
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Return the cipher for the specified key.
 * @param key The key.
 * @return Cipher The cipher.
 * @throws AuthenticationException If the cipher cannot be retrieved.
 */
private Cipher getCipher(byte[] key) throws AuthenticationException {
  try {
    final Cipher ecipher = Cipher.getInstance("DES/ECB/NoPadding");
    key = setupKey(key);
    ecipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "DES"));
    return ecipher;
  } catch (NoSuchAlgorithmException e) {
    throw new AuthenticationException("DES encryption is not available.", e);
  } catch (InvalidKeyException e) {
    throw new AuthenticationException("Invalid key for DES encryption.", e);
  } catch (NoSuchPaddingException e) {
    throw new AuthenticationException(
      "NoPadding option for DES is not available.", e);
  }
}

代码示例来源:origin: commons-httpclient/commons-httpclient

throw new AuthenticationException(
    "Unsupported qop in HTTP Digest authentication");   
  md5Helper = MessageDigest.getInstance(digAlg);
} catch (Exception e) {
  throw new AuthenticationException(
   "Unsupported algorithm in HTTP Digest authentication: "
    + digAlg);

代码示例来源:origin: commons-httpclient/commons-httpclient

throw new AuthenticationException(id + 
  " authorization challenge expected, but not found");

代码示例来源:origin: org.zaproxy/zap

/** Read a byte from a position within the message buffer */
protected byte readByte(final int position) throws AuthenticationException {
  if (messageContents.length < position + 1) {
    throw new AuthenticationException("NTLM: Message too short");
  }
  return messageContents[position];
}

代码示例来源:origin: org.zaproxy/zap

/**
 * Find the character set based on the flags.
 * @param flags is the flags.
 * @return the character set.
 */
private static Charset getCharset(final int flags) throws AuthenticationException
{
  if ((flags & FLAG_REQUEST_UNICODE_ENCODING) == 0) {
    return DEFAULT_CHARSET;
  } else {
    if (UNICODE_LITTLE_UNMARKED == null) {
      throw new AuthenticationException( "Unicode not supported" );
    }
    return UNICODE_LITTLE_UNMARKED;
  }
}

代码示例来源:origin: org.zaproxy/zap

/** Read a bunch of bytes from a position in the message buffer */
protected void readBytes(final byte[] buffer, final int position) throws AuthenticationException {
  if (messageContents.length < position + buffer.length) {
    throw new AuthenticationException("NTLM: Message too short");
  }
  System.arraycopy(messageContents, position, buffer, 0, buffer.length);
}

代码示例来源:origin: org.apache.abdera/abdera-extensions-wsse

private String generateNonce() throws AuthenticationException {
  try {
    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
    byte[] temp = new byte[NONCE_LENGTH];
    sr.nextBytes(temp);
    String n = new String(Hex.encodeHex(temp));
    return n;
  } catch (Exception e) {
    throw new AuthenticationException(e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.abdera/abdera-extensions-oauth

private String generateNonce() throws AuthenticationException {
  try {
    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
    byte[] temp = new byte[NONCE_LENGTH];
    sr.nextBytes(temp);
    String n = new String(Hex.encodeHex(temp));
    return n;
  } catch (Exception e) {
    throw new AuthenticationException(e.getMessage(), e);
  }
}

代码示例来源:origin: org.zaproxy/zap

/** Calculates RC4 */
static byte[] RC4(final byte[] value, final byte[] key)
  throws AuthenticationException {
  try {
    final Cipher rc4 = Cipher.getInstance("RC4");
    rc4.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "RC4"));
    return rc4.doFinal(value);
  } catch (final Exception e) {
    throw new AuthenticationException(e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient

/**
 * Encrypt the data.
 * @param key The key.
 * @param bytes The data
 * @return byte[] The encrypted data
 * @throws HttpException If {@link Cipher.doFinal(byte[])} fails
 */
private byte[] encrypt(byte[] key, byte[] bytes)
  throws AuthenticationException {
  Cipher ecipher = getCipher(key);
  try {
    byte[] enc = ecipher.doFinal(bytes);
    return enc;
  } catch (IllegalBlockSizeException e) {
    throw new AuthenticationException("Invalid block size for DES encryption.", e);
  } catch (BadPaddingException e) {
    throw new AuthenticationException("Data not padded correctly for DES encryption.", e);
  }
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Encrypt the data.
 * @param key The key.
 * @param bytes The data
 * @return byte[] The encrypted data
 * @throws HttpException If {@link Cipher.doFinal(byte[])} fails
 */
private byte[] encrypt(byte[] key, byte[] bytes)
  throws AuthenticationException {
  Cipher ecipher = getCipher(key);
  try {
    byte[] enc = ecipher.doFinal(bytes);
    return enc;
  } catch (IllegalBlockSizeException e) {
    throw new AuthenticationException("Invalid block size for DES encryption.", e);
  } catch (BadPaddingException e) {
    throw new AuthenticationException("Data not padded correctly for DES encryption.", e);
  }
}

代码示例来源:origin: org.apache.abdera/abdera-extensions-wsse

private String generatePasswordDigest(String password, String nonce, AtomDate date) throws AuthenticationException {
  String temp = nonce + date.getValue() + password;
  try {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    return new String(Base64.encodeBase64(md.digest(temp.getBytes())));
  } catch (Exception e) {
    throw new AuthenticationException(e.getMessage(), e);
  }
}

代码示例来源:origin: org.wso2.commons-httpclient/commons-httpclient

/**
 * Encrypt the data.
 * @param key The key.
 * @param bytes The data
 * @return byte[] The encrypted data
 * @throws HttpException If {@link Cipher.doFinal(byte[])} fails
 */
private byte[] encrypt(byte[] key, byte[] bytes)
  throws AuthenticationException {
  Cipher ecipher = getCipher(key);
  try {
    byte[] enc = ecipher.doFinal(bytes);
    return enc;
  } catch (IllegalBlockSizeException e) {
    throw new AuthenticationException("Invalid block size for DES encryption.", e);
  } catch (BadPaddingException e) {
    throw new AuthenticationException("Data not padded correctly for DES encryption.", e);
  }
}

代码示例来源:origin: org.apache.commons/httpclient

/**
 * Encrypt the data.
 * @param key The key.
 * @param bytes The data
 * @return byte[] The encrypted data
 * @throws HttpException If {@link Cipher.doFinal(byte[])} fails
 */
private byte[] encrypt(byte[] key, byte[] bytes)
  throws AuthenticationException {
  Cipher ecipher = getCipher(key);
  try {
    byte[] enc = ecipher.doFinal(bytes);
    return enc;
  } catch (IllegalBlockSizeException e) {
    throw new AuthenticationException("Invalid block size for DES encryption.", e);
  } catch (BadPaddingException e) {
    throw new AuthenticationException("Data not padded correctly for DES encryption.", e);
  }
}

代码示例来源:origin: org.zaproxy/zap

public byte[] decryptAndVerifySignedMessage( final byte[] inMessage ) throws AuthenticationException
{
  final byte[] signature = new byte[16];
  System.arraycopy( inMessage, 0, signature, 0, signature.length );
  final byte[] encryptedMessage = new byte[inMessage.length - 16];
  System.arraycopy( inMessage, 16, encryptedMessage, 0, encryptedMessage.length );
  final byte[] cleartextMessage = decrypt( encryptedMessage );
  if ( !validateSignature( signature, cleartextMessage ) )
  {
    throw new AuthenticationException( "Wrong signature" );
  }
  advanceMessageSequence();
  return cleartextMessage;
}

代码示例来源:origin: org.zaproxy/zap

/**
 * Creates the LMv2 Hash of the user's password.
 *
 * @return The LMv2 Hash, used in the calculation of the NTLMv2 and LMv2
 *         Responses.
 */
private static byte[] lmv2Hash(final String domain, final String user, final byte[] ntlmHash)
    throws AuthenticationException {
  if (UNICODE_LITTLE_UNMARKED == null) {
    throw new AuthenticationException("Unicode not supported");
  }
  final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
  // Upper case username, upper case domain!
  hmacMD5.update(user.toUpperCase(Locale.ROOT).getBytes(UNICODE_LITTLE_UNMARKED));
  if (domain != null) {
    hmacMD5.update(domain.toUpperCase(Locale.ROOT).getBytes(UNICODE_LITTLE_UNMARKED));
  }
  return hmacMD5.getOutput();
}

代码示例来源:origin: org.zaproxy/zap

/**
 * Creates the NTLMv2 Hash of the user's password.
 *
 * @return The NTLMv2 Hash, used in the calculation of the NTLMv2 and LMv2
 *         Responses.
 */
private static byte[] ntlmv2Hash(final String domain, final String user, final byte[] ntlmHash)
    throws AuthenticationException {
  if (UNICODE_LITTLE_UNMARKED == null) {
    throw new AuthenticationException("Unicode not supported");
  }
  final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
  // Upper case username, mixed case target!!
  hmacMD5.update(user.toUpperCase(Locale.ROOT).getBytes(UNICODE_LITTLE_UNMARKED));
  if (domain != null) {
    hmacMD5.update(domain.getBytes(UNICODE_LITTLE_UNMARKED));
  }
  return hmacMD5.getOutput();
}

代码示例来源:origin: org.zaproxy/zap

/**
 * Creates the NTLM Hash of the user's password.
 *
 * @param password
 *            The password.
 *
 * @return The NTLM Hash of the given password, used in the calculation of
 *         the NTLM Response and the NTLMv2 and LMv2 Hashes.
 */
private static byte[] ntlmHash(final String password) throws AuthenticationException {
  if (UNICODE_LITTLE_UNMARKED == null) {
    throw new AuthenticationException("Unicode not supported");
  }
  final byte[] unicodePassword = password.getBytes(UNICODE_LITTLE_UNMARKED);
  final MD4 md4 = new MD4();
  md4.update(unicodePassword);
  return md4.getOutput();
}

代码示例来源:origin: org.apache.abdera/abdera-extensions-gdata

public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
  String auth = null;
  if (credentials instanceof UsernamePasswordCredentials) {
    UsernamePasswordCredentials usercreds = (UsernamePasswordCredentials)credentials;
    String id = usercreds.getUserName();
    String pwd = usercreds.getPassword();
    auth = getAuth(id, pwd);
  } else if (credentials instanceof GoogleLoginAuthCredentials) {
    GoogleLoginAuthCredentials gcreds = (GoogleLoginAuthCredentials)credentials;
    service = gcreds.getService();
    auth = gcreds.getAuth();
  } else {
    throw new AuthenticationException("Cannot use credentials for GoogleLogin authentication");
  }
  StringBuffer buf = new StringBuffer("GoogleLogin ");
  buf.append(auth);
  return buf.toString();
}

相关文章

微信公众号

最新文章

更多