キーベースの MID Web サーバー認証の設定
キーベースの認証を使用して、MID Web サーバー拡張のセキュリティを強化します。着信したクライアント要求の [認証] ヘッダーで送信する認証トークンを生成します。
始める前に
注:
この手順は、オーストラリア より前のリリースとの互換性を保つためだけのものです。オーストラリア リリースで MID Web サーバー を設定する手順の詳細については、「MID Web サーバー 拡張の設定」を参照してください。
- MID サーバー を展開して起動します。
- MID Web サーバー 拡張を設定し、認証タイプとして [キーベース] を選択します。詳細については、「MID Web サーバー拡張の設定」を参照してください。
必要なロール:agent_admin
手順
Java を使用して HTTP/HTTPS 要求の定義済み要素を使用する文字列の HMAC を生成する方法
package sample;
import com.glide.util;
import java.security.SignatureException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public class AuthUtil {
private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
/***
* Generates base64-encode the HMAC(Hash Message Authentication Code) of input data
*
* @param data
* @param key
* @return
* @throws java.security.SignatureException
*/
public static String signData(String data, String key) throws java.security.SignatureException {
String result;
try {
// get an hmac_sha1 key from the raw key bytes
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
// create hmac_sha1 Mac instance and initialize with the signing key
Mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(signingKey);
// compute the hmac on input data bytes
byte[] rawHmac = mac.doFinal(data.getBytes("UTF-8"));
// base64-encode the hmac
result = Base64.encode(rawHmac);
} catch (Exception e) {
throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
}
return result;
}
}