Configure a autenticação do MID Web Server baseada em chave
Forneça segurança adicional à extensão do MID Web Server usando autenticação baseada em chave. Gere um token de autenticação a ser enviado no cabeçalho de autorização das solicitações de cliente recebidas.
Antes de Iniciar
Nota:
Este procedimento é somente para compatibilidade com versões anteriores a. Zurich. Para obter detalhes sobre o procedimento em Zurich versão para configurar o. MID Web Server, consulte Configure o. MID Web Server extensão.
- Implantar e iniciar um MID Server.
- Configure um MID Web Server E selecione Baseada em chave como o tipo de autenticação. Para obter detalhes, consulte Configure a extensão do MID Web Server .
Função necessária: agent_admin
Procedimento
Como gerar o HMAC da cadeia de caracteres que usa elementos definidos da solicitação HTTP/HTTPS usando 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;
}
}