키 기반 MID 웹 서버 인증 구성
키 기반 인증을 사용하여 MID 웹 서버 확장에 추가 보안을 제공합니다. 수신 클라이언트 요청의 인증 헤더에서 보낼 인증 토큰을 생성합니다.
시작하기 전에
주:
이 절차는 Zurich 이전 릴리스와의 호환성에만 해당됩니다. MID 웹 서버 구성의 Zurich 릴리스 절차에 대한 자세한 내용은 MID 웹 서버 확장 구성 문서를 참조하십시오.
- MID 서버를 배포하고 시작합니다.
- MID 웹 서버 확장을 구성하고 키 기반을 인증 유형으로 선택합니다. 자세한 내용은 MID 웹 서버 확장 구성을 참조하십시오.
필요한 역할: 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;
}
}