public final class CommonUtils extends Object
Modifier and Type | Method and Description |
---|---|
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 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 serverName,
String artifactParameterName,
boolean encode)
Constructs a service url from the HttpServletRequest or from the given
serviceUrl.
|
static ProxyList |
createProxyList(String proxies) |
static String |
formatForUtcTime(Date date) |
static String |
getResponseFromServer(String url,
String encoding)
Contacts the remote URL and returns the response.
|
static String |
getResponseFromServer(URL constructedUrl,
HostnameVerifier hostnameVerifier,
String encoding)
Contacts the remote URL and returns the response.
|
static String |
getResponseFromServer(URL constructedUrl,
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)
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.
|
public static void assertNotNull(Object object, String message)
object
- the object to check.message
- the message to display if the object is null.public static void assertNotEmpty(Collection<?> c, String message)
c
- the collecion to check.message
- the message to display if the object is null.public static void assertTrue(boolean cond, String message)
cond
- the codition to assert is true.message
- the message to display if the condition is not true.public static boolean isEmpty(String string)
string
- the string to checkpublic static boolean isNotEmpty(String string)
string
- the string to checkpublic static boolean isBlank(String string)
string
- the string to checkpublic static boolean isNotBlank(String string)
string
- the string to check.public static String constructRedirectUrl(String casServerLoginUrl, String serviceParameterName, String serviceUrl, boolean renew, boolean gateway)
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.public static void readAndRespondToProxyReceptorRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ProxyGrantingTicketStorage proxyGrantingTicketStorage) throws IOException
IOException
public static String constructServiceUrl(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String service, String serverName, String artifactParameterName, boolean encode)
request
- the HttpServletRequestresponse
- the HttpServletResponseservice
- the configured service url (this will be used if not null)serverName
- the server name to use to constuct the service url if the service param is emptyartifactParameterName
- the artifact parameter name to remove (i.e. ticket)encode
- whether to encode the url or not (i.e. Jsession).public static String safeGetParameter(javax.servlet.http.HttpServletRequest request, String parameter)
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.
request
- the request to check.parameter
- the parameter to look for.public static String getResponseFromServer(URL constructedUrl, String encoding)
constructedUrl
- the url to contact.encoding
- the encoding to use.public static String getResponseFromServer(URL constructedUrl, HostnameVerifier hostnameVerifier, String encoding)
constructedUrl
- the url to contact.hostnameVerifier
- Host name verifier to use for HTTPS connections.encoding
- the encoding to use.public static String getResponseFromServer(String url, String encoding)
url
- the url to contact.encoding
- the encoding to use.public static void sendRedirect(javax.servlet.http.HttpServletResponse response, String url)
response
- the HttpServletResponse. CANNOT be NULL.url
- the url to redirect to.Copyright © 2006–2013 Jasig. All rights reserved.