本文整理汇总了Java中org.openid4java.association.AssociationSessionType.getHAlgorithm方法的典型用法代码示例。如果您正苦于以下问题:Java AssociationSessionType.getHAlgorithm方法的具体用法?Java AssociationSessionType.getHAlgorithm怎么用?Java AssociationSessionType.getHAlgorithm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openid4java.association.AssociationSessionType
的用法示例。
在下文中一共展示了AssociationSessionType.getHAlgorithm方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAssociationRequest
import org.openid4java.association.AssociationSessionType; //导入方法依赖的package包/类
public static AssociationRequest createAssociationRequest(
AssociationSessionType type, DiffieHellmanSession dhSess)
throws MessageException
{
AssociationRequest req = new AssociationRequest(type, dhSess);
// make sure the association / session type matches the dhSess
if ( type == null ||
(dhSess == null && type.getHAlgorithm() != null) ||
(dhSess != null && ! dhSess.getType().equals(type) ) )
throw new MessageException(
"Invalid association / session combination specified: " +
type + "DH session: " + dhSess);
req.validate();
if (DEBUG) _log.debug("Created association request:\n"
+ req.keyValueFormEncoding());
return req;
}
示例2: AssociationResponse
import org.openid4java.association.AssociationSessionType; //导入方法依赖的package包/类
/**
* Constructs an AssociationResponse for a given association request.
*
* @param assocReq The association request that needs to be responded.
* @param assoc The association which will be used to sign
* authentication responses.
*/
protected AssociationResponse(AssociationRequest assocReq, Association assoc)
throws AssociationException
{
if (DEBUG)
_log.debug("Creating association response, type: " + assocReq.getType()
+ " association handle: " + assoc.getHandle());
if (assocReq.isVersion2()) set("ns", OPENID2_NS);
AssociationSessionType type = assocReq.getType();
setType(type);
setAssocHandle(assoc.getHandle());
Long expiryIn = new Long( ( assoc.getExpiry().getTime() -
System.currentTimeMillis() ) / 1000 );
setExpire(expiryIn);
if (type.getHAlgorithm() != null) // DH session, encrypt the MAC key
{
DiffieHellmanSession dhSess = DiffieHellmanSession.create(
type, assocReq.getDhModulus(), assocReq.getDhGen() );
setPublicKey(dhSess.getPublicKey());
setMacKeyEnc(dhSess.encryptMacKey(
assoc.getMacKey().getEncoded(),
assocReq.getDhPublicKey() ));
}
else // no-encryption session, unecrypted MAC key
{
setMacKey(new String(
Base64.encodeBase64(assoc.getMacKey().getEncoded())));
}
}
示例3: createAssociationRequest
import org.openid4java.association.AssociationSessionType; //导入方法依赖的package包/类
/**
* Constructs an Association Request message of the specified session and
* association type, taking into account the user preferences (encryption
* level, default Diffie-Hellman parameters).
*
* @param type The type of the association (session and association)
* @param opUrl The OP for which the association request is created
* @return An AssociationRequest message ready to be sent back
* to the OpenID Provider, or null if an association
* of the requested type cannot be built.
*/
private AssociationRequest createAssociationRequest(
AssociationSessionType type, URL opUrl)
{
try
{
if (_minAssocSessEnc.isBetter(type))
return null;
AssociationRequest assocReq = null;
DiffieHellmanSession dhSess;
if (type.getHAlgorithm() != null) // DH session
{
dhSess = DiffieHellmanSession.create(type, _dhParams);
if (DiffieHellmanSession.isDhSupported(type)
&& Association.isHmacSupported(type.getAssociationType()))
assocReq = AssociationRequest.createAssociationRequest(type, dhSess);
}
else if ( opUrl.getProtocol().equals("https") && // no-enc sess
Association.isHmacSupported(type.getAssociationType()))
assocReq = AssociationRequest.createAssociationRequest(type);
if (assocReq == null)
_log.warn("Could not create association of type: " + type);
return assocReq;
}
catch (OpenIDException e)
{
_log.error("Error trying to create association request.", e);
return null;
}
}
示例4: validate
import org.openid4java.association.AssociationSessionType; //导入方法依赖的package包/类
/**
* Checks if the message is a valid OpenID Association Response..
*
* @throws MessageException if message validation failed.
*/
public void validate() throws MessageException
{
// basic checks
super.validate();
// association / session type checks
// (includes most of the compatibility stuff)
AssociationSessionType type;
try
{
// throws exception for invalid session / association types
type = getType();
// make sure compatibility mode is the same for type and message
if (type.isVersion2() ^ isVersion2())
{
throw new MessageException(
"Protocol verison mismatch between association " +
"session type: " + type +
" and AssociationResponse message type.",
OpenIDException.ASSOC_ERROR);
}
}
catch (AssociationException e)
{
throw new MessageException(
"Error verifying association response validity.",
OpenIDException.ASSOC_ERROR, e);
}
// additional compatibility checks
if (! isVersion2() && getAssociationType() == null)
{
throw new MessageException(
"assoc_type cannot be omitted in OpenID1 responses",
OpenIDException.ASSOC_ERROR);
}
String macKey;
if (type.getHAlgorithm() != null) // DH session
{
if ( ! hasParameter("dh_server_public") ||
! hasParameter("enc_mac_key") )
{
throw new MessageException(
"DH public key or encrypted MAC key missing.",
OpenIDException.ASSOC_ERROR);
}
else
macKey = getParameterValue("enc_mac_key");
} else // no-enc session
{
if ( !hasParameter("mac_key") )
{
throw new MessageException("Missing MAC key.",
OpenIDException.ASSOC_ERROR);
}
else
macKey = getParameterValue("mac_key");
}
// mac key size
int macSize = Base64.decodeBase64(macKey.getBytes()).length * 8;
if ( macSize != type.getKeySize())
{
throw new MessageException("MAC key size: " + macSize +
" doesn't match the association/session type: " + type,
OpenIDException.ASSOC_ERROR);
}
}
示例5: getAssociation
import org.openid4java.association.AssociationSessionType; //导入方法依赖的package包/类
/**
* Generates an Association object from an Association Response.
*
* @param dhSess The Diffie-Helman session containing the private key
* used to encrypt / decrypt the MAC key exchange.
* Should be null for no-encryption sessions.
*/
public Association getAssociation(DiffieHellmanSession dhSess)
throws AssociationException
{
if (DEBUG) _log.debug("Retrieving MAC key from association response...");
String handle = getParameterValue("assoc_handle");
int expiresIn = Integer.parseInt(
getParameterValue("expires_in") );
// get (and decrypt) the MAC key
byte[] macKey;
AssociationSessionType type = getType();
if ( type.getHAlgorithm() != null )
{
macKey = dhSess.decryptMacKey(
getParameterValue("enc_mac_key"),
getParameterValue("dh_server_public") );
if (DEBUG) _log.debug("Decrypted MAC key (base64): " +
new String(Base64.encodeBase64(macKey)));
}
else
{
macKey = Base64.decodeBase64(
getParameterValue("mac_key").getBytes() );
if (DEBUG) _log.debug("Unencrypted MAC key (base64): "
+ getParameterValue("mac_key"));
}
Association assoc;
if (Association.TYPE_HMAC_SHA1.equals(type.getAssociationType()))
assoc = Association.createHmacSha1(handle, macKey, expiresIn);
else if (Association.TYPE_HMAC_SHA256.equals(type.getAssociationType()))
assoc = Association.createHmacSha256(handle, macKey, expiresIn);
else
throw new AssociationException("Unknown association type: " + type);
if (DEBUG) _log.debug("Created association for handle: " + handle);
return assoc;
}
示例6: validate
import org.openid4java.association.AssociationSessionType; //导入方法依赖的package包/类
/**
* Checks if the message is a valid OpenID Association Request.
*
* @throws MessageException if message validation failed.
*/
public void validate() throws MessageException
{
// basic checks
super.validate();
// association / session type checks
// (includes most of the compatibility stuff)
AssociationSessionType type;
try
{
// throws exception for invalid session / association types
type = getType();
// make sure compatibility mode is the same for type and message
if (type.isVersion2() != isVersion2())
{
throw new MessageException("Protocol verison mismatch " +
"between association session type: " + type +
" and AssociationRequest message type.",
OpenIDException.ASSOC_ERROR);
}
}
catch (AssociationException e)
{
throw new MessageException(
"Error verifying association request validity.",
OpenIDException.ASSOC_ERROR, e);
}
// additional compatibility checks
if (! isVersion2() && getSessionType() == null)
{
throw new MessageException(
"sess_type cannot be omitted in OpenID1 association requests",
OpenIDException.ASSOC_ERROR);
}
// DH seesion parameters
if ( type.getHAlgorithm() != null && getDhPublicKey() == null)
{
throw new MessageException("DH consumer public key not specified.",
OpenIDException.ASSOC_ERROR);
}
// no-enc session
if (type.getHAlgorithm() == null && (getDhGen() != null ||
getDhModulus() != null || getDhPublicKey() != null) )
{
throw new MessageException(
"No-encryption session, but DH parameters specified.",
OpenIDException.ASSOC_ERROR);
}
}