Skip to content

Commit 5a98fda

Browse files
committed
Fix Sonar issues
Signed-off-by: Duane May <[email protected]>
1 parent 97d6858 commit 5a98fda

File tree

5 files changed

+12
-36
lines changed

5 files changed

+12
-36
lines changed

server/src/main/java/org/cloudfoundry/identity/uaa/login/LoginInfoEndpoint.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.springframework.util.StringUtils;
5252
import org.springframework.web.HttpMediaTypeNotAcceptableException;
5353
import org.springframework.web.bind.annotation.GetMapping;
54+
import org.springframework.web.bind.annotation.PathVariable;
5455
import org.springframework.web.bind.annotation.PostMapping;
5556
import org.springframework.web.bind.annotation.RequestBody;
5657
import org.springframework.web.bind.annotation.RequestHeader;
@@ -863,7 +864,7 @@ public String captureImplicitValuesUsingJavascript() {
863864
}
864865

865866
@GetMapping(value = "/login/callback/{origin}")
866-
public String handleExternalOAuthCallback(final HttpSession session) {
867+
public String handleExternalOAuthCallback(final HttpSession session, @PathVariable String origin) {
867868
String redirectLocation = "/home";
868869
SavedRequest savedRequest = SessionUtils.getSavedRequestSession(session);
869870
if (savedRequest != null && savedRequest.getRedirectUrl() != null) {

server/src/test/java/org/cloudfoundry/identity/uaa/login/LoginInfoEndpointTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ void we_return_both_oauth_and_oidc_providers() throws Exception {
920920
void externalOAuthCallback_redirectsToHomeIfNoSavedRequest() {
921921
LoginInfoEndpoint endpoint = getEndpoint(IdentityZoneHolder.get());
922922
HttpSession session = new MockHttpSession();
923-
String redirectUrl = endpoint.handleExternalOAuthCallback(session);
923+
String redirectUrl = endpoint.handleExternalOAuthCallback(session, "origin");
924924
assertThat(redirectUrl).isEqualTo("redirect:/home");
925925
}
926926

@@ -931,7 +931,7 @@ void externalOAuthCallback_redirectsToSavedRequestIfPresent() {
931931
DefaultSavedRequest savedRequest = mock(DefaultSavedRequest.class);
932932
when(savedRequest.getRedirectUrl()).thenReturn("/some.redirect.url");
933933
SessionUtils.setSavedRequestSession(session, savedRequest);
934-
String redirectUrl = endpoint.handleExternalOAuthCallback(session);
934+
String redirectUrl = endpoint.handleExternalOAuthCallback(session, "origin");
935935
assertThat(redirectUrl).isEqualTo("redirect:/some.redirect.url");
936936
}
937937

server/src/test/java/org/cloudfoundry/identity/uaa/provider/saml/OpenSaml4AuthenticationProviderUnitTests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ void setResponseValidatorWhenNullThenIllegalArgument() {
572572
void authenticateWhenCustomResponseValidatorThenUses() {
573573
Converter<ResponseToken, Saml2ResponseValidatorResult> validator = mock(
574574
Converter.class);
575-
OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
576575
// @formatter:off
577576
provider.setResponseValidator((responseToken) -> OpenSaml4AuthenticationProvider.createDefaultResponseValidator()
578577
.convert(responseToken)
@@ -591,7 +590,6 @@ void authenticateWhenCustomResponseValidatorThenUses() {
591590

592591
@Test
593592
void authenticateWhenAssertionIssuerNotValidThenFailsWithInvalidIssuer() {
594-
OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
595593
Response response = response();
596594
Assertion assertion = assertion();
597595
assertion.setIssuer(TestOpenSamlObjects.issuer("https://invalid.idp.test/saml2/idp"));
@@ -620,7 +618,7 @@ private Consumer<Saml2AuthenticationException> errorOf(String errorCode) {
620618
}
621619

622620
private Consumer<Saml2AuthenticationException> errorOf(String errorCode, String description) {
623-
return (ex) -> {
621+
return ex -> {
624622
assertThat(ex.getSaml2Error().getErrorCode()).isEqualTo(errorCode);
625623
if (StringUtils.hasText(description)) {
626624
assertThat(ex.getSaml2Error().getDescription()).contains(description);
@@ -726,16 +724,16 @@ private RelyingPartyRegistration.Builder registration() {
726724
return TestRelyingPartyRegistrations.noCredentials()
727725
.entityId(RELYING_PARTY_ENTITY_ID)
728726
.assertionConsumerServiceLocation(DESTINATION)
729-
.assertingPartyDetails((party) -> party.entityId(ASSERTING_PARTY_ENTITY_ID));
727+
.assertingPartyDetails(party -> party.entityId(ASSERTING_PARTY_ENTITY_ID));
730728
}
731729

732730
private RelyingPartyRegistration.Builder verifying(RelyingPartyRegistration.Builder builder) {
733-
return builder.assertingPartyDetails((party) -> party
734-
.verificationX509Credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())));
731+
return builder.assertingPartyDetails(party -> party
732+
.verificationX509Credentials(c -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())));
735733
}
736734

737735
private RelyingPartyRegistration.Builder decrypting(RelyingPartyRegistration.Builder builder) {
738736
return builder
739-
.decryptionX509Credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyDecryptingCredential()));
737+
.decryptionX509Credentials(c -> c.add(TestSaml2X509Credentials.relyingPartyDecryptingCredential()));
740738
}
741739
}

server/src/test/java/org/cloudfoundry/identity/uaa/provider/saml/Saml2BearerGrantAuthenticationConverterTest.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.opensaml.saml.saml2.core.Audience;
2222
import org.opensaml.saml.saml2.core.AuthnRequest;
2323
import org.opensaml.saml.saml2.core.Conditions;
24-
import org.opensaml.saml.saml2.core.EncryptedAssertion;
2524
import org.opensaml.saml.saml2.core.EncryptedAttribute;
2625
import org.opensaml.saml.saml2.core.Response;
2726
import org.opensaml.saml.saml2.core.SubjectConfirmation;
@@ -179,7 +178,7 @@ void authenticateWhenAssertionContainsValidationAddressThenItSucceeds() {
179178
Assertion assertion = assertion();
180179
assertion.getSubject()
181180
.getSubjectConfirmations()
182-
.forEach((sc) -> sc.getSubjectConfirmationData().setAddress("10.10.10.10"));
181+
.forEach(sc -> sc.getSubjectConfirmationData().setAddress("10.10.10.10"));
183182
Saml2AuthenticationToken token = token(assertion, verifying(registration()));
184183
this.provider.authenticate(token);
185184
}
@@ -204,15 +203,6 @@ void evaluateInResponseToFailsWhenInResponseToInAssertionMismatchWithRequestID()
204203
.withStackTraceContaining("invalid_assertion");
205204
}
206205

207-
@Test
208-
void evaluateInResponseToSucceedsWhenNoInResponseToInResponseOrAssertions() {
209-
Assertion assertion = assertion();
210-
AbstractSaml2AuthenticationRequest mockAuthenticationRequest = mockedStoredAuthenticationRequest("SAML2",
211-
Saml2MessageBinding.POST, false);
212-
Saml2AuthenticationToken token = token(assertion, verifying(registration()), mockAuthenticationRequest);
213-
this.provider.authenticate(token);
214-
}
215-
216206
@Test
217207
void authenticateWhenAssertionContainsAttributesThenItSucceeds() {
218208
Assertion assertion = assertion();
@@ -364,8 +354,6 @@ void authenticateWhenAuthenticationHasDetailsThenSucceeds() {
364354
void writeObjectWhenTypeIsSaml2AuthenticationThenNoException() throws IOException {
365355
Assertion assertion = TestOpenSamlObjects.signed(assertion(),
366356
TestSaml2X509Credentials.assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
367-
EncryptedAssertion encryptedAssertion = TestOpenSamlObjects.encrypted(assertion,
368-
TestSaml2X509Credentials.assertingPartyEncryptingCredential());
369357
Saml2AuthenticationToken token = token(signed(assertion), decrypting(verifying(registration())));
370358
Saml2Authentication authentication = (Saml2Authentication) this.provider.authenticate(token);
371359
// the following code will throw an exception if authentication isn't serializable
@@ -412,7 +400,7 @@ void authenticateWhenAssertionIssuerNotValidThenFailsWithInvalidIssuer() {
412400
assertion.setIssuer(TestOpenSamlObjects.issuer("https://invalid.idp.test/saml2/idp"));
413401
Saml2AuthenticationToken token = token(signed(assertion), verifying(registration()));
414402
assertThatExceptionOfType(Saml2AuthenticationException.class).isThrownBy(() -> provider.authenticate(token))
415-
.withMessageContaining("from Issuer","was not valid");
403+
.withMessageContaining("from Issuer", "was not valid");
416404
}
417405

418406
private <T extends XMLObject> T build(QName qName) {
@@ -449,8 +437,7 @@ private Response response() {
449437
}
450438

451439
private AuthnRequest request() {
452-
AuthnRequest request = TestOpenSamlObjects.authnRequest();
453-
return request;
440+
return TestOpenSamlObjects.authnRequest();
454441
}
455442

456443
private String serializedRequest(AuthnRequest request, Saml2MessageBinding binding) {
@@ -515,10 +502,6 @@ private Saml2AuthenticationToken token(Assertion assertion, RelyingPartyRegistra
515502
return new Saml2AuthenticationToken(registration.build(), serialize(assertion));
516503
}
517504

518-
private Saml2AuthenticationToken token(EncryptedAssertion assertion, RelyingPartyRegistration.Builder registration) {
519-
return new Saml2AuthenticationToken(registration.build(), serialize(assertion));
520-
}
521-
522505
private Saml2AuthenticationToken token(Assertion assertion, RelyingPartyRegistration.Builder registration,
523506
AbstractSaml2AuthenticationRequest authenticationRequest) {
524507
return new Saml2AuthenticationToken(registration.build(), serialize(assertion), authenticationRequest);

server/src/test/java/org/cloudfoundry/identity/uaa/provider/saml/Saml2TestUtils.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.opensaml.core.xml.io.MarshallingException;
2424
import org.opensaml.core.xml.schema.XSDateTime;
2525
import org.opensaml.core.xml.schema.impl.XSDateTimeBuilder;
26-
import org.opensaml.saml.common.SignableSAMLObject;
2726
import org.opensaml.saml.saml2.core.Assertion;
2827
import org.opensaml.saml.saml2.core.Attribute;
2928
import org.opensaml.saml.saml2.core.AttributeStatement;
@@ -195,11 +194,6 @@ public static RelyingPartyRegistration.Builder verifying(RelyingPartyRegistratio
195194
.verificationX509Credentials(c -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())));
196195
}
197196

198-
private static RelyingPartyRegistration.Builder decrypting(RelyingPartyRegistration.Builder builder) {
199-
return builder
200-
.decryptionX509Credentials(c -> c.add(TestSaml2X509Credentials.relyingPartyDecryptingCredential()));
201-
}
202-
203197
public static Map<String, String> xmlNamespaces() {
204198
return Map.of(
205199
// Metadata

0 commit comments

Comments
 (0)