Class 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 the OAuthApplication interface, to minimize the effort required to implement this interface.
    Since:
    1.3.0
    • Constructor Detail

      • AbstractOAuthApplication

        public AbstractOAuthApplication()
    • Method Detail

      • 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:
        OAuthIdentity.getInstance(HttpServletRequest)
      • 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
        See Also:
        OAuthIdentity.isAdministrator()
      • 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