本文整理汇总了Java中org.openid4java.association.Association.createHmacSha1方法的典型用法代码示例。如果您正苦于以下问题:Java Association.createHmacSha1方法的具体用法?Java Association.createHmacSha1怎么用?Java Association.createHmacSha1使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openid4java.association.Association
的用法示例。
在下文中一共展示了Association.createHmacSha1方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapToAssociation
import org.openid4java.association.Association; //导入方法依赖的package包/类
private Association mapToAssociation(OpenIdAssociation ssoAssociation) {
Association association;
String type = ssoAssociation.getType();
String handle = ssoAssociation.getHandle();
byte[] macKey = ssoAssociation.getKey();
DateTime expiration = ssoAssociation.getExpiry();
switch(type) {
case Association.TYPE_HMAC_SHA1:
association = Association.createHmacSha1(handle, macKey, expiration.toDate());
break;
case Association.TYPE_HMAC_SHA256:
association = Association.createHmacSha256(handle, macKey, expiration.toDate());
break;
default:
LOGGER.warn("Somehow a handle of type {0} managed to get into the persistent store.", type);
return null;
}
return association;
}
示例2: getAssociation
import org.openid4java.association.Association; //导入方法依赖的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;
}
示例3: load
import org.openid4java.association.Association; //导入方法依赖的package包/类
public Association load ( String opUrl, String handle )
{
try
{
JdbcTemplate jdbcTemplate = getJdbcTemplate ( ) ;
Map res = jdbcTemplate.queryForMap ( _sqlSelect, new Object[]
{ opUrl, handle } ) ;
String type = (String) res.get ( "type" ) ;
String macKey = (String) res.get ( "mackey" ) ;
Date expDate = (Date) res.get ( "expdate" ) ;
if ( type == null || macKey == null || expDate == null )
throw new AssociationException (
"Invalid association data retrived from database; cannot create Association "
+ "object for handle: "
+ handle ) ;
Association assoc ;
if ( Association.TYPE_HMAC_SHA1.equals ( type ) )
assoc = Association.createHmacSha1 ( handle,
Base64.decodeBase64 ( macKey.getBytes ( ) ),
expDate ) ;
else if ( Association.TYPE_HMAC_SHA256.equals ( type ) )
assoc = Association.createHmacSha256 ( handle,
Base64.decodeBase64 ( macKey.getBytes ( ) ),
expDate ) ;
else
throw new AssociationException (
"Invalid association type "
+ "retrieved from database: "
+ type ) ;
if ( _log.isDebugEnabled ( ) )
_log.debug ( "Retrieved association for handle: " + handle
+ " from table: " + _tableName ) ;
return assoc ;
}
catch ( AssociationException ase )
{
_log.error ( "Error retrieving association from table: "
+ _tableName, ase ) ;
return null ;
}
catch ( IncorrectResultSizeDataAccessException rse )
{
_log.warn ( "Association not found for handle: " + handle
+ " in the table: " + _tableName ) ;
return null ;
}
catch ( DataAccessException dae )
{
_log.error ( "Error retrieving association for handle: " + handle
+ "from table: " + _tableName, dae ) ;
return null ;
}
}
示例4: load
import org.openid4java.association.Association; //导入方法依赖的package包/类
public Association load(String handle)
{
try
{
String sql = "SELECT type,mackey,expdate FROM " + _tableName +
" WHERE handle=?";
JdbcTemplate jdbcTemplate = getJdbcTemplate();
Map res = jdbcTemplate.queryForMap(sql, new Object[] {handle});
String type = (String) res.get("type");
String macKey = (String) res.get("mackey");
Date expDate = (Date) res.get("expdate");
if (type == null || macKey == null || expDate == null)
throw new AssociationException("Invalid association data " +
"retrived from database; cannot create Association " +
"object for handle: " + handle);
Association assoc;
if (Association.TYPE_HMAC_SHA1.equals(type))
assoc = Association.createHmacSha1(handle,
Base64.decodeBase64(macKey.getBytes() ), expDate);
else if (Association.TYPE_HMAC_SHA256.equals(type))
assoc = Association.createHmacSha256(handle,
Base64.decodeBase64(macKey.getBytes() ), expDate);
else
throw new AssociationException("Invalid association type " +
"retrieved from database: " + type);
if (DEBUG)
_log.debug("Retrieved association for handle: " + handle +
" from table: " + _tableName);
return assoc;
}
catch (AssociationException ase )
{
_log.error("Error retrieving association from table: " + _tableName, ase);
return null;
}
catch (IncorrectResultSizeDataAccessException rse)
{
_log.warn("Association not found for handle: " + handle +
" in the table: " + _tableName);
return null;
}
catch (DataAccessException dae)
{
_log.error("Error retrieving association for handle: " + handle +
"from table: " + _tableName, dae);
return null;
}
}
示例5: buildAssociationObject
import org.openid4java.association.Association; //导入方法依赖的package包/类
/**
* Builds the Association object
*
* @param results
* @return <code>Association</code>
* @throws SQLException
*/
private synchronized Association buildAssociationObject(ResultSet results) {
Association assoc = null;
String assocHandle = null;
try {
assocHandle = results.getString(1);
String assocType = results.getString(2);
java.util.Date expireIn = new java.util.Date(results.getTimestamp(3).getTime());
String macKey = results.getString(4);
String assocStore = results.getString(5);
// we check if params are missing
if (assocHandle == null || assocType == null || expireIn == null || macKey == null || assocStore == null) {
log.error("Required data missing. Cannot build the Association object");
return null;
}
// Here we check if we are loading the correct associations
if (associationStore.equals(OpenIDServerConstants.ASSOCIATION_STORE_TYPE_PRIVATE) &&
assocStore.equals(OpenIDServerConstants.ASSOCIATION_STORE_TYPE_SHARED)) {
log.error(
"Invalid association data found. Tried to load a Private Association but found a Shared Association");
return null;
} else if (associationStore.equals(OpenIDServerConstants.ASSOCIATION_STORE_TYPE_SHARED) &&
assocStore.equals(OpenIDServerConstants.ASSOCIATION_STORE_TYPE_PRIVATE)) {
log.error(
"Invalid association data found. Tried to load a Shared Association but found a Private Association");
return null;
}
// Checks for association handle
if (Association.TYPE_HMAC_SHA1.equals(assocType)) {
assoc = Association.createHmacSha1(assocHandle, Base64.decode(macKey), expireIn);
} else if (Association.TYPE_HMAC_SHA256.equals(assocType)) {
assoc = Association.createHmacSha256(assocHandle, Base64.decode(macKey), expireIn);
} else {
log.error("Invalid association type " + assocType + " loaded from database");
return null;
}
} catch (SQLException e) {
log.error("Failed to build the Association for " + assocHandle + ". Error while accessing the database.",
e);
} finally {
IdentityDatabaseUtil.closeResultSet(results);
}
log.debug("Association " + assocHandle + " loaded successfully from the database.");
return assoc;
}
示例6: getFromCache
import org.openid4java.association.Association; //导入方法依赖的package包/类
/**
* Read entries from the cache. If no value found then returns null.
* If the association is expired then returns null.
* Else returns the <code>Association</code>
*
* @param handle
* @return <code>Association<code>
*/
public Association getFromCache(String handle) {
if(IdentityUtil.isBlank(handle)){
throw new IllegalArgumentException("Handle is \'NULL\'");
}
OpenIDIdentityCacheKey cacheKey = new OpenIDIdentityCacheKey(0, handle);
OpenIDIdentityCacheEntry cacheEntry = associationCache.getValueFromCache(cacheKey);
if (cacheEntry != null) {
if (log.isDebugEnabled()) {
log.debug("Cache hit for handle : " + handle);
}
Date expiry = cacheEntry.getDate();
String type = cacheEntry.getCacheEntry();
Key secretKey = cacheEntry.getSecretKey();
if(Association.TYPE_HMAC_SHA1.equals(type)){
return Association.createHmacSha1(handle, secretKey.getEncoded(), expiry);
} else if(Association.TYPE_HMAC_SHA256.equals(type)) {
return Association.createHmacSha256(handle, secretKey.getEncoded(), expiry);
} else {
throw IdentityRuntimeException.error("Invalid algorithm " + type);
}
/*
* We are not removing expired handles from the cache. If we
* do, then at a lookup for a expired search, it will fall
* back to a database lookup which costs a lot. JCache
* should remove an entry if an entry was never called.
*
* if(association.hasExpired()){
* associationCache.removeCacheEntry(handle);
* if(log.isDebugEnabled()){
* log.debug("Expired entry in cache for handle : " +
* handle); } } else { return association; }
*/
} else {
if (log.isDebugEnabled()) {
log.debug("Cache miss for handle : " + handle);
}
return null;
}
}