Class AbstractOAuthApplication

java.lang.Object
com.sodius.oslc.server.oauth.AbstractOAuthApplication
All Implemented Interfaces:
OAuthApplication, org.eclipse.lyo.server.oauth.core.Application
Direct Known Subclasses:
BrokerOAuthApplication

public abstract class AbstractOAuthApplication extends Object implements OAuthApplication
Provides a skeletal implementation of the OAuthApplication interface, to minimize the effort required to implement this interface.
Since:
1.3.0
  • Constructor Details

    • AbstractOAuthApplication

      public AbstractOAuthApplication()
  • Method Details

    • isAuthenticated

      public boolean isAuthenticated(HttpServletRequest request)
      Returns true if an OAuthIdentity instance has been associated to this request by the OAuthFilter class, meaning the user has successfully authenticated.
      Specified by:
      isAuthenticated in interface org.eclipse.lyo.server.oauth.core.Application
      See Also:
    • isAdminSession

      public boolean isAdminSession(HttpServletRequest request)
      Returns true if the OAuthIdentity instance associated to this request by the OAuthFilter class was granted administrator privilege, meaning the connected user is an administrator.
      Specified by:
      isAdminSession in interface org.eclipse.lyo.server.oauth.core.Application
    • isAdminSession

      protected abstract boolean isAdminSession(OAuthIdentity identity)
      Determines whether the given identity has administration privileges.
      Parameters:
      identity - the given identity representing the current instance.
      Returns:
      true if the identity has administration privileges; false otherwise.
      Since:
      4.0.0
    • login

      public void login(HttpServletRequest request, String userName, String password) throws org.eclipse.lyo.server.oauth.core.AuthenticationException
      If login is successful, associates the created OAuthIdentity instance to the request.
      Specified by:
      login in interface org.eclipse.lyo.server.oauth.core.Application
      Throws:
      org.eclipse.lyo.server.oauth.core.AuthenticationException
      See Also:
    • 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 an OAuthIdentity 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
      Sends WWW-Authenticate header for OAuth authorization.

      Sends WWW-Authenticate header for Basic authorization, if the request has no Referer (i.e. is not made from a browser).

      Specified by:
      sendUnauthorized in interface OAuthApplication
      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 interface OAuthApplication
      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