-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored out Servlet dependencies from core and toolkit #395
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.onelogin.saml2.http; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class HttpRequestUtils { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see this class used anywhere in core. It should either be moved or removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
private HttpRequestUtils() { | ||
} | ||
|
||
/** | ||
* Returns the protocol + the current host + the port (if different than | ||
* common ports). | ||
* | ||
* @param request | ||
* HttpServletRequest object to be processed | ||
* | ||
* @return the HOST URL | ||
*/ | ||
public static String getSelfURLhost(HttpRequest request) { | ||
String hostUrl = StringUtils.EMPTY; | ||
final int serverPort = request.getServerPort(); | ||
if ((serverPort == 80) || (serverPort == 443) || serverPort == 0) { | ||
hostUrl = String.format("%s://%s", request.getScheme(), request.getServerName()); | ||
} else { | ||
hostUrl = String.format("%s://%s:%s", request.getScheme(), request.getServerName(), serverPort); | ||
} | ||
return hostUrl; | ||
} | ||
|
||
/** | ||
* Returns the URL of the current context + current view + query | ||
* | ||
* @param request | ||
* HttpServletRequest object to be processed | ||
* | ||
* @return current context + current view + query | ||
*/ | ||
public static String getSelfURL(HttpRequest request) { | ||
String url = getSelfURLhost(request); | ||
|
||
String requestUri = request.getRequestURI(); | ||
String queryString = request.getQueryString(); | ||
|
||
if (null != requestUri && !requestUri.isEmpty()) { | ||
url += requestUri; | ||
} | ||
|
||
if (null != queryString && !queryString.isEmpty()) { | ||
url += '?' + queryString; | ||
} | ||
return url; | ||
} | ||
|
||
/** | ||
* Returns the URL of the current host + current view. | ||
* | ||
* @param request | ||
* HttpServletRequest object to be processed | ||
* | ||
* @return current host + current view | ||
*/ | ||
public static String getSelfURLNoQuery(HttpRequest request) { | ||
return request.getRequestURL(); | ||
} | ||
|
||
/** | ||
* Returns the routed URL of the current host + current view. | ||
* | ||
* @param request | ||
* HttpServletRequest object to be processed | ||
* | ||
* @return the current routed url | ||
*/ | ||
public static String getSelfRoutedURLNoQuery(HttpRequest request) { | ||
String url = getSelfURLhost(request); | ||
String requestUri = request.getRequestURI(); | ||
if (null != requestUri && !requestUri.isEmpty()) { | ||
url += requestUri; | ||
} | ||
return url; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.onelogin.saml2.http; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Framework-agnostic definition of an HTTP response with a very minimal set of | ||
* methods needed to support the SAML handshake. | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
public interface HttpResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
void sendRedirect(String location) throws IOException; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK calling this interface
SamlHttpRequest
orOneLoginSamlHttpRequest
if the existing name is too generic.Three implementors in this PR: