Skip to content

Commit

Permalink
fix: JENKINS-53245 use closeable (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuisathaverat authored Dec 23, 2024
1 parent ff0437a commit fd5088c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.jenkinsci.plugins.saml;

import java.io.IOException;
import java.util.logging.Logger;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
Expand Down Expand Up @@ -52,16 +53,15 @@ public SamlProfileWrapper(SamlPluginConfig samlPluginConfig, StaplerRequest2 req
protected SAML2Profile process() {
SAML2AuthenticationCredentials credentials;
SAML2Profile saml2Profile;
try {
SAML2Client client = createSAML2Client();
try (SAML2Client client = createSAML2Client()) {
WebContext context = createWebContext();
SessionStore sessionStore = createSessionStore();
CallContext ctx = new CallContext(context, sessionStore);
SAML2Credentials unvalidated = (SAML2Credentials) client.getCredentials(ctx).orElse(null);
credentials = (SAML2AuthenticationCredentials) client.validateCredentials(ctx, unvalidated).orElse(null);
saml2Profile = (SAML2Profile) client.getUserProfile(ctx, credentials).orElse(null);
client.destroy();
} catch (HttpAction|SAMLException e) {
} catch (HttpAction|SAMLException|IOException e) {

Check warning on line 64 in src/main/java/org/jenkinsci/plugins/saml/SamlProfileWrapper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 64 is not covered by tests
//if the SAMLResponse is not valid we send the user again to the IdP
throw new BadCredentialsException(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.jenkinsci.plugins.saml;

import java.io.IOException;

import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
import org.pac4j.core.context.CallContext;
Expand Down Expand Up @@ -44,15 +46,14 @@ public SamlRedirectActionWrapper(SamlPluginConfig samlPluginConfig, StaplerReque
@SuppressWarnings("unused")
@Override
protected RedirectionAction process() throws IllegalStateException {
try {
SAML2Client client = createSAML2Client();
try (SAML2Client client = createSAML2Client()) {
WebContext context = createWebContext();
SessionStore sessionStore = createSessionStore();
CallContext ctx = new CallContext(context, sessionStore);
RedirectionAction redirection = client.getRedirectionAction(ctx).orElse(null);
client.destroy();
return redirection;
} catch (HttpAction e) {
} catch (HttpAction|IOException e) {

Check warning on line 56 in src/main/java/org/jenkinsci/plugins/saml/SamlRedirectActionWrapper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 56 is not covered by tests
throw new IllegalStateException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.jenkinsci.plugins.saml;

import java.io.IOException;

import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.StaplerRequest2;
Expand All @@ -41,12 +43,11 @@ public SamlSPMetadataWrapper(SamlPluginConfig samlPluginConfig, StaplerRequest2
*/
@Override
protected HttpResponse process() throws IllegalStateException {
SAML2Client client = createSAML2Client();
String metadata = "";
try {
try (SAML2Client client = createSAML2Client()) {
metadata = client.getServiceProviderMetadataResolver().getMetadata();
client.destroy();
} catch (TechnicalException e) {
} catch (TechnicalException|IOException e) {

Check warning on line 50 in src/main/java/org/jenkinsci/plugins/saml/SamlSPMetadataWrapper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 50 is not covered by tests
throw new IllegalStateException(e);
}
return HttpResponses.text(metadata);
Expand Down

0 comments on commit fd5088c

Please sign in to comment.