-
Notifications
You must be signed in to change notification settings - Fork 6.1k
SAML AuthNRequest Signatures - Step 1 #7758
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
...rk/security/saml2/provider/service/authentication/AbstractSaml2AuthenticationRequest.java
This file contains hidden or 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,148 @@ | ||
/* | ||
* Copyright 2002-2020 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.saml2.provider.service.authentication; | ||
|
||
import org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding; | ||
import org.springframework.util.Assert; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
/** | ||
* Data holder for {@code AuthNRequest} parameters to be sent using either the | ||
* {@link Saml2MessageBinding#POST} or {@link Saml2MessageBinding#REDIRECT} binding. | ||
* Data will be encoded and possibly deflated, but will not be escaped for transport, | ||
* ie URL encoded, {@link org.springframework.web.util.UriUtils#encode(String, Charset)} | ||
* or HTML encoded, {@link org.springframework.web.util.HtmlUtils#htmlEscape(String)}. | ||
* https://www.oasis-open.org/committees/download.php/35711/sstc-saml-core-errata-2.0-wd-06-diff.pdf (line 2031) | ||
* | ||
* @see Saml2AuthenticationRequestFactory#createPostAuthenticationRequest(Saml2AuthenticationRequestContext) | ||
* @see Saml2AuthenticationRequestFactory#createRedirectAuthenticationRequest(Saml2AuthenticationRequestContext) | ||
* @since 5.3 | ||
*/ | ||
abstract class AbstractSaml2AuthenticationRequest { | ||
|
||
private final String samlRequest; | ||
private final String relayState; | ||
private final String authenticationRequestUri; | ||
|
||
/** | ||
* Mandatory constructor for the {@link AbstractSaml2AuthenticationRequest} | ||
* @param samlRequest - the SAMLRequest XML data, SAML encoded, cannot be empty or null | ||
* @param relayState - RelayState value that accompanies the request, may be null | ||
* @param authenticationRequestUri - The authenticationRequestUri, a URL, where to send the XML message, cannot be empty or null | ||
*/ | ||
AbstractSaml2AuthenticationRequest( | ||
String samlRequest, | ||
String relayState, | ||
String authenticationRequestUri) { | ||
Assert.hasText(samlRequest, "samlRequest cannot be null or empty"); | ||
Assert.hasText(authenticationRequestUri, "authenticationRequestUri cannot be null or empty"); | ||
this.authenticationRequestUri = authenticationRequestUri; | ||
this.samlRequest = samlRequest; | ||
this.relayState = relayState; | ||
} | ||
|
||
/** | ||
* Returns the AuthNRequest XML value to be sent. This value is already encoded for transport. | ||
* If {@link #getBinding()} is {@link Saml2MessageBinding#REDIRECT} the value is deflated and SAML encoded. | ||
* If {@link #getBinding()} is {@link Saml2MessageBinding#POST} the value is SAML encoded. | ||
* @return the SAMLRequest parameter value | ||
*/ | ||
public String getSamlRequest() { | ||
return this.samlRequest; | ||
} | ||
|
||
/** | ||
* Returns the RelayState value, if present in the parameters | ||
* @return the RelayState value, or null if not available | ||
*/ | ||
public String getRelayState() { | ||
return this.relayState; | ||
} | ||
|
||
/** | ||
* Returns the URI endpoint that this AuthNRequest should be sent to. | ||
* @return the URI endpoint for this message | ||
*/ | ||
public String getAuthenticationRequestUri() { | ||
return this.authenticationRequestUri; | ||
} | ||
|
||
/** | ||
* Returns the binding this AuthNRequest will be sent and | ||
* encoded with. If {@link Saml2MessageBinding#REDIRECT} is used, the DEFLATE encoding will be automatically applied. | ||
* @return the binding this message will be sent with. | ||
*/ | ||
public abstract Saml2MessageBinding getBinding(); | ||
|
||
/** | ||
* A builder for {@link AbstractSaml2AuthenticationRequest} and its subclasses. | ||
*/ | ||
static class Builder<T extends Builder<T>> { | ||
String authenticationRequestUri; | ||
String samlRequest; | ||
String relayState; | ||
|
||
protected Builder() { | ||
} | ||
|
||
/** | ||
* Casting the return as the generic subtype, when returning itself | ||
* @return this object | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
protected final T _this() { | ||
return (T) this; | ||
} | ||
|
||
|
||
/** | ||
* Sets the {@code RelayState} parameter that will accompany this AuthNRequest | ||
* | ||
* @param relayState the relay state value, unencoded. if null or empty, the parameter will be removed from the | ||
* map. | ||
* @return this object | ||
*/ | ||
public T relayState(String relayState) { | ||
this.relayState = relayState; | ||
return _this(); | ||
} | ||
|
||
/** | ||
* Sets the {@code SAMLRequest} parameter that will accompany this AuthNRequest | ||
* | ||
* @param samlRequest the SAMLRequest parameter. | ||
* @return this object | ||
*/ | ||
public T samlRequest(String samlRequest) { | ||
this.samlRequest = samlRequest; | ||
return _this(); | ||
} | ||
|
||
/** | ||
* Sets the {@code authenticationRequestUri}, a URL that will receive the AuthNRequest message | ||
* | ||
* @param authenticationRequestUri the relay state value, unencoded. | ||
* @return this object | ||
*/ | ||
public T authenticationRequestUri(String authenticationRequestUri) { | ||
this.authenticationRequestUri = authenticationRequestUri; | ||
return _this(); | ||
} | ||
} | ||
|
||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When you are cleaning up the commit log, this should probably go into a separate commit since it isn't about signature support.