org.jasig.cas.client.util
Class CommonUtils

java.lang.Object
  extended by org.jasig.cas.client.util.CommonUtils

public final class CommonUtils
extends Object

Common utilities so that we don't need to include Commons Lang.

Since:
3.0
Version:
$Revision: 11729 $ $Date: 2007-09-26 14:22:30 -0400 (Tue, 26 Sep 2007) $
Author:
Scott Battaglia

Method Summary
static void assertNotEmpty(Collection<?> c, String message)
          Check whether the collection is null or empty.
static void assertNotNull(Object object, String message)
          Check whether the object is null or not.
static void assertTrue(boolean cond, String message)
          Assert that the statement is true, otherwise throw an exception with the provided message.
static void closeQuietly(Closeable resource)
          Unconditionally close a Closeable.
static String constructRedirectUrl(String casServerLoginUrl, String serviceParameterName, String serviceUrl, boolean renew, boolean gateway)
          Constructs the URL to use to redirect to the CAS server.
static String constructServiceUrl(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String service, String serverNames, String artifactParameterName, boolean encode)
          Constructs a service url from the HttpServletRequest or from the given serviceUrl.
static ProxyList createProxyList(String proxies)
           
protected static String findMatchingServerName(javax.servlet.http.HttpServletRequest request, String serverName)
           
static String formatForUtcTime(Date date)
           
static String getResponseFromServer(String constructedUrl, String encoding)
          Deprecated. 
static String getResponseFromServer(URL constructedUrl, HttpURLConnectionFactory factory, String encoding)
          Contacts the remote URL and returns the response.
static boolean isBlank(String string)
          Determines if a String is blank or not.
static boolean isEmpty(String string)
          Determines whether the String is null or of length 0.
static boolean isNotBlank(String string)
          Determines if a string is not blank.
static boolean isNotEmpty(String string)
          Determines if the String is not empty.
static void readAndRespondToProxyReceptorRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ProxyGrantingTicketStorage proxyGrantingTicketStorage)
           
static String safeGetParameter(javax.servlet.http.HttpServletRequest request, String parameter)
           
static String safeGetParameter(javax.servlet.http.HttpServletRequest request, String parameter, List<String> parameters)
          Safe method for retrieving a parameter from the request without disrupting the reader UNLESS the parameter actually exists in the query string.
static void sendRedirect(javax.servlet.http.HttpServletResponse response, String url)
          Sends the redirect message and captures the exceptions that we can't possibly do anything with.
static String urlEncode(String value)
          Url encode a value using UTF-8 encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

formatForUtcTime

public static String formatForUtcTime(Date date)

assertNotNull

public static void assertNotNull(Object object,
                                 String message)
Check whether the object is null or not. If it is, throw an exception and display the message.

Parameters:
object - the object to check.
message - the message to display if the object is null.

assertNotEmpty

public static void assertNotEmpty(Collection<?> c,
                                  String message)
Check whether the collection is null or empty. If it is, throw an exception and display the message.

Parameters:
c - the collection to check.
message - the message to display if the object is null.

assertTrue

public static void assertTrue(boolean cond,
                              String message)
Assert that the statement is true, otherwise throw an exception with the provided message.

Parameters:
cond - the codition to assert is true.
message - the message to display if the condition is not true.

isEmpty

public static boolean isEmpty(String string)
Determines whether the String is null or of length 0.

Parameters:
string - the string to check
Returns:
true if its null or length of 0, false otherwise.

isNotEmpty

public static boolean isNotEmpty(String string)
Determines if the String is not empty. A string is not empty if it is not null and has a length > 0.

Parameters:
string - the string to check
Returns:
true if it is not empty, false otherwise.

isBlank

public static boolean isBlank(String string)
Determines if a String is blank or not. A String is blank if its empty or if it only contains spaces.

Parameters:
string - the string to check
Returns:
true if its blank, false otherwise.

isNotBlank

public static boolean isNotBlank(String string)
Determines if a string is not blank. A string is not blank if it contains at least one non-whitespace character.

Parameters:
string - the string to check.
Returns:
true if its not blank, false otherwise.

constructRedirectUrl

public static String constructRedirectUrl(String casServerLoginUrl,
                                          String serviceParameterName,
                                          String serviceUrl,
                                          boolean renew,
                                          boolean gateway)
Constructs the URL to use to redirect to the CAS server.

Parameters:
casServerLoginUrl - the CAS Server login url.
serviceParameterName - the name of the parameter that defines the service.
serviceUrl - the actual service's url.
renew - whether we should send renew or not.
gateway - where we should send gateway or not.
Returns:
the fully constructed redirect url.

urlEncode

public static String urlEncode(String value)
Url encode a value using UTF-8 encoding.

Parameters:
value - the value to encode.
Returns:
the encoded value.

readAndRespondToProxyReceptorRequest

public static void readAndRespondToProxyReceptorRequest(javax.servlet.http.HttpServletRequest request,
                                                        javax.servlet.http.HttpServletResponse response,
                                                        ProxyGrantingTicketStorage proxyGrantingTicketStorage)
                                                 throws IOException
Throws:
IOException

findMatchingServerName

protected static String findMatchingServerName(javax.servlet.http.HttpServletRequest request,
                                               String serverName)

constructServiceUrl

public static String constructServiceUrl(javax.servlet.http.HttpServletRequest request,
                                         javax.servlet.http.HttpServletResponse response,
                                         String service,
                                         String serverNames,
                                         String artifactParameterName,
                                         boolean encode)
Constructs a service url from the HttpServletRequest or from the given serviceUrl. Prefers the serviceUrl provided if both a serviceUrl and a serviceName.

Parameters:
request - the HttpServletRequest
response - the HttpServletResponse
service - the configured service url (this will be used if not null)
serverNames - the server name to use to constuct the service url if the service param is empty. Note, prior to CAS Client 3.3, this was a single value. As of 3.3, it can be a space-separated value. We keep it as a single value, but will convert it to an array internally to get the matching value. This keeps backward compatability with anything using this public method.
artifactParameterName - the artifact parameter name to remove (i.e. ticket)
encode - whether to encode the url or not (i.e. Jsession).
Returns:
the service url to use.

safeGetParameter

public static String safeGetParameter(javax.servlet.http.HttpServletRequest request,
                                      String parameter,
                                      List<String> parameters)
Safe method for retrieving a parameter from the request without disrupting the reader UNLESS the parameter actually exists in the query string.

Note, this does not work for POST Requests for "logoutRequest". It works for all other CAS POST requests because the parameter is ALWAYS in the GET request.

If we see the "logoutRequest" parameter we MUST treat it as if calling the standard request.getParameter.

Note, that as of 3.3.0, we've made it more generic.

Parameters:
request - the request to check.
parameter - the parameter to look for.
Returns:
the value of the parameter.

safeGetParameter

public static String safeGetParameter(javax.servlet.http.HttpServletRequest request,
                                      String parameter)

getResponseFromServer

@Deprecated
public static String getResponseFromServer(String constructedUrl,
                                                      String encoding)
Deprecated. 

Contacts the remote URL and returns the response.

Parameters:
constructedUrl - the url to contact.
encoding - the encoding to use.
Returns:
the response.

getResponseFromServer

public static String getResponseFromServer(URL constructedUrl,
                                           HttpURLConnectionFactory factory,
                                           String encoding)
Contacts the remote URL and returns the response.

Parameters:
constructedUrl - the url to contact.
factory - connection factory to prepare the URL connection instance
encoding - the encoding to use.
Returns:
the response.

createProxyList

public static ProxyList createProxyList(String proxies)

sendRedirect

public static void sendRedirect(javax.servlet.http.HttpServletResponse response,
                                String url)
Sends the redirect message and captures the exceptions that we can't possibly do anything with.

Parameters:
response - the HttpServletResponse. CANNOT be NULL.
url - the url to redirect to.

closeQuietly

public static void closeQuietly(Closeable resource)
Unconditionally close a Closeable. Equivalent to Closeable.close()close(), except any exceptions will be ignored. This is typically used in finally blocks.

Parameters:
resource -


Copyright © 2006-2014 Jasig. All Rights Reserved.