com.google.code.facebookapi
Class FacebookSignatureUtil

java.lang.Object
  extended by com.google.code.facebookapi.FacebookSignatureUtil

public final class FacebookSignatureUtil
extends java.lang.Object

Utility for managing Facebook-specific parameters, specifically those related to session/login aspects.


Field Summary
protected static org.apache.commons.logging.Log log
           
 
Constructor Summary
FacebookSignatureUtil()
           
 
Method Summary
static boolean autoVerifySignature(java.util.Map<java.lang.String,java.lang.String[]> requestParams, java.lang.String secret)
          Verifies that a signature received matches the expected value.
static boolean autoVerifySignature(java.util.Map<java.lang.String,java.lang.String[]> requestParams, java.lang.String secret, java.lang.String expected)
          Verifies that a signature received matches the expected value.
static java.util.List<java.lang.String> convert(java.util.Collection<java.util.Map.Entry<java.lang.String,java.lang.String>> entries)
          Converts a Map of key-value pairs into the form expected by generateSignature
static java.util.List<java.lang.String> convertFacebookParams(java.util.Collection<java.util.Map.Entry<FacebookParam,java.lang.String>> entries)
          Converts a Map of key-value pairs into the form expected by generateSignature
static java.util.Map<java.lang.String,java.lang.CharSequence> extractFacebookNamespaceParams(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> reqParams)
          Out of the passed in reqParams, extracts the parameters that are in the FacebookParam namespace and returns them.
static java.util.EnumMap<FacebookParam,java.lang.CharSequence> extractFacebookParams(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> reqParams)
          Out of the passed in reqParams, extracts the parameters that are known FacebookParams and returns them.
static java.util.Map<java.lang.String,java.lang.String> extractFacebookParamsFromArray(java.util.Map<java.lang.CharSequence,java.lang.CharSequence[]> reqParams)
          Out of the passed in reqParams, extracts the parameters that are in the FacebookParam namespace and returns them.
static java.util.Map<java.lang.String,java.lang.String> extractFacebookParamsFromStandardsCompliantArray(java.util.Map<java.lang.String,java.lang.String[]> reqParams)
          Out of the passed in reqParams, extracts the parameters that are in the FacebookParam namespace and returns them.
static java.lang.String generateEmailHash(java.lang.String email)
           Normalize the email address.
static java.lang.String generateMD5(java.lang.String value)
           
static java.lang.String generateSignature(java.util.List<java.lang.String> params, java.lang.String secret)
          Calculates the signature for the given set of params using the supplied secret
static java.util.Map<java.lang.String,java.lang.String> pulloutFbSigParams(java.util.Map<java.lang.String,java.lang.String[]> reqParams)
           
static java.lang.String toString(java.lang.CharSequence cs)
           
static boolean verifySignature(java.util.EnumMap<FacebookParam,java.lang.String> params, java.lang.String secret)
          Verifies that a signature received matches the expected value.
static boolean verifySignature(java.util.EnumMap<FacebookParam,java.lang.String> params, java.lang.String secret, java.lang.String expected)
          Verifies that a signature received matches the expected value.
static boolean verifySignature(java.util.Map<java.lang.String,java.lang.String> params, java.lang.String secret)
          Verifies that a signature received matches the expected value.
static boolean verifySignature(java.util.Map<java.lang.String,java.lang.String> params, java.lang.String secret, java.lang.String expected)
          Verifies that a signature received matches the expected value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log
Constructor Detail

FacebookSignatureUtil

public FacebookSignatureUtil()
Method Detail

pulloutFbSigParams

public static java.util.Map<java.lang.String,java.lang.String> pulloutFbSigParams(java.util.Map<java.lang.String,java.lang.String[]> reqParams)

extractFacebookParamsFromArray

public static java.util.Map<java.lang.String,java.lang.String> extractFacebookParamsFromArray(java.util.Map<java.lang.CharSequence,java.lang.CharSequence[]> reqParams)
Out of the passed in reqParams, extracts the parameters that are in the FacebookParam namespace and returns them.

Parameters:
reqParams - A map of request parameters to their values. Values are arrays of strings, as returned by ServletRequest.getParameterMap(). Only the first element in a given array is significant.
Returns:
a boolean indicating whether the calculated signature matched the expected signature

toString

public static java.lang.String toString(java.lang.CharSequence cs)

extractFacebookParamsFromStandardsCompliantArray

public static java.util.Map<java.lang.String,java.lang.String> extractFacebookParamsFromStandardsCompliantArray(java.util.Map<java.lang.String,java.lang.String[]> reqParams)
Out of the passed in reqParams, extracts the parameters that are in the FacebookParam namespace and returns them.

Parameters:
reqParams - A map of request parameters to their values. Values are arrays of strings, as returned by ServletRequest.getParameterMap(). Only the first element in a given array is significant.
Returns:
a boolean indicating whether the calculated signature matched the expected signature

extractFacebookNamespaceParams

public static java.util.Map<java.lang.String,java.lang.CharSequence> extractFacebookNamespaceParams(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> reqParams)
Out of the passed in reqParams, extracts the parameters that are in the FacebookParam namespace and returns them.

Parameters:
reqParams - a map of request parameters to their values
Returns:
a boolean indicating whether the calculated signature matched the expected signature

extractFacebookParams

public static java.util.EnumMap<FacebookParam,java.lang.CharSequence> extractFacebookParams(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> reqParams)
Out of the passed in reqParams, extracts the parameters that are known FacebookParams and returns them.

Parameters:
reqParams - a map of request parameters to their values
Returns:
a map suitable for being passed to verify signature

verifySignature

public static boolean verifySignature(java.util.EnumMap<FacebookParam,java.lang.String> params,
                                      java.lang.String secret)
Verifies that a signature received matches the expected value. Removes FacebookParam.SIGNATURE from params if present.

Parameters:
params - a map of parameters and their values, such as one obtained from extractFacebookParams; expected to the expected signature as the FacebookParam.SIGNATURE parameter
secret -
Returns:
a boolean indicating whether the calculated signature matched the expected signature

verifySignature

public static boolean verifySignature(java.util.EnumMap<FacebookParam,java.lang.String> params,
                                      java.lang.String secret,
                                      java.lang.String expected)
Verifies that a signature received matches the expected value.

Parameters:
params - a map of parameters and their values, such as one obtained from extractFacebookParams
secret - the developers 'secret' API key
expected - the expected resulting value of computing the MD5 sum of the 'sig' params and the 'secret' key
Returns:
a boolean indicating whether the calculated signature matched the expected signature

verifySignature

public static boolean verifySignature(java.util.Map<java.lang.String,java.lang.String> params,
                                      java.lang.String secret)
Verifies that a signature received matches the expected value. Removes FacebookParam.SIGNATURE from params if present.

Parameters:
params - a map of parameters and their values, such as one obtained from extractFacebookNamespaceParams; expected to contain the signature as the FacebookParam.SIGNATURE parameter
secret - the developers 'secret' API key
Returns:
a boolean indicating whether the calculated signature matched the expected signature

autoVerifySignature

public static boolean autoVerifySignature(java.util.Map<java.lang.String,java.lang.String[]> requestParams,
                                          java.lang.String secret,
                                          java.lang.String expected)
Verifies that a signature received matches the expected value. This method will perform any necessary conversion of the parameter map passed to it (should the map be immutable, etc.), meaning that you may safely call it without doing any manual preprocessing of the parameters first.

Parameters:
requestParams - A map of request parameters to their values, as returned by ServletRequest.getParameterMap(), for example.
secret - the developers 'secret' API key
expected - the expected resulting value of computing the MD5 sum of the 'sig' params and the 'secret' key
Returns:
a boolean indicating whether the calculated signature matched the expected signature

autoVerifySignature

public static boolean autoVerifySignature(java.util.Map<java.lang.String,java.lang.String[]> requestParams,
                                          java.lang.String secret)
Verifies that a signature received matches the expected value. This method will perform any necessary conversion of the parameter map passed to it (should the map be immutable, etc.), meaning that you may safely call it without doing any manual preprocessing of the parameters first.

Parameters:
requestParams - A map of request parameters to their values, as returned by ServletRequest.getParameterMap(), for example.
secret - the developers 'secret' API key
Returns:
a boolean indicating whether the calculated signature matched the expected signature

verifySignature

public static boolean verifySignature(java.util.Map<java.lang.String,java.lang.String> params,
                                      java.lang.String secret,
                                      java.lang.String expected)
Verifies that a signature received matches the expected value.

Parameters:
params - a map of parameters and their values, such as one obtained from extractFacebookNamespaceParams
secret - the developers 'secret' API key
expected - the expected resulting value of computing the MD5 sum of the 'sig' params and the 'secret' key
Returns:
a boolean indicating whether the calculated signature matched the expected signature

convert

public static java.util.List<java.lang.String> convert(java.util.Collection<java.util.Map.Entry<java.lang.String,java.lang.String>> entries)
Converts a Map of key-value pairs into the form expected by generateSignature

Parameters:
entries - a collection of Map.Entry's, such as can be obtained using myMap.entrySet()
Returns:
a List suitable for being passed to generateSignature

convertFacebookParams

public static java.util.List<java.lang.String> convertFacebookParams(java.util.Collection<java.util.Map.Entry<FacebookParam,java.lang.String>> entries)
Converts a Map of key-value pairs into the form expected by generateSignature

Parameters:
entries - a collection of Map.Entry's, such as can be obtained using myMap.entrySet()
Returns:
a List suitable for being passed to generateSignature

generateSignature

public static java.lang.String generateSignature(java.util.List<java.lang.String> params,
                                                 java.lang.String secret)
Calculates the signature for the given set of params using the supplied secret

Parameters:
params - Strings of the form "key=value"
secret -
Returns:
the signature

generateMD5

public static java.lang.String generateMD5(java.lang.String value)

generateEmailHash

public static java.lang.String generateEmailHash(java.lang.String email)
  1. Normalize the email address. Trim leading and trailing whitespace, and convert all characters to lowercase.
  2. Compute the CRC32 value for the normalized email address and use the unsigned integer representation of this value. (Note that some implementations return signed integers, in which case you will need to convert that result to an unsigned integer.)
  3. Compute the MD5 value for the normalized email address and use the hex representation of this value (using lowercase for A through F).
  4. Combine these two value with an underscore.
For example, the address mary@example.com converts to 4228600737_c96da02bba97aedfd26136e980ae3761.

Parameters:
email -
Returns:
email_hash
See Also:
IFacebookRestClient.connect_registerUsers(Collection)


Copyright © 2009. All Rights Reserved.