Package com.sodius.oslc.server.oauth
Class AbstractOAuthApplication
- java.lang.Object
-
- com.sodius.oslc.server.oauth.AbstractOAuthApplication
-
- All Implemented Interfaces:
OAuthApplication
,org.eclipse.lyo.server.oauth.core.Application
public abstract class AbstractOAuthApplication extends Object implements OAuthApplication
Provides a skeletal implementation of theOAuthApplication
interface, to minimize the effort required to implement this interface.- Since:
- 1.3.0
-
-
Constructor Summary
Constructors Constructor Description AbstractOAuthApplication()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Optional<OAuthIdentity>
getTwoLeggedOAuthIdentity(HttpServletRequest request, org.eclipse.lyo.server.oauth.core.consumer.LyoOAuthConsumer consumer)
Gets the OAuthIdentity for a consumer's functional user if it has one.boolean
isAdminSession(HttpServletRequest request)
Returnstrue
if theOAuthIdentity
instance associated to this request by theOAuthFilter
class was granted administrator privilege, meaning the connected user is an administrator.boolean
isAuthenticated(HttpServletRequest request)
Returnstrue
if anOAuthIdentity
instance has been associated to this request by theOAuthFilter
class, meaning the user has successfully authenticated.void
login(HttpServletRequest request, String userName, String password)
If login is successful, associates the createdOAuthIdentity
instance to the request.protected abstract OAuthIdentity
login(HttpServletRequest request, org.apache.http.auth.Credentials credentials)
Authenticates with the application and returns anOAuthIdentity
instance representing the connected user.void
sendUnauthorized(HttpServletRequest request, HttpServletResponse response)
SendsWWW-Authenticate
header forOAuth
authorization.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.sodius.oslc.server.oauth.OAuthApplication
getLoginUri, logout
-
-
-
-
Method Detail
-
isAuthenticated
public boolean isAuthenticated(HttpServletRequest request)
Returnstrue
if anOAuthIdentity
instance has been associated to this request by theOAuthFilter
class, meaning the user has successfully authenticated.- Specified by:
isAuthenticated
in interfaceorg.eclipse.lyo.server.oauth.core.Application
- See Also:
OAuthIdentity.getInstance(HttpServletRequest)
-
isAdminSession
public boolean isAdminSession(HttpServletRequest request)
Returnstrue
if theOAuthIdentity
instance associated to this request by theOAuthFilter
class was granted administrator privilege, meaning the connected user is an administrator.- Specified by:
isAdminSession
in interfaceorg.eclipse.lyo.server.oauth.core.Application
- See Also:
OAuthIdentity.isAdministrator()
-
login
public void login(HttpServletRequest request, String userName, String password) throws org.eclipse.lyo.server.oauth.core.AuthenticationException
If login is successful, associates the createdOAuthIdentity
instance to the request.- Specified by:
login
in interfaceorg.eclipse.lyo.server.oauth.core.Application
- Throws:
org.eclipse.lyo.server.oauth.core.AuthenticationException
- See Also:
login(HttpServletRequest, Credentials)
,OAuthIdentity.setInstance(HttpServletRequest, OAuthIdentity)
-
login
protected abstract OAuthIdentity login(HttpServletRequest request, org.apache.http.auth.Credentials credentials) throws org.eclipse.lyo.server.oauth.core.utils.UnauthorizedException
Authenticates with the application and returns anOAuthIdentity
instance representing the connected user.- Parameters:
request
- the servlet request.credentials
- the credentials entered by the user trying to authenticate.- Returns:
- an
OAuthIdentity
instance representing the connected user. - Throws:
org.eclipse.lyo.server.oauth.core.utils.UnauthorizedException
- if the authentication failed.
-
sendUnauthorized
public void sendUnauthorized(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
SendsWWW-Authenticate
header forOAuth
authorization.Sends
WWW-Authenticate
header forBasic
authorization, if the request has no Referer (i.e. is not made from a browser).- Specified by:
sendUnauthorized
in interfaceOAuthApplication
- Parameters:
request
- the servlet request.response
- the servlet response.- Throws:
IOException
- if an error occurs while writing the response.ServletException
- if an error occurs while producing the response.- See Also:
Application.getRealm(HttpServletRequest)
-
getTwoLeggedOAuthIdentity
public Optional<OAuthIdentity> getTwoLeggedOAuthIdentity(HttpServletRequest request, org.eclipse.lyo.server.oauth.core.consumer.LyoOAuthConsumer consumer) throws org.eclipse.lyo.server.oauth.core.utils.UnauthorizedException
Description copied from interface:OAuthApplication
Gets the OAuthIdentity for a consumer's functional user if it has one.- Specified by:
getTwoLeggedOAuthIdentity
in interfaceOAuthApplication
- Parameters:
request
- the servlet request.consumer
- the consumer used for two legged OAuth.- Returns:
- an
OAuthIdentity
representing the functional user associated to the consumer,Optional.empty()
if no functional user is associated to the consumer. - Throws:
org.eclipse.lyo.server.oauth.core.utils.UnauthorizedException
- if a functional user is associated to the consumer but this user cannot be found
-
-