Package org.dspace.app.rest
Class AuthenticationRestController
- java.lang.Object
-
- org.dspace.app.rest.AuthenticationRestController
-
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
@RequestMapping("/api/authn") @RestController public class AuthenticationRestController extends Object implements org.springframework.beans.factory.InitializingBeanRest controller that handles authentication on the REST API together with the Spring Security filters configured inWebSecurityConfiguration- Author:
- Frederic Van Reet (frederic dot vanreet at atmire dot com), Tom Desair (tom dot desair at atmire dot com)
-
-
Constructor Summary
Constructors Constructor Description AuthenticationRestController()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()AuthnResourceauthn()protected org.springframework.http.ResponseEntitygetLoginResponse(javax.servlet.http.HttpServletRequest request, String failedMessage)Check the request to see if the login succeeded or failed.org.springframework.http.ResponseEntitylogin()Disables GET/PUT/PATCH on the /login endpoint.org.springframework.http.ResponseEntitylogin(javax.servlet.http.HttpServletRequest request, String user, String password)Check whether the login has succeeded or not.org.springframework.http.ResponseEntitylogout()Returns a successful "204 No Content" response for a logout request.org.springframework.http.ResponseEntitylogoutMethodNotAllowed()Disables GET/PUT/PATCH on the /logout endpoint.AuthenticationTokenResourceshortLivedToken(javax.servlet.http.HttpServletRequest request)This method will generate a short lived token to be used for bitstream downloads among other things.AuthenticationTokenResourceshortLivedTokenViaGet(javax.servlet.http.HttpServletRequest request)This method will generate a short lived token to be used for bitstream downloads among other things.AuthenticationStatusResourcestatus(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)Check the current user's authentication status (i.e.
-
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
authn
@RequestMapping(method=GET) public AuthnResource authn()
-
status
@RequestMapping(value="/status", method=GET) public AuthenticationStatusResource status(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws SQLExceptionCheck the current user's authentication status (i.e. whether they are authenticated or not)If the user is NOT currently authenticated, a list of all currently enabled DSpace authentication endpoints is returned in the WWW-Authenticate header.
- Parameters:
request- current requestresponse- response- Returns:
- AuthenticationStatusResource
- Throws:
SQLException
-
login
@RequestMapping(value="/login", method=POST) public org.springframework.http.ResponseEntity login(javax.servlet.http.HttpServletRequest request, @RequestParam(name="user",required=false) String user, @RequestParam(name="password",required=false) String password)Check whether the login has succeeded or not. The actual login is performed by one of the enabled login filters (e.g.StatelessLoginFilter). SeeWebSecurityConfigurationfor enabled login filters.- Parameters:
request- current requestuser- userpassword- password- Returns:
- ResponseEntity with information about whether login was successful or failed
-
shortLivedToken
@PreAuthorize("hasAuthority(\'AUTHENTICATED\')") @RequestMapping(value="/shortlivedtokens", method=POST) public AuthenticationTokenResource shortLivedToken(javax.servlet.http.HttpServletRequest request)This method will generate a short lived token to be used for bitstream downloads among other things. curl -v -X POST https://{dspace-server.url}/api/authn/shortlivedtokens -H "Authorization: Bearer eyJhbG...COdbo" Example:curl -v -X POST https://{dspace-server.url}/api/authn/shortlivedtokens -H "Authorization: Bearer eyJhbG...COdbo"- Parameters:
request- The StandardMultipartHttpServletRequest- Returns:
- The created short lived token
-
shortLivedTokenViaGet
@PreAuthorize("hasAuthority(\'AUTHENTICATED\')") @RequestMapping(value="/shortlivedtokens", method=GET) public AuthenticationTokenResource shortLivedTokenViaGet(javax.servlet.http.HttpServletRequest request) throws org.dspace.authorize.AuthorizeExceptionThis method will generate a short lived token to be used for bitstream downloads among other things. For security reasons, this endpoint only responds to a explicitly defined list of ips. curl -v -X GET https://{dspace-server.url}/api/authn/shortlivedtokens -H "Authorization: Bearer eyJhbG...COdbo" Example:curl -v -X GET https://{dspace-server.url}/api/authn/shortlivedtokens -H "Authorization: Bearer eyJhbG...COdbo"- Parameters:
request- The StandardMultipartHttpServletRequest- Returns:
- The created short lived token
- Throws:
org.dspace.authorize.AuthorizeException
-
login
@RequestMapping(value="/login", method={GET,PUT,PATCH,DELETE}) public org.springframework.http.ResponseEntity login()Disables GET/PUT/PATCH on the /login endpoint. You must use POST (see above method)- Returns:
- ResponseEntity
-
logout
@RequestMapping(value="/logout", method={HEAD,POST}) public org.springframework.http.ResponseEntity logout()Returns a successful "204 No Content" response for a logout request. Actual logout is performed by ourCustomLogoutHandlerFor logout we *require* POST requests. HEAD is also supported for endpoint visibility in HAL Browser, etc.
- Returns:
- ResponseEntity (204 No Content)
-
logoutMethodNotAllowed
@RequestMapping(value="/logout", method={GET,PUT,PATCH,DELETE}) public org.springframework.http.ResponseEntity logoutMethodNotAllowed()Disables GET/PUT/PATCH on the /logout endpoint. You must use POST (see above method)- Returns:
- ResponseEntity
-
getLoginResponse
protected org.springframework.http.ResponseEntity getLoginResponse(javax.servlet.http.HttpServletRequest request, String failedMessage)Check the request to see if the login succeeded or failed. If the request includes a valid EPerson, then it was successful. If the request does not include a valid EPerson, then return the failedMessage.NOTE: This method assumes that a login filter (e.g.
StatelessLoginFilter) has already attempted the authentication and, if successful, added EPerson data to the current request.- Parameters:
request- current requestfailedMessage- message to send if no EPerson found- Returns:
- ResponseEntity
-
-