Always use 'this.' when accessing fields
Apply an Eclipse cleanup rules to ensure that fields are always accessed using `this.`. This aligns with the style used by Spring Framework and helps users quickly see the difference between a local and member variable. Issue gh-8945
This commit is contained in:
+1
-1
@@ -174,7 +174,7 @@ public class Saml2AuthenticationException extends AuthenticationException {
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuffer sb = new StringBuffer("Saml2AuthenticationException{");
|
||||
sb.append("error=").append(error);
|
||||
sb.append("error=").append(this.error);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public final class Saml2AuthenticationRequest {
|
||||
* @return the AssertionConsumerServiceURL value
|
||||
*/
|
||||
public String getAssertionConsumerServiceUrl() {
|
||||
return assertionConsumerServiceUrl;
|
||||
return this.assertionConsumerServiceUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ public class Saml2AuthenticationRequestContext {
|
||||
* @return the AssertionConsumerServiceURL value
|
||||
*/
|
||||
public String getAssertionConsumerServiceUrl() {
|
||||
return assertionConsumerServiceUrl;
|
||||
return this.assertionConsumerServiceUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public enum Saml2MessageBinding {
|
||||
* @return URN value representing this binding
|
||||
*/
|
||||
public String getUrn() {
|
||||
return urn;
|
||||
return this.urn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+38
-38
@@ -60,7 +60,7 @@ public class Saml2X509CredentialTests {
|
||||
+ "YX/sDTE2AdVBVGaMj1Cb51bPHnNC6Q5kXKQnj/YrLqRQND09Q7ParX0CQQC5NxZr\n"
|
||||
+ "9jKqhHj8yQD6PlXTsY4Occ7DH6/IoDenfdEVD5qlet0zmd50HatN2Jiqm5ubN7CM\n" + "INrtuLp4YHbgk1mi\n"
|
||||
+ "-----END PRIVATE KEY-----";
|
||||
key = RsaKeyConverters.pkcs8().convert(new ByteArrayInputStream(keyData.getBytes(UTF_8)));
|
||||
this.key = RsaKeyConverters.pkcs8().convert(new ByteArrayInputStream(keyData.getBytes(UTF_8)));
|
||||
final CertificateFactory factory = CertificateFactory.getInstance("X.509");
|
||||
String certificateData = "-----BEGIN CERTIFICATE-----\n"
|
||||
+ "MIICgTCCAeoCCQCuVzyqFgMSyDANBgkqhkiG9w0BAQsFADCBhDELMAkGA1UEBhMC\n"
|
||||
@@ -77,121 +77,121 @@ public class Saml2X509CredentialTests {
|
||||
+ "XOfI2Z9eukwrSknDwq/zscR0YxwwqDBMt/QdAODfSwAfnciiYLkmEjlozWRtOeN+\n"
|
||||
+ "qK7UFgP1bRl5qksrYX5S0z2iGJh0GvonLUt3e20Ssfl5tTEDDnAEUMLfBkyaxEHD\n"
|
||||
+ "RZ/nbTJ7VTeZOSyRoVn5XHhpuJ0B\n" + "-----END CERTIFICATE-----";
|
||||
certificate = (X509Certificate) factory
|
||||
this.certificate = (X509Certificate) factory
|
||||
.generateCertificate(new ByteArrayInputStream(certificateData.getBytes(UTF_8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithCredentialsThenItSucceeds() {
|
||||
new Saml2X509Credential(key, certificate, SIGNING);
|
||||
new Saml2X509Credential(key, certificate, SIGNING, DECRYPTION);
|
||||
new Saml2X509Credential(key, certificate, DECRYPTION);
|
||||
Saml2X509Credential.signing(key, certificate);
|
||||
Saml2X509Credential.decryption(key, certificate);
|
||||
new Saml2X509Credential(this.key, this.certificate, SIGNING);
|
||||
new Saml2X509Credential(this.key, this.certificate, SIGNING, DECRYPTION);
|
||||
new Saml2X509Credential(this.key, this.certificate, DECRYPTION);
|
||||
Saml2X509Credential.signing(this.key, this.certificate);
|
||||
Saml2X509Credential.decryption(this.key, this.certificate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenAssertingPartyWithCredentialsThenItSucceeds() {
|
||||
new Saml2X509Credential(certificate, VERIFICATION);
|
||||
new Saml2X509Credential(certificate, VERIFICATION, ENCRYPTION);
|
||||
new Saml2X509Credential(certificate, ENCRYPTION);
|
||||
Saml2X509Credential.verification(certificate);
|
||||
Saml2X509Credential.encryption(certificate);
|
||||
new Saml2X509Credential(this.certificate, VERIFICATION);
|
||||
new Saml2X509Credential(this.certificate, VERIFICATION, ENCRYPTION);
|
||||
new Saml2X509Credential(this.certificate, ENCRYPTION);
|
||||
Saml2X509Credential.verification(this.certificate);
|
||||
Saml2X509Credential.encryption(this.certificate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithoutCredentialsThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(null, (X509Certificate) null, SIGNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithoutPrivateKeyThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(null, certificate, SIGNING);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(null, this.certificate, SIGNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithoutCertificateThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(key, null, SIGNING);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(this.key, null, SIGNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenAssertingPartyWithoutCertificateThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(null, SIGNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithEncryptionUsageThenItFails() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(key, certificate, ENCRYPTION);
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(this.key, this.certificate, ENCRYPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithVerificationUsageThenItFails() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(key, certificate, VERIFICATION);
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(this.key, this.certificate, VERIFICATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenAssertingPartyWithSigningUsageThenItFails() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(certificate, SIGNING);
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(this.certificate, SIGNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenAssertingPartyWithDecryptionUsageThenItFails() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(certificate, DECRYPTION);
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(this.certificate, DECRYPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryWhenRelyingPartyForSigningWithoutCredentialsThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.signing(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryWhenRelyingPartyForSigningWithoutPrivateKeyThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.signing(null, certificate);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.signing(null, this.certificate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryWhenRelyingPartyForSigningWithoutCertificateThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.signing(key, null);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.signing(this.key, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryWhenRelyingPartyForDecryptionWithoutCredentialsThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.decryption(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryWhenRelyingPartyForDecryptionWithoutPrivateKeyThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.decryption(null, certificate);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.decryption(null, this.certificate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryWhenRelyingPartyForDecryptionWithoutCertificateThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.decryption(key, null);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.decryption(this.key, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryWhenAssertingPartyForVerificationWithoutCertificateThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.verification(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryWhenAssertingPartyForEncryptionWithoutCertificateThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
Saml2X509Credential.encryption(null);
|
||||
}
|
||||
|
||||
|
||||
+22
-22
@@ -62,7 +62,7 @@ public class Saml2X509CredentialTests {
|
||||
+ "YX/sDTE2AdVBVGaMj1Cb51bPHnNC6Q5kXKQnj/YrLqRQND09Q7ParX0CQQC5NxZr\n"
|
||||
+ "9jKqhHj8yQD6PlXTsY4Occ7DH6/IoDenfdEVD5qlet0zmd50HatN2Jiqm5ubN7CM\n" + "INrtuLp4YHbgk1mi\n"
|
||||
+ "-----END PRIVATE KEY-----";
|
||||
key = RsaKeyConverters.pkcs8().convert(new ByteArrayInputStream(keyData.getBytes(UTF_8)));
|
||||
this.key = RsaKeyConverters.pkcs8().convert(new ByteArrayInputStream(keyData.getBytes(UTF_8)));
|
||||
final CertificateFactory factory = CertificateFactory.getInstance("X.509");
|
||||
String certificateData = "-----BEGIN CERTIFICATE-----\n"
|
||||
+ "MIICgTCCAeoCCQCuVzyqFgMSyDANBgkqhkiG9w0BAQsFADCBhDELMAkGA1UEBhMC\n"
|
||||
@@ -79,70 +79,70 @@ public class Saml2X509CredentialTests {
|
||||
+ "XOfI2Z9eukwrSknDwq/zscR0YxwwqDBMt/QdAODfSwAfnciiYLkmEjlozWRtOeN+\n"
|
||||
+ "qK7UFgP1bRl5qksrYX5S0z2iGJh0GvonLUt3e20Ssfl5tTEDDnAEUMLfBkyaxEHD\n"
|
||||
+ "RZ/nbTJ7VTeZOSyRoVn5XHhpuJ0B\n" + "-----END CERTIFICATE-----";
|
||||
certificate = (X509Certificate) factory
|
||||
this.certificate = (X509Certificate) factory
|
||||
.generateCertificate(new ByteArrayInputStream(certificateData.getBytes(UTF_8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithCredentialsThenItSucceeds() {
|
||||
new Saml2X509Credential(key, certificate, SIGNING);
|
||||
new Saml2X509Credential(key, certificate, SIGNING, DECRYPTION);
|
||||
new Saml2X509Credential(key, certificate, DECRYPTION);
|
||||
new Saml2X509Credential(this.key, this.certificate, SIGNING);
|
||||
new Saml2X509Credential(this.key, this.certificate, SIGNING, DECRYPTION);
|
||||
new Saml2X509Credential(this.key, this.certificate, DECRYPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenAssertingPartyWithCredentialsThenItSucceeds() {
|
||||
new Saml2X509Credential(certificate, VERIFICATION);
|
||||
new Saml2X509Credential(certificate, VERIFICATION, ENCRYPTION);
|
||||
new Saml2X509Credential(certificate, ENCRYPTION);
|
||||
new Saml2X509Credential(this.certificate, VERIFICATION);
|
||||
new Saml2X509Credential(this.certificate, VERIFICATION, ENCRYPTION);
|
||||
new Saml2X509Credential(this.certificate, ENCRYPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithoutCredentialsThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(null, (X509Certificate) null, SIGNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithoutPrivateKeyThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(null, certificate, SIGNING);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(null, this.certificate, SIGNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithoutCertificateThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(key, null, SIGNING);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(this.key, null, SIGNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenAssertingPartyWithoutCertificateThenItFails() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
new Saml2X509Credential(null, SIGNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithEncryptionUsageThenItFails() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(key, certificate, ENCRYPTION);
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(this.key, this.certificate, ENCRYPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenRelyingPartyWithVerificationUsageThenItFails() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(key, certificate, VERIFICATION);
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(this.key, this.certificate, VERIFICATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenAssertingPartyWithSigningUsageThenItFails() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(certificate, SIGNING);
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(this.certificate, SIGNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenAssertingPartyWithDecryptionUsageThenItFails() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(certificate, DECRYPTION);
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
new Saml2X509Credential(this.certificate, DECRYPTION);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+24
-23
@@ -80,25 +80,26 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
.providerDetails(c -> c.entityId("remote-entity-id")).localEntityIdTemplate("local-entity-id")
|
||||
.credentials(c -> c.add(relyingPartySigningCredential()));
|
||||
this.relyingPartyRegistration = this.relyingPartyRegistrationBuilder.build();
|
||||
contextBuilder = Saml2AuthenticationRequestContext.builder().issuer("https://issuer")
|
||||
.relyingPartyRegistration(relyingPartyRegistration).assertionConsumerServiceUrl("https://issuer/sso");
|
||||
context = contextBuilder.build();
|
||||
factory = new OpenSamlAuthenticationRequestFactory();
|
||||
this.contextBuilder = Saml2AuthenticationRequestContext.builder().issuer("https://issuer")
|
||||
.relyingPartyRegistration(this.relyingPartyRegistration)
|
||||
.assertionConsumerServiceUrl("https://issuer/sso");
|
||||
this.context = this.contextBuilder.build();
|
||||
this.factory = new OpenSamlAuthenticationRequestFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAuthenticationRequestWhenInvokingDeprecatedMethodThenReturnsXML() {
|
||||
Saml2AuthenticationRequest request = Saml2AuthenticationRequest.withAuthenticationRequestContext(context)
|
||||
Saml2AuthenticationRequest request = Saml2AuthenticationRequest.withAuthenticationRequestContext(this.context)
|
||||
.build();
|
||||
String result = factory.createAuthenticationRequest(request);
|
||||
String result = this.factory.createAuthenticationRequest(request);
|
||||
assertThat(result.replace("\n", ""))
|
||||
.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><saml2p:AuthnRequest");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createRedirectAuthenticationRequestWhenUsingContextThenAllValuesAreSet() {
|
||||
context = contextBuilder.relayState("Relay State Value").build();
|
||||
Saml2RedirectAuthenticationRequest result = factory.createRedirectAuthenticationRequest(context);
|
||||
this.context = this.contextBuilder.relayState("Relay State Value").build();
|
||||
Saml2RedirectAuthenticationRequest result = this.factory.createRedirectAuthenticationRequest(this.context);
|
||||
assertThat(result.getSamlRequest()).isNotEmpty();
|
||||
assertThat(result.getRelayState()).isEqualTo("Relay State Value");
|
||||
assertThat(result.getSigAlg()).isNotEmpty();
|
||||
@@ -109,11 +110,11 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
@Test
|
||||
public void createRedirectAuthenticationRequestWhenNotSignRequestThenNoSignatureIsPresent() {
|
||||
|
||||
context = contextBuilder.relayState("Relay State Value")
|
||||
.relyingPartyRegistration(withRelyingPartyRegistration(relyingPartyRegistration)
|
||||
this.context = this.contextBuilder.relayState("Relay State Value")
|
||||
.relyingPartyRegistration(withRelyingPartyRegistration(this.relyingPartyRegistration)
|
||||
.providerDetails(c -> c.signAuthNRequest(false)).build())
|
||||
.build();
|
||||
Saml2RedirectAuthenticationRequest result = factory.createRedirectAuthenticationRequest(context);
|
||||
Saml2RedirectAuthenticationRequest result = this.factory.createRedirectAuthenticationRequest(this.context);
|
||||
assertThat(result.getSamlRequest()).isNotEmpty();
|
||||
assertThat(result.getRelayState()).isEqualTo("Relay State Value");
|
||||
assertThat(result.getSigAlg()).isNull();
|
||||
@@ -123,11 +124,11 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
|
||||
@Test
|
||||
public void createPostAuthenticationRequestWhenNotSignRequestThenNoSignatureIsPresent() {
|
||||
context = contextBuilder.relayState("Relay State Value")
|
||||
.relyingPartyRegistration(withRelyingPartyRegistration(relyingPartyRegistration)
|
||||
this.context = this.contextBuilder.relayState("Relay State Value")
|
||||
.relyingPartyRegistration(withRelyingPartyRegistration(this.relyingPartyRegistration)
|
||||
.providerDetails(c -> c.signAuthNRequest(false)).build())
|
||||
.build();
|
||||
Saml2PostAuthenticationRequest result = factory.createPostAuthenticationRequest(context);
|
||||
Saml2PostAuthenticationRequest result = this.factory.createPostAuthenticationRequest(this.context);
|
||||
assertThat(result.getSamlRequest()).isNotEmpty();
|
||||
assertThat(result.getRelayState()).isEqualTo("Relay State Value");
|
||||
assertThat(result.getBinding()).isEqualTo(POST);
|
||||
@@ -136,9 +137,9 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
|
||||
@Test
|
||||
public void createPostAuthenticationRequestWhenSignRequestThenSignatureIsPresent() {
|
||||
context = contextBuilder.relayState("Relay State Value")
|
||||
.relyingPartyRegistration(withRelyingPartyRegistration(relyingPartyRegistration).build()).build();
|
||||
Saml2PostAuthenticationRequest result = factory.createPostAuthenticationRequest(context);
|
||||
this.context = this.contextBuilder.relayState("Relay State Value")
|
||||
.relyingPartyRegistration(withRelyingPartyRegistration(this.relyingPartyRegistration).build()).build();
|
||||
Saml2PostAuthenticationRequest result = this.factory.createPostAuthenticationRequest(this.context);
|
||||
assertThat(result.getSamlRequest()).isNotEmpty();
|
||||
assertThat(result.getRelayState()).isEqualTo("Relay State Value");
|
||||
assertThat(result.getBinding()).isEqualTo(POST);
|
||||
@@ -153,16 +154,16 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
|
||||
@Test
|
||||
public void createAuthenticationRequestWhenSetUriThenReturnsCorrectBinding() {
|
||||
factory.setProtocolBinding(SAMLConstants.SAML2_REDIRECT_BINDING_URI);
|
||||
this.factory.setProtocolBinding(SAMLConstants.SAML2_REDIRECT_BINDING_URI);
|
||||
AuthnRequest authn = getAuthNRequest(POST);
|
||||
Assert.assertEquals(SAMLConstants.SAML2_REDIRECT_BINDING_URI, authn.getProtocolBinding());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAuthenticationRequestWhenSetUnsupportredUriThenThrowsIllegalArgumentException() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage(containsString("my-invalid-binding"));
|
||||
factory.setProtocolBinding("my-invalid-binding");
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expectMessage(containsString("my-invalid-binding"));
|
||||
this.factory.setProtocolBinding("my-invalid-binding");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -209,8 +210,8 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
|
||||
private AuthnRequest getAuthNRequest(Saml2MessageBinding binding) {
|
||||
AbstractSaml2AuthenticationRequest result = (binding == REDIRECT)
|
||||
? factory.createRedirectAuthenticationRequest(context)
|
||||
: factory.createPostAuthenticationRequest(context);
|
||||
? this.factory.createRedirectAuthenticationRequest(this.context)
|
||||
: this.factory.createPostAuthenticationRequest(this.context);
|
||||
String samlRequest = result.getSamlRequest();
|
||||
assertThat(samlRequest).isNotEmpty();
|
||||
if (result.getBinding() == REDIRECT) {
|
||||
|
||||
+2
-2
@@ -43,7 +43,7 @@ public class Saml2AuthenticationRequestFactoryTests {
|
||||
final String value = "Test String: " + UUID.randomUUID().toString();
|
||||
Saml2AuthenticationRequestFactory factory = request -> value;
|
||||
Saml2AuthenticationRequestContext request = Saml2AuthenticationRequestContext.builder()
|
||||
.relyingPartyRegistration(registration).issuer("https://example.com/issuer")
|
||||
.relyingPartyRegistration(this.registration).issuer("https://example.com/issuer")
|
||||
.assertionConsumerServiceUrl("https://example.com/acs-url").build();
|
||||
Saml2RedirectAuthenticationRequest response = factory.createRedirectAuthenticationRequest(request);
|
||||
String resultValue = response.getSamlRequest();
|
||||
@@ -57,7 +57,7 @@ public class Saml2AuthenticationRequestFactoryTests {
|
||||
final String value = "Test String: " + UUID.randomUUID().toString();
|
||||
Saml2AuthenticationRequestFactory factory = request -> value;
|
||||
Saml2AuthenticationRequestContext request = Saml2AuthenticationRequestContext.builder()
|
||||
.relyingPartyRegistration(registration).issuer("https://example.com/issuer")
|
||||
.relyingPartyRegistration(this.registration).issuer("https://example.com/issuer")
|
||||
.assertionConsumerServiceUrl("https://example.com/acs-url").build();
|
||||
Saml2PostAuthenticationRequest response = factory.createPostAuthenticationRequest(request);
|
||||
String resultValue = response.getSamlRequest();
|
||||
|
||||
+17
-17
@@ -49,47 +49,47 @@ public class Saml2WebSsoAuthenticationFilterTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
filter = new Saml2WebSsoAuthenticationFilter(repository);
|
||||
request.setPathInfo("/login/saml2/sso/idp-registration-id");
|
||||
request.setParameter("SAMLResponse", "xml-data-goes-here");
|
||||
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository);
|
||||
this.request.setPathInfo("/login/saml2/sso/idp-registration-id");
|
||||
this.request.setParameter("SAMLResponse", "xml-data-goes-here");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructingFilterWithMissingRegistrationIdVariableThenThrowsException() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("filterProcessesUrl must contain a {registrationId} match variable");
|
||||
filter = new Saml2WebSsoAuthenticationFilter(repository, "/url/missing/variable");
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
this.exception.expectMessage("filterProcessesUrl must contain a {registrationId} match variable");
|
||||
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/url/missing/variable");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructingFilterWithValidRegistrationIdVariableThenSucceeds() {
|
||||
filter = new Saml2WebSsoAuthenticationFilter(repository, "/url/variable/is/present/{registrationId}");
|
||||
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/url/variable/is/present/{registrationId}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requiresAuthenticationWhenHappyPathThenReturnsTrue() {
|
||||
Assert.assertTrue(filter.requiresAuthentication(request, response));
|
||||
Assert.assertTrue(this.filter.requiresAuthentication(this.request, this.response));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requiresAuthenticationWhenCustomProcessingUrlThenReturnsTrue() {
|
||||
filter = new Saml2WebSsoAuthenticationFilter(repository, "/some/other/path/{registrationId}");
|
||||
request.setPathInfo("/some/other/path/idp-registration-id");
|
||||
request.setParameter("SAMLResponse", "xml-data-goes-here");
|
||||
Assert.assertTrue(filter.requiresAuthentication(request, response));
|
||||
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/some/other/path/{registrationId}");
|
||||
this.request.setPathInfo("/some/other/path/idp-registration-id");
|
||||
this.request.setParameter("SAMLResponse", "xml-data-goes-here");
|
||||
Assert.assertTrue(this.filter.requiresAuthentication(this.request, this.response));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attemptAuthenticationWhenRegistrationIdDoesNotExistThenThrowsException() {
|
||||
when(repository.findByRegistrationId("non-existent-id")).thenReturn(null);
|
||||
when(this.repository.findByRegistrationId("non-existent-id")).thenReturn(null);
|
||||
|
||||
filter = new Saml2WebSsoAuthenticationFilter(repository, "/some/other/path/{registrationId}");
|
||||
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/some/other/path/{registrationId}");
|
||||
|
||||
request.setPathInfo("/some/other/path/non-existent-id");
|
||||
request.setParameter("SAMLResponse", "response");
|
||||
this.request.setPathInfo("/some/other/path/non-existent-id");
|
||||
this.request.setParameter("SAMLResponse", "response");
|
||||
|
||||
try {
|
||||
filter.attemptAuthentication(request, response);
|
||||
this.filter.attemptAuthentication(this.request, this.response);
|
||||
failBecauseExceptionWasNotThrown(Saml2AuthenticationException.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
+34
-33
@@ -68,14 +68,14 @@ public class Saml2WebSsoAuthenticationRequestFilterTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
filter = new Saml2WebSsoAuthenticationRequestFilter(repository);
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
request.setPathInfo("/saml2/authenticate/registration-id");
|
||||
this.filter = new Saml2WebSsoAuthenticationRequestFilter(this.repository);
|
||||
this.request = new MockHttpServletRequest();
|
||||
this.response = new MockHttpServletResponse();
|
||||
this.request.setPathInfo("/saml2/authenticate/registration-id");
|
||||
|
||||
filterChain = new MockFilterChain();
|
||||
this.filterChain = new MockFilterChain();
|
||||
|
||||
rpBuilder = RelyingPartyRegistration.withRegistrationId("registration-id")
|
||||
this.rpBuilder = RelyingPartyRegistration.withRegistrationId("registration-id")
|
||||
.providerDetails(c -> c.entityId("idp-entity-id")).providerDetails(c -> c.webSsoUrl(IDP_SSO_URL))
|
||||
.assertionConsumerServiceUrlTemplate("template")
|
||||
.credentials(c -> c.add(assertingPartyPrivateCredential()));
|
||||
@@ -83,62 +83,63 @@ public class Saml2WebSsoAuthenticationRequestFilterTests {
|
||||
|
||||
@Test
|
||||
public void doFilterWhenNoRelayStateThenRedirectDoesNotContainParameter() throws ServletException, IOException {
|
||||
when(repository.findByRegistrationId("registration-id")).thenReturn(rpBuilder.build());
|
||||
filter.doFilterInternal(request, response, filterChain);
|
||||
assertThat(response.getHeader("Location")).doesNotContain("RelayState=").startsWith(IDP_SSO_URL);
|
||||
when(this.repository.findByRegistrationId("registration-id")).thenReturn(this.rpBuilder.build());
|
||||
this.filter.doFilterInternal(this.request, this.response, this.filterChain);
|
||||
assertThat(this.response.getHeader("Location")).doesNotContain("RelayState=").startsWith(IDP_SSO_URL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doFilterWhenRelayStateThenRedirectDoesContainParameter() throws ServletException, IOException {
|
||||
when(repository.findByRegistrationId("registration-id")).thenReturn(rpBuilder.build());
|
||||
request.setParameter("RelayState", "my-relay-state");
|
||||
filter.doFilterInternal(request, response, filterChain);
|
||||
assertThat(response.getHeader("Location")).contains("RelayState=my-relay-state").startsWith(IDP_SSO_URL);
|
||||
when(this.repository.findByRegistrationId("registration-id")).thenReturn(this.rpBuilder.build());
|
||||
this.request.setParameter("RelayState", "my-relay-state");
|
||||
this.filter.doFilterInternal(this.request, this.response, this.filterChain);
|
||||
assertThat(this.response.getHeader("Location")).contains("RelayState=my-relay-state").startsWith(IDP_SSO_URL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doFilterWhenRelayStateThatRequiresEncodingThenRedirectDoesContainsEncodedParameter() throws Exception {
|
||||
when(repository.findByRegistrationId("registration-id")).thenReturn(rpBuilder.build());
|
||||
when(this.repository.findByRegistrationId("registration-id")).thenReturn(this.rpBuilder.build());
|
||||
final String relayStateValue = "https://my-relay-state.example.com?with=param&other=param";
|
||||
final String relayStateEncoded = UriUtils.encode(relayStateValue, StandardCharsets.ISO_8859_1);
|
||||
request.setParameter("RelayState", relayStateValue);
|
||||
filter.doFilterInternal(request, response, filterChain);
|
||||
assertThat(response.getHeader("Location")).contains("RelayState=" + relayStateEncoded).startsWith(IDP_SSO_URL);
|
||||
this.request.setParameter("RelayState", relayStateValue);
|
||||
this.filter.doFilterInternal(this.request, this.response, this.filterChain);
|
||||
assertThat(this.response.getHeader("Location")).contains("RelayState=" + relayStateEncoded)
|
||||
.startsWith(IDP_SSO_URL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doFilterWhenSimpleSignatureSpecifiedThenSignatureParametersAreInTheRedirectURL() throws Exception {
|
||||
when(repository.findByRegistrationId("registration-id")).thenReturn(rpBuilder.build());
|
||||
when(this.repository.findByRegistrationId("registration-id")).thenReturn(this.rpBuilder.build());
|
||||
final String relayStateValue = "https://my-relay-state.example.com?with=param&other=param";
|
||||
final String relayStateEncoded = UriUtils.encode(relayStateValue, StandardCharsets.ISO_8859_1);
|
||||
request.setParameter("RelayState", relayStateValue);
|
||||
filter.doFilterInternal(request, response, filterChain);
|
||||
assertThat(response.getHeader("Location")).contains("RelayState=" + relayStateEncoded).contains("SigAlg=")
|
||||
this.request.setParameter("RelayState", relayStateValue);
|
||||
this.filter.doFilterInternal(this.request, this.response, this.filterChain);
|
||||
assertThat(this.response.getHeader("Location")).contains("RelayState=" + relayStateEncoded).contains("SigAlg=")
|
||||
.contains("Signature=").startsWith(IDP_SSO_URL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doFilterWhenSignatureIsDisabledThenSignatureParametersAreNotInTheRedirectURL() throws Exception {
|
||||
when(repository.findByRegistrationId("registration-id"))
|
||||
.thenReturn(rpBuilder.providerDetails(c -> c.signAuthNRequest(false)).build());
|
||||
when(this.repository.findByRegistrationId("registration-id"))
|
||||
.thenReturn(this.rpBuilder.providerDetails(c -> c.signAuthNRequest(false)).build());
|
||||
final String relayStateValue = "https://my-relay-state.example.com?with=param&other=param";
|
||||
final String relayStateEncoded = UriUtils.encode(relayStateValue, StandardCharsets.ISO_8859_1);
|
||||
request.setParameter("RelayState", relayStateValue);
|
||||
filter.doFilterInternal(request, response, filterChain);
|
||||
assertThat(response.getHeader("Location")).contains("RelayState=" + relayStateEncoded).doesNotContain("SigAlg=")
|
||||
.doesNotContain("Signature=").startsWith(IDP_SSO_URL);
|
||||
this.request.setParameter("RelayState", relayStateValue);
|
||||
this.filter.doFilterInternal(this.request, this.response, this.filterChain);
|
||||
assertThat(this.response.getHeader("Location")).contains("RelayState=" + relayStateEncoded)
|
||||
.doesNotContain("SigAlg=").doesNotContain("Signature=").startsWith(IDP_SSO_URL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doFilterWhenPostFormDataIsPresent() throws Exception {
|
||||
when(repository.findByRegistrationId("registration-id"))
|
||||
.thenReturn(rpBuilder.providerDetails(c -> c.binding(POST)).build());
|
||||
when(this.repository.findByRegistrationId("registration-id"))
|
||||
.thenReturn(this.rpBuilder.providerDetails(c -> c.binding(POST)).build());
|
||||
final String relayStateValue = "https://my-relay-state.example.com?with=param&other=param&javascript{alert('1');}";
|
||||
final String relayStateEncoded = HtmlUtils.htmlEscape(relayStateValue);
|
||||
request.setParameter("RelayState", relayStateValue);
|
||||
filter.doFilterInternal(request, response, filterChain);
|
||||
assertThat(response.getHeader("Location")).isNull();
|
||||
assertThat(response.getContentAsString())
|
||||
this.request.setParameter("RelayState", relayStateValue);
|
||||
this.filter.doFilterInternal(this.request, this.response, this.filterChain);
|
||||
assertThat(this.response.getHeader("Location")).isNull();
|
||||
assertThat(this.response.getContentAsString())
|
||||
.contains("<form action=\"https://sso-url.example.com/IDP/SSO\" method=\"post\">")
|
||||
.contains("<input type=\"hidden\" name=\"SAMLRequest\"")
|
||||
.contains("value=\"" + relayStateEncoded + "\"");
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class DefaultSaml2AuthenticationRequestContextResolverTests {
|
||||
private RelyingPartyRegistration.Builder relyingPartyBuilder;
|
||||
|
||||
private Saml2AuthenticationRequestContextResolver authenticationRequestContextResolver = new DefaultSaml2AuthenticationRequestContextResolver(
|
||||
new DefaultRelyingPartyRegistrationResolver(id -> relyingPartyBuilder.build()));
|
||||
new DefaultRelyingPartyRegistrationResolver(id -> this.relyingPartyBuilder.build()));
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
+2
-2
@@ -61,7 +61,7 @@ public class Saml2AuthenticationTokenConverterTests {
|
||||
Saml2AuthenticationToken token = converter.convert(request);
|
||||
assertThat(token.getSaml2Response()).isEqualTo("response");
|
||||
assertThat(token.getRelyingPartyRegistration().getRegistrationId())
|
||||
.isEqualTo(relyingPartyRegistration.getRegistrationId());
|
||||
.isEqualTo(this.relyingPartyRegistration.getRegistrationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,7 +97,7 @@ public class Saml2AuthenticationTokenConverterTests {
|
||||
Saml2AuthenticationToken token = converter.convert(request);
|
||||
assertThat(token.getSaml2Response()).isEqualTo("response");
|
||||
assertThat(token.getRelyingPartyRegistration().getRegistrationId())
|
||||
.isEqualTo(relyingPartyRegistration.getRegistrationId());
|
||||
.isEqualTo(this.relyingPartyRegistration.getRegistrationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user