mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-13 13:03:11 +00:00
Merge branch 'ds3777' of https://github.com/TAMULib/DSpace into TAMULib-ds3777
This commit is contained in:
@@ -84,19 +84,23 @@ public class AuthenticationRestController implements InitializingBean {
|
|||||||
return authenticationStatusResource;
|
return authenticationStatusResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.POST})
|
@RequestMapping(value = "/login", method = {RequestMethod.POST})
|
||||||
public ResponseEntity login(HttpServletRequest request, @RequestParam(name = "user", required = false) String user,
|
public ResponseEntity login(HttpServletRequest request, @RequestParam(name = "user", required = false) String user,
|
||||||
@RequestParam(name = "password", required = false) String password) {
|
@RequestParam(name = "password", required = false) String password) {
|
||||||
//If you can get here, you should be authenticated, the actual login is handled by spring security
|
//If you can get here, you should be authenticated, the actual login is handled by spring security
|
||||||
//see org.dspace.app.rest.security.StatelessLoginFilter
|
//see org.dspace.app.rest.security.StatelessLoginFilter
|
||||||
|
|
||||||
//If we don't have an EPerson here, this means authentication failed and we should return an error message.
|
//If we don't have an EPerson here, this means authentication failed and we should return an error message.
|
||||||
|
|
||||||
return getLoginResponse(request,
|
return getLoginResponse(request,
|
||||||
"Authentication failed for user " + user + ": The credentials you provided are not " +
|
"Authentication failed for user " + user + ": The credentials you provided are not " +
|
||||||
"valid.");
|
"valid.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE})
|
||||||
|
public ResponseEntity login() {
|
||||||
|
return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body("Only POST is allowed for login requests.");
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/logout", method = {RequestMethod.GET, RequestMethod.POST})
|
@RequestMapping(value = "/logout", method = {RequestMethod.GET, RequestMethod.POST})
|
||||||
public ResponseEntity logout() {
|
public ResponseEntity logout() {
|
||||||
//This is handled by org.dspace.app.rest.security.CustomLogoutHandler
|
//This is handled by org.dspace.app.rest.security.CustomLogoutHandler
|
||||||
|
@@ -15,6 +15,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||||
@@ -50,6 +51,18 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CustomLogoutHandler customLogoutHandler;
|
private CustomLogoutHandler customLogoutHandler;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure(WebSecurity webSecurity) throws Exception
|
||||||
|
{
|
||||||
|
webSecurity
|
||||||
|
.ignoring()
|
||||||
|
.antMatchers(HttpMethod.GET, "/api/authn/login")
|
||||||
|
.antMatchers(HttpMethod.PUT, "/api/authn/login")
|
||||||
|
.antMatchers(HttpMethod.PATCH, "/api/authn/login")
|
||||||
|
.antMatchers(HttpMethod.DELETE, "/api/authn/login");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.headers().cacheControl();
|
http.headers().cacheControl();
|
||||||
@@ -81,8 +94,9 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
|
|
||||||
//Configure the URL patterns with their authentication requirements
|
//Configure the URL patterns with their authentication requirements
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
//Allow GET and POST by anyone on the login endpoint
|
//Allow POST by anyone on the login endpoint
|
||||||
.antMatchers("/api/authn/login").permitAll()
|
.antMatchers(HttpMethod.POST,"/api/authn/login").permitAll()
|
||||||
|
//TRACE, CONNECT, OPTIONS, HEAD
|
||||||
//Everyone can call GET on the status endpoint
|
//Everyone can call GET on the status endpoint
|
||||||
.antMatchers(HttpMethod.GET, "/api/authn/status").permitAll()
|
.antMatchers(HttpMethod.GET, "/api/authn/status").permitAll()
|
||||||
.and()
|
.and()
|
||||||
|
Reference in New Issue
Block a user