Skip to content
Snippets Groups Projects
Unverified Commit 147030fb authored by Martin Weise's avatar Martin Weise
Browse files

Change the endpoint

parent 892f9410
No related branches found
No related tags found
4 merge requests!81New stable release,!43Merge dev to master,!33Draft: merge dev to master,!30Resolve "Refactor: fix all TODOs and FIXMEs in the backend"
package at.tuwien.config; package at.tuwien.config;
import at.tuwien.service.AuthenticationService;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
...@@ -107,6 +106,13 @@ public class SamlConfig extends WebSecurityConfigurerAdapter { ...@@ -107,6 +106,13 @@ public class SamlConfig extends WebSecurityConfigurerAdapter {
return new HttpClient(multiThreadedHttpConnectionManager()); return new HttpClient(multiThreadedHttpConnectionManager());
} }
@Bean
public SAMLAuthenticationProvider samlAuthenticationProvider() {
final SAMLAuthenticationProvider samlAuthenticationProvider = new SAMLAuthenticationProvider();
samlAuthenticationProvider.setForcePrincipalAsString(false);
return samlAuthenticationProvider;
}
@Bean @Bean
public WebSSOProfileConsumer webSSOprofileConsumer() { public WebSSOProfileConsumer webSSOprofileConsumer() {
return new WebSSOProfileConsumerImpl(); return new WebSSOProfileConsumerImpl();
...@@ -347,11 +353,6 @@ public class SamlConfig extends WebSecurityConfigurerAdapter { ...@@ -347,11 +353,6 @@ public class SamlConfig extends WebSecurityConfigurerAdapter {
return new JKSKeyManager(storeFile, samlKeystorePassword, passwords, samlKeystoreAlias); return new JKSKeyManager(storeFile, samlKeystorePassword, passwords, samlKeystoreAlias);
} }
@Bean
public SAMLAuthenticationProvider samlAuthenticationProvider() {
return new AuthenticationService();
}
@Override @Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception { protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(samlAuthenticationProvider()); auth.authenticationProvider(samlAuthenticationProvider());
......
...@@ -6,16 +6,16 @@ import org.springframework.security.core.Authentication; ...@@ -6,16 +6,16 @@ import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@Log4j2 @Log4j2
@RestController("/api/auth") @RestController
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
public class AuthenticationEndpoint { public class AuthenticationEndpoint {
@GetMapping("/") @GetMapping("/api/auth")
public String index() { public String index() {
return "Index"; return "Index";
} }
@GetMapping("/info") @GetMapping("/api/auth/info")
public ResponseEntity<Object> info(Authentication authentication) { public ResponseEntity<Object> info(Authentication authentication) {
return ResponseEntity.ok(authentication.getName()); return ResponseEntity.ok(authentication.getName());
} }
......
package at.tuwien.endpoints;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@Log4j2
@RestController("/api/test")
@CrossOrigin(origins = "*")
public class TestEndpoint {
@GetMapping("/")
public String index() {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
log.debug("auth {}", auth);
log.debug("auth principal {}", auth.getPrincipal());
return "hello";
}
}
\ No newline at end of file
package at.tuwien.service;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.providers.ExpiringUsernameAuthenticationToken;
import org.springframework.security.saml.SAMLAuthenticationProvider;
import org.springframework.security.saml.SAMLCredential;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@Service
public class AuthenticationService extends SAMLAuthenticationProvider {
@Override
public Collection<? extends GrantedAuthority> getEntitlements(SAMLCredential credential, Object userDetail) {
if (userDetail instanceof ExpiringUsernameAuthenticationToken) {
return new ArrayList<>(((ExpiringUsernameAuthenticationToken) userDetail)
.getAuthorities());
} else {
return Collections.emptyList();
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment