Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit a871c61

Browse files
authored
Merge pull request #1155 from stormpath/issue-1136-stormpath-idp-flow-support
Issue 1136 stormpath idp flow support
2 parents 41a057e + b28e97f commit a871c61

File tree

17 files changed

+651
-17
lines changed

17 files changed

+651
-17
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.stormpath.sdk.saml;
2+
3+
import com.stormpath.sdk.application.Application;
4+
import com.stormpath.sdk.resource.Resource;
5+
6+
import java.util.Date;
7+
8+
/**
9+
* An AuthnVerification represents the successful results of verifying the signature of a SAML AuthnRequest targeted
10+
* against a particular Stormpath {@link Application}.
11+
*
12+
* @since 1.3.0
13+
*/
14+
public interface AuthnVerification extends Resource {
15+
16+
/**
17+
* Returns the relay state provided with the original SAML AuthnRequest, if any was provided. Otherwise the default
18+
* relay state configured for the {@link Application}.
19+
*
20+
* @return the relay state associated with the SAML AuthnRequest.
21+
*/
22+
String getRelayState();
23+
24+
/**
25+
* Returns the {@link RegisteredSamlServiceProvider} associated with the entityId of the original AuthnRequest.
26+
*
27+
* @return the {@link RegisteredSamlServiceProvider} associated with the entityId of the original AuthnRequest.
28+
*/
29+
RegisteredSamlServiceProvider getServiceProvider();
30+
31+
32+
/**
33+
* Returns the request ID provided with the original SAML AuthnRequest.
34+
*
35+
* @return the request ID provided with the original SAML AuthnRequest.
36+
*/
37+
String getRequestId();
38+
39+
40+
/**
41+
* Returns the issue instant of the original SAML AuthnRequest.
42+
*
43+
* @return the issue instant of the original SAML AuthnRequest.
44+
*/
45+
Date getAuthnIssueInstant();
46+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.stormpath.sdk.saml;
2+
3+
import com.stormpath.sdk.resource.Resource;
4+
5+
/**
6+
* An AuthnVerificationRequest encapsulates the fields of a SAML AuthnRequest targeted
7+
* against a particular Stormpath Application.
8+
*
9+
* @since 1.3.0
10+
*/
11+
public interface AuthnVerificationRequest extends Resource {
12+
13+
/**
14+
* Returns the value of the SAMLRequest parameter provided with the incoming AuthnRequest.
15+
*
16+
* @return the value of the SAMLRequest parameter provided with the incoming AuthnRequest.
17+
*/
18+
String getSamlRequest();
19+
20+
/**
21+
* Sets the value of the SAMLRequest parameter provided with the incoming AuthnRequest.
22+
*
23+
* @param samlRequest the value of the SAMLRequest parameter from the incoming AuthnRequest.
24+
* @return this instance for method chaining.
25+
*/
26+
AuthnVerificationRequest setSamlRequest(String samlRequest);
27+
28+
/**
29+
* Returns the value of the RelayState parameter provided with the incoming AuthnRequest.
30+
*
31+
* @return the value of the RelayState parameter provided with the incoming AuthnRequest.
32+
*/
33+
String getRelayState();
34+
35+
/**
36+
* Sets the value of the RelayState parameter provided with the incoming AuthnRequest.
37+
*
38+
* @param relayState the value of the RelayState parameter from the incoming AuthnRequest.
39+
* @return this instance for method chaining.
40+
*/
41+
AuthnVerificationRequest setRelayState(String relayState);
42+
43+
/**
44+
* Returns the value of the SigAlg parameter provided with the incoming AuthnRequest.
45+
*
46+
* @return the value of the SigAlg parameter provided with the incoming AuthnRequest.
47+
*/
48+
String getSigAlg();
49+
50+
/**
51+
* Sets the value of the SigAlg parameter provided with the incoming AuthnRequest.
52+
*
53+
* @param sigAlg the value of the SigAlg parameter from the incoming AuthnRequest.
54+
* @return this instance for method chaining.
55+
*/
56+
AuthnVerificationRequest setSigAlg(String sigAlg);
57+
58+
/**
59+
* Returns the value of the Signature parameter provided with the incoming AuthnRequest.
60+
*
61+
* @return the value of the Signature parameter provided with the incoming AuthnRequest.
62+
*/
63+
String getSignature();
64+
65+
/**
66+
* Sets the value of the Signature parameter provided with the incoming AuthnRequest.
67+
*
68+
* @param signature the value of the Signature parameter from the incoming AuthnRequest.
69+
* @return this instance for method chaining.
70+
*/
71+
AuthnVerificationRequest setSignature(String signature);
72+
73+
/**
74+
* When the AuthnRequest is submitted via HTTP GET, returns the query string of the incoming request.
75+
* Otherwise null.
76+
*
77+
* @return the query string of the incoming AuthnRequest, or null if the AuthnRequest was submitted with HTTP POST.
78+
*/
79+
String getQueryString();
80+
81+
AuthnVerificationRequest setQueryString(String queryString);
82+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.stormpath.sdk.saml;
2+
3+
import com.stormpath.sdk.account.Account;
4+
import com.stormpath.sdk.resource.Resource;
5+
6+
import java.util.Date;
7+
8+
/**
9+
* A SamlResponseRequest encapsulates the information needed to prepare a SAML response according to the SAML specification.
10+
*
11+
* @since 1.3.0
12+
*/
13+
public interface CreateSamlResponseRequest extends Resource {
14+
15+
/**
16+
* Returns the {@link Account} to be represented in this SAML response.
17+
*
18+
* @return the {@link Account} to be represented in this SAML response.
19+
*/
20+
Account getAccount();
21+
22+
/**
23+
* Sets the {@link Account} to be represented in this SAML response.
24+
*
25+
* @param account the {@link Account} to be represented in this SAML response.
26+
* @return this instance for method chaining.
27+
*/
28+
CreateSamlResponseRequest setAccount(Account account);
29+
30+
/**
31+
* Returns the {@link RegisteredSamlServiceProvider} to be represented in this SAML response.
32+
*
33+
* @return the {@link RegisteredSamlServiceProvider} to be represented in this SAML response.
34+
*/
35+
RegisteredSamlServiceProvider getServiceProvider();
36+
37+
/**
38+
* Sets the {@link RegisteredSamlServiceProvider} to be represented in this SAML response.
39+
*
40+
* @param serviceProvider the {@link RegisteredSamlServiceProvider} to be represented in this SAML response.
41+
* @return this instance for method chaining.
42+
*/
43+
CreateSamlResponseRequest setServiceProvider(RegisteredSamlServiceProvider serviceProvider);
44+
45+
/**
46+
* Returns the request ID to be represented in this SAML response, which should match the request ID
47+
* that was provided in the initiating SAML AuthnRequest.
48+
*
49+
* @return the request ID to be represented in this SAML response.
50+
*/
51+
String getRequestId();
52+
53+
/**
54+
* Sets the request ID to be represented in this SAML response, which should match the request ID
55+
* that was provided in the initiating SAML AuthnRequest.
56+
*
57+
* @param requestId the request ID to be represented in this SAML response.
58+
* @return this instance for method chaining.
59+
*/
60+
CreateSamlResponseRequest setRequestId(String requestId);
61+
62+
/**
63+
* Returns the issue instant to be represented in this SAML response, which should match the issue instant
64+
* that was provided in the initiating SAML AuthnRequest.
65+
*
66+
* @return the issue instant to be represented in this SAML response.
67+
*/
68+
Date getAuthnIssueInstant();
69+
70+
/**
71+
* Sets the issue instant to be represented in this SAML response, which should match the issue instant
72+
* that was provided in the initiating SAML AuthnRequest.
73+
*
74+
* @param authnIssueInstant the issue instant to be represented in this SAML response.
75+
* @return this instance for method chaining.
76+
*/
77+
CreateSamlResponseRequest setAuthnIssueInstant(Date authnIssueInstant);
78+
}

api/src/main/java/com/stormpath/sdk/saml/SamlIdentityProvider.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,23 @@ public interface SamlIdentityProvider extends Resource, Saveable, Deletable, Aud
195195
* @return a paginated list of the samlIdentityProvider's samlServiceProviderRegistrations that match the specified query criteria.
196196
*/
197197
SamlServiceProviderRegistrationList getSamlServiceProviderRegistrations(SamlServiceProviderRegistrationCriteria criteria);
198+
199+
/**
200+
* Given an {@link AuthnVerificationRequest} wrapping an incoming SAML AuthnRequest, verifies that the request targets a
201+
* {@link RegisteredSamlServiceProvider} that is registered with this identity provider, and validates the signature of
202+
* the request if one is provided.
203+
*
204+
* @param request the request to be verified.
205+
* @return an {@link AuthnVerification} containing the state to be passed along during the SAML flow.
206+
*/
207+
AuthnVerification createAuthnVerification(AuthnVerificationRequest request);
208+
209+
/**
210+
* Given a {@link CreateSamlResponseRequest} for a given {@link com.stormpath.sdk.account.Account} and {@link RegisteredSamlServiceProvider},
211+
* creates a {@link SamlResponse} wrapping the XML of the SAML response to be returned to the service provider.
212+
*
213+
* @param samlResponseRequest a {@link CreateSamlResponseRequest} wrapping the values needed to prepare the SAML response.
214+
* @return a {@link SamlResponse} wrapping the XML of the SAML response to be returned to the service provider.
215+
*/
216+
SamlResponse createSamlResponse(CreateSamlResponseRequest samlResponseRequest);
198217
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.stormpath.sdk.saml;
2+
3+
import com.stormpath.sdk.resource.Resource;
4+
5+
/**
6+
* A SamlResponse has a single field whose value is the base 64 encoded XML of a SAML response according to the SAML specification.
7+
*
8+
* @since 1.3.0
9+
*/
10+
public interface SamlResponse extends Resource {
11+
12+
/**
13+
* Returns the base 64 encoded XML of the SAML response..
14+
*
15+
* @return the base 64 encoded XML of the SAML response.
16+
*/
17+
String getValue();
18+
}

extensions/httpclient/src/test/groovy/com/stormpath/sdk/impl/saml/AbstractSamlIT.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import static org.testng.Assert.assertTrue
3131
/**
3232
* @since 1.3.0
3333
*/
34-
abstract class AbstractSamlIT extends ClientIT{
34+
abstract class AbstractSamlIT extends ClientIT {
3535
public static String validX509Cert = '''-----BEGIN CERTIFICATE-----
3636
MIIDBjCCAe4CCQDkkfBwuV3jqTANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJV
3737
UzETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0
@@ -75,23 +75,23 @@ xu/vQr6stjuzJIsDNAtW1FlG8WALOMjV
7575
'''
7676

7777

78-
protected SamlIdentityProvider getNewSamlIdentityProviderForNewApplication(){
78+
protected SamlIdentityProvider getNewSamlIdentityProviderForNewApplication() {
7979
def app = createTempApp()
8080
return getSamlIdentityProviderForApplication(app)
8181
}
8282

83-
protected SamlIdentityProvider getSamlIdentityProviderForApplication(Application app){
83+
protected SamlIdentityProvider getSamlIdentityProviderForApplication(Application app) {
8484
def samlPolicy = client.getResource(app.getSamlPolicy().href, SamlPolicy)
8585
samlPolicy.getIdentityProvider()
8686
return client.getResource(samlPolicy.getIdentityProvider().href, SamlIdentityProvider)
8787
}
8888

89-
protected SamlIdentityProvider getSamlIdentityProviderForDefaultApplication(){
89+
protected SamlIdentityProvider getSamlIdentityProviderForDefaultApplication() {
9090
def app = client.currentTenant.getApplications(Applications.where(Applications.name().eqIgnoreCase("Stormpath"))).asList().get(0)
9191
return getSamlIdentityProviderForApplication(app)
9292
}
9393

94-
protected SamlServiceProviderRegistration createAndGetAndAssertNewRegistration(SamlServiceProviderRegistration registration){
94+
protected SamlServiceProviderRegistration createAndGetAndAssertNewRegistration(SamlServiceProviderRegistration registration) {
9595
def identityProviderHref = registration.getIdentityProvider().href
9696
def builder = SamlServiceProviderRegistrations.newCreateRequestFor(registration)
9797
registration = registration.getIdentityProvider().createSamlServiceProviderRegistration(builder.build())
@@ -105,7 +105,7 @@ xu/vQr6stjuzJIsDNAtW1FlG8WALOMjV
105105
return registration
106106
}
107107

108-
protected void createNewRegistrationError(SamlServiceProviderRegistration registration, int expectedErrorCode){
108+
protected void createNewRegistrationError(SamlServiceProviderRegistration registration, int expectedErrorCode) {
109109
def builder = SamlServiceProviderRegistrations.newCreateRequestFor(registration)
110110

111111
Throwable e = null;

extensions/httpclient/src/test/groovy/com/stormpath/sdk/impl/saml/SAMLServiceProviderRegistrationIT.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.testng.annotations.Test
1212
import static org.testng.AssertJUnit.assertEquals
1313
import static org.testng.AssertJUnit.assertNotNull
1414

15-
class SamlServiceProviderRegistrationIT extends AbstractSamlIT{
15+
class SamlServiceProviderRegistrationIT extends AbstractSamlIT {
1616

1717
@AfterMethod
1818
public void cleanUp() {

0 commit comments

Comments
 (0)