Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authNRequest fixes and other changes #13

Merged
merged 6 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package it.italia.developers.spid.integration.config;

import lombok.Data;

@Data
public class SAMLConfig {

private String idpEntityId;
Expand All @@ -11,65 +14,4 @@ public class SAMLConfig {
private String alias;
private String defaultBaseUrl;
private String x509Certificate;

public String getIdpEntityId() {
return idpEntityId;
}

public void setIdpEntityId(final String idpEntityId) {
this.idpEntityId = idpEntityId;
}

public String getX509Certificate() {
return x509Certificate;
}

public void setX509Certificate(final String x509Certificate) {
this.x509Certificate = x509Certificate;
}

public String getSpEntityId() {
return spEntityId;
}

public void setSpEntityId(final String spEntityId) {
this.spEntityId = spEntityId;
}

public String getDefaultBaseUrl() {
return defaultBaseUrl;
}

public void setDefaultBaseUrl(final String defaultBaseUrl) {
this.defaultBaseUrl = defaultBaseUrl;
}

public String getLoginUrl() {
return loginUrl;
}

public void setLoginUrl(final String loginUrl) {
this.loginUrl = loginUrl;
}

public String getLogoutUrl() {
return logoutUrl;
}

public void setLogoutUrl(final String logoutUrl) {
this.logoutUrl = logoutUrl;
}

public String getBaseUrl() {
return defaultBaseUrl;
}

public String getAlias() {
return alias;
}

public void setAlias(final String alias) {
this.alias = alias;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
import org.springframework.security.saml.processor.SAMLProcessor;
import org.springframework.security.saml.processor.SAMLProcessorImpl;

import lombok.Getter;

public class SAMLContext {
private static final Logger logger = LoggerFactory.getLogger(SAMLContext.class);

@Getter
private static final SAMLProcessor samlProcessor;

@Getter
private MetadataManager metadataManager;
private KeyManager idpKeyManager;

Expand Down Expand Up @@ -88,18 +92,6 @@ public SAMLMessageContext createSamlMessageContext(final HttpServletRequest requ
return context;
}

public SAMLProcessor getSamlProcessor() {
return samlProcessor;
}

public MetadataManager getMetadataManager() {
return metadataManager;
}

public KeyManager getIdpKeyManager() {
return idpKeyManager;
}

private String getDefaultBaseURL(final HttpServletRequest request) {
StringBuilder sb = new StringBuilder();
sb.append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getServerPort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public MetadataProvider generate(final SAMLConfig configuration) throws ServletE

// Defaults
String alias = configuration.getAlias();
String baseURL = configuration.getBaseUrl();
String baseURL = configuration.getDefaultBaseUrl();

generator.setEntityBaseURL(baseURL);
List<String> ssoBindings = new ArrayList<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ public ResponseDecoded processAuthenticationResponse(
SAMLMessageContext messageContext = context.createSamlMessageContext(request, response);

// Process response
context.getSamlProcessor().retrieveMessage(messageContext);
SAMLContext.getSamlProcessor().retrieveMessage(messageContext);

messageContext
.setLocalEntityEndpoint(SAMLUtil.getEndpoint(messageContext.getLocalEntityRoleMetadata().getEndpoints(),
messageContext.getInboundSAMLBinding(), new HttpServletRequestAdapter(request)));
messageContext.getPeerEntityMetadata().setEntityID(saml2Config.getIdpEntityId());

WebSSOProfileConsumer consumer = new WebSSOProfileConsumerImpl(context.getSamlProcessor(),
WebSSOProfileConsumer consumer = new WebSSOProfileConsumerImpl(SAMLContext.getSamlProcessor(),
context.getMetadataManager());
credential = consumer.processAuthenticationResponse(messageContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@ public AuthnRequest buildAuthenticationRequest(String assertionConsumerServiceUr

AuthnRequest authRequest = authRequestBuilder.buildObject(SAML2_PROTOCOL, "AuthnRequest", "samlp");
authRequest.setForceAuthn(Boolean.TRUE);
// authRequest.setIsPassive(Boolean.FALSE);
authRequest.setIssueInstant(issueInstant);
// authRequest.setProtocolBinding(SAML2_POST_BINDING);
// authRequest.setAssertionConsumerServiceURL(assertionConsumerServiceUrl);
authRequest.setAssertionConsumerServiceIndex(assertionConsumerServiceIndex);
authRequest.setIssuer(buildIssuer(issuerId));
authRequest.setNameIDPolicy(buildNameIDPolicy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public String printAuthnRequest(AuthnRequest authnRequest) throws IntegrationSer
try {
Signer.signObject(authnRequest.getSignature());
} catch (SignatureException e) {
e.printStackTrace();
log.error("There was an error while signing the request", e);
throw new IntegrationServiceException(e);
Nick87 marked this conversation as resolved.
Show resolved Hide resolved
}

// converting to a DOM
Expand Down Expand Up @@ -184,8 +185,6 @@ public Credential getCredential() {
credential.setEntityCertificate(certificate);
credential.setPrivateKey(pk);

// log.info("Private Key" + pk.toString());

return credential;
}

Expand Down Expand Up @@ -235,7 +234,6 @@ public Signature getSignature() {
KeyStore ks = getKeyStore();
try {
X509Certificate certificate = (X509Certificate) ks.getCertificate(certificateAliasName);
// KeyInfoHelper.addPublicKey(keyInfo, certificate.getPublicKey());
KeyInfoHelper.addCertificate(keyInfo, certificate);
}
catch (CertificateEncodingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public static void main(final String[] args) {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build().apiInfo(apiInfo());
// .useDefaultResponseMessages(false)
// .globalResponseMessage(RequestMethod.GET, errorList())
// .globalResponseMessage(RequestMethod.POST, errorList())
// .globalResponseMessage(RequestMethod.PUT, errorList())
// .globalResponseMessage(RequestMethod.DELETE, errorList());
}

private List<ResponseMessage> errorList() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
package it.italia.developers.spid.spidspringrest.model;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class ExtraInfo {

private String title;
private String url;

public ExtraInfo() {
}

public ExtraInfo(final String title, final String url) {
this.title = title;
this.url = url;
}

public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(final String url) {
this.url = url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,11 @@
import java.util.List;

import it.italia.developers.spid.integration.model.IdpEntry;
import lombok.Data;

@Data
public class SpidProviders {

private List<IdpEntry> identityProviders;
private List<ExtraInfo> extraInfo;

public List<IdpEntry> getIdentityProviders() {
return identityProviders;
}
public void setIdentityProviders(final List<IdpEntry> identityProviders) {
this.identityProviders = identityProviders;
}
public List<ExtraInfo> getExtraInfo() {
return extraInfo;
}
public void setExtraInfo(final List<ExtraInfo> extraInfo) {
this.extraInfo = extraInfo;
}
}