Configurer l’authentification du serveur Web MID basée sur la clé
Assurez la sécurité de votre extension Serveur Web MID à l’aide de l’authentification basée sur les clés. Générer un jeton d’authentification à envoyer dans l’en-tête d’autorisation des demandes client entrantes.
Avant de commencer
Remarque :
Cette procédure ne concerne que la compatibilité avec les versions antérieures à Australie. Pour plus d’informations sur la procédure de configuration de la AustralieServeur Web MID version , reportez-vous à la section Configurer l’extension Serveur Web MID.
- Déployez et démarrez un Serveur MID.
- Configurez une Serveur Web MID extension et sélectionnez Basé sur les clés comme type d’authentification. Pour plus d’informations, voir Configurer l’extension Serveur Web MID.
Rôle requis : agent_admin
Procédure
Comment générer le HMAC de la chaîne qui utilise les éléments définis de la requête HTTP/HTTPS, à l’aide de Java
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;
}
}