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 theOAuthApplicationinterface, 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.booleanisAdminSession(HttpServletRequest request)Returnstrueif theOAuthIdentityinstance associated to this request by theOAuthFilterclass was granted administrator privilege, meaning the connected user is an administrator.booleanisAuthenticated(HttpServletRequest request)Returnstrueif anOAuthIdentityinstance has been associated to this request by theOAuthFilterclass, meaning the user has successfully authenticated.voidlogin(HttpServletRequest request, String userName, String password)If login is successful, associates the createdOAuthIdentityinstance to the request.protected abstract OAuthIdentitylogin(HttpServletRequest request, org.apache.http.auth.Credentials credentials)Authenticates with the application and returns anOAuthIdentityinstance representing the connected user.voidsendUnauthorized(HttpServletRequest request, HttpServletResponse response)SendsWWW-Authenticateheader forOAuthauthorization.-
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)
Returnstrueif anOAuthIdentityinstance has been associated to this request by theOAuthFilterclass, meaning the user has successfully authenticated.- Specified by:
isAuthenticatedin interfaceorg.eclipse.lyo.server.oauth.core.Application- See Also:
OAuthIdentity.getInstance(HttpServletRequest)
-
isAdminSession
public boolean isAdminSession(HttpServletRequest request)
Returnstrueif theOAuthIdentityinstance associated to this request by theOAuthFilterclass was granted administrator privilege, meaning the connected user is an administrator.- Specified by:
isAdminSessionin 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 createdOAuthIdentityinstance to the request.- Specified by:
loginin 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 anOAuthIdentityinstance representing the connected user.- Parameters:
request- the servlet request.credentials- the credentials entered by the user trying to authenticate.- Returns:
- an
OAuthIdentityinstance 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-Authenticateheader forOAuthauthorization.Sends
WWW-Authenticateheader forBasicauthorization, if the request has no Referer (i.e. is not made from a browser).- Specified by:
sendUnauthorizedin 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:OAuthApplicationGets the OAuthIdentity for a consumer's functional user if it has one.- Specified by:
getTwoLeggedOAuthIdentityin interfaceOAuthApplication- Parameters:
request- the servlet request.consumer- the consumer used for two legged OAuth.- Returns:
- an
OAuthIdentityrepresenting 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
-
-