Skip to content

Commit

Permalink
Added metadata endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Nov 8, 2023
1 parent 6c1e0a1 commit 0b56a20
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 7 deletions.
4 changes: 3 additions & 1 deletion myconext-gui/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ export function logout() {
credentials: "same-origin",
redirect: "manual"
};
return fetchJson("/myconext/api/sp/logout").then(() => fetch("/Shibboleth.sso/Logout", fetchOptions));
return forgetMe().then(() =>
fetchJson("/myconext/api/sp/logout").then(() => fetch("/Shibboleth.sso/Logout", fetchOptions))
);
}

export function forgetMe() {
Expand Down
2 changes: 2 additions & 0 deletions myconext-server/src/main/java/myconext/aa/UserAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Collections;
import java.util.List;

@Getter
@NoArgsConstructor
@ToString
public class UserAttribute {

private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
Expand All @@ -69,9 +70,11 @@ public class GuestIdpAuthenticationRequestFilter extends OncePerRequestFilter im

private final AntPathRequestMatcher ssoSamlRequestMatcher;
private final AntPathRequestMatcher magicSamlRequestMatcher;
private final AntPathRequestMatcher continueAfterloginSamlRequestMatcher;
private final AntPathRequestMatcher continueAfterLoginSamlRequestMatcher;
private final AntPathRequestMatcher metaDataSamlRequestMatcher;
private final String redirectUrl;
private final AuthenticationRequestRepository authenticationRequestRepository;
private final IdentityProviderMetaData identityProviderMetaData;
private UserRepository userRepository;
private final UserLoginRepository userLoginRepository;
private final List<String> accountLinkingContextClassReferences;
Expand Down Expand Up @@ -107,10 +110,12 @@ public GuestIdpAuthenticationRequestFilter(String redirectUrl,
long ssoMFADurationSeconds,
String mobileAppROEntityId,
boolean featureDefaultRememberMe,
SAMLConfiguration configuration) {
SAMLConfiguration configuration,
IdentityProviderMetaData identityProviderMetaData) {
this.ssoSamlRequestMatcher = new AntPathRequestMatcher("/saml/guest-idp/SSO/**");
this.magicSamlRequestMatcher = new AntPathRequestMatcher("/saml/guest-idp/magic/**");
this.continueAfterloginSamlRequestMatcher = new AntPathRequestMatcher("/saml/guest-idp/continue/**");
this.continueAfterLoginSamlRequestMatcher = new AntPathRequestMatcher("/saml/guest-idp/continue/**");
this.metaDataSamlRequestMatcher = new AntPathRequestMatcher("/saml/guest-idp/metadata/**");
this.redirectUrl = redirectUrl;
this.serviceProviderResolver = serviceProviderResolver;
this.authenticationRequestRepository = authenticationRequestRepository;
Expand All @@ -130,6 +135,7 @@ public GuestIdpAuthenticationRequestFilter(String redirectUrl,
this.featureDefaultRememberMe = featureDefaultRememberMe;
this.samlIdpService = new DefaultSAMLIdPService(configuration);
this.executor = Executors.newSingleThreadExecutor();
this.identityProviderMetaData = identityProviderMetaData;
}

@Override
Expand All @@ -142,10 +148,14 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
LOG.debug("Starting magic filter");
this.magic(request, response);
return;
} else if (this.continueAfterloginSamlRequestMatcher.matches(request)) {
} else if (this.continueAfterLoginSamlRequestMatcher.matches(request)) {
LOG.debug("Starting continue after login filter");
this.continueAfterLogin(request, response);
return;
} else if (this.metaDataSamlRequestMatcher.matches(request)) {
LOG.debug("Starting metadata filter");
this.metaData(response);
return;
}
filterChain.doFilter(request, response);
}
Expand Down Expand Up @@ -761,4 +771,19 @@ private SAMLAttribute attribute(String name, String value) {
return new SAMLAttribute(name, value);
}

private void metaData(HttpServletResponse servletResponse) throws IOException {
servletResponse.setContentType("text/xml");
servletResponse.setCharacterEncoding(UTF_8.name());

servletResponse.setHeader("Cache-Control", "private");
String metaData = this.samlIdpService.metaData(
this.identityProviderMetaData.getSingleSignOnServiceURI(),
this.identityProviderMetaData.getName(),
this.identityProviderMetaData.getDescription(),
this.identityProviderMetaData.getLogoURI()
);
servletResponse.getWriter().write(metaData);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package myconext.security;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Getter
@Setter
@NoArgsConstructor
@ConfigurationProperties(prefix = "identity-provider-meta-data")
public class IdentityProviderMetaData {

private String singleSignOnServiceURI;
private String name;
private String description;
private String logoURI;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class SecurityConfiguration {

@Configuration
@Order(1)
@EnableConfigurationProperties(IdentityProviderMetaData.class)
public static class SamlSecurity extends WebSecurityConfigurerAdapter {

private final GuestIdpAuthenticationRequestFilter guestIdpAuthenticationRequestFilter;
Expand Down Expand Up @@ -80,7 +82,8 @@ public SamlSecurity(@Value("${private_key_path}") Resource privateKeyPath,
UserLoginRepository userLoginRepository,
GeoLocation geoLocation,
MailBox mailBox,
ServiceProviderResolver serviceProviderResolver) {
ServiceProviderResolver serviceProviderResolver,
IdentityProviderMetaData identityProviderMetaData) {
String[] keys = this.getKeys(certificatePath, privateKeyPath);
final List<SAMLServiceProvider> serviceProviders = new ArrayList<>();

Expand Down Expand Up @@ -112,7 +115,8 @@ public SamlSecurity(@Value("${private_key_path}") Resource privateKeyPath,
ssoMFADurationSeconds,
mobileAppROEntityId,
featureDefaultRememberMe,
configuration
configuration,
identityProviderMetaData
);

}
Expand Down
6 changes: 6 additions & 0 deletions myconext-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ email:
# mail-templates-directory: file://opt/build/main/resources/mail_templates
mail-templates-directory: classpath:mail_templates

identity-provider-meta-data:
single_sign_on_service_uri: "https://login.test.eduid.nl/saml/guest-idp/SSO"
name: "eduID IdP"
description: "eduID IdP"
logo_uri: "https://static.surfconext.nl/media/idp/eduid.png"

schac_home_organization: eduid.nl

cron:
Expand Down

0 comments on commit 0b56a20

Please sign in to comment.