Skip to content

Commit

Permalink
Use the current port rather than hardcoding 8080
Browse files Browse the repository at this point in the history
I initially wanted to use @LocalServerPort like AbstractIntegrationTest
does, but got execeptions from Spring. This approach is based
on http://stackoverflow.com/a/36391145/797

Fixes OpenConext#19
  • Loading branch information
Matthew Sheppard committed May 11, 2017
1 parent 17b5003 commit 65b1edb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion mujina-idp/src/main/java/mujina/idp/MetadataController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opensaml.xml.signature.Signer;
import org.opensaml.xml.util.XMLHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.security.saml.key.KeyManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -45,6 +46,9 @@ public class MetadataController {
@Autowired
private IdpConfiguration idpConfiguration;

@Autowired
Environment environment;

@RequestMapping(method = RequestMethod.GET, value = "/metadata", produces = "application/xml")
public String metadata() throws SecurityException, ParserConfigurationException, SignatureException, MarshallingException, TransformerException {
EntityDescriptor entityDescriptor = buildSAMLObject(EntityDescriptor.class, EntityDescriptor.DEFAULT_ELEMENT_NAME);
Expand Down Expand Up @@ -72,8 +76,10 @@ public String metadata() throws SecurityException, ParserConfigurationException,

idpssoDescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS);

String localPort = environment.getProperty("local.server.port");

SingleSignOnService singleSignOnService = buildSAMLObject(SingleSignOnService.class, SingleSignOnService.DEFAULT_ELEMENT_NAME);
singleSignOnService.setLocation("http://localhost:8080/SingleSignOnService");
singleSignOnService.setLocation("http://localhost:" + localPort + "/SingleSignOnService");
singleSignOnService.setBinding(SAMLConstants.SAML2_REDIRECT_BINDING_URI);

idpssoDescriptor.getSingleSignOnServices().add(singleSignOnService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void metadata() throws Exception {
.statusCode(SC_OK)
.body(
"EntityDescriptor.IDPSSODescriptor.SingleSignOnService.@Location",
equalTo("http://localhost:8080/SingleSignOnService"));
equalTo("http://localhost:" + serverPort + "/SingleSignOnService"));
}

}
Expand Down

0 comments on commit 65b1edb

Please sign in to comment.