-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored out Servlet dependencies from core and toolkit
- Introduced `servlet-jakarta` and `servlet-javax` - Teased apart HTTP request and HTTP response objects along a common seam - Bumped version to 3.0.0
- Loading branch information
1 parent
5a58410
commit d5dbbde
Showing
32 changed files
with
1,409 additions
and
1,270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
core/src/main/java/com/onelogin/saml2/http/HttpRequestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
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; | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
core/src/main/java/com/onelogin/saml2/http/HttpResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
void sendRedirect(String location) throws IOException; | ||
|
||
} |
Oops, something went wrong.