Class UserContext

  • All Implemented Interfaces:
    Serializable

    @Named
    @SessionScoped
    public class UserContext
    extends Object
    implements Serializable
    Session-scoped bean for the current user of the session.

    To enable authentication by OAuth, the deployment descriptor must be configured as follows:

     <env-entry>
     <env-entry-name>bitbucketClientId</env-entry-name>
     <env-entry-type>java.lang.String</env-entry-type>
     <lookup-name>java:global/env/bitbucketClientId</lookup-name>
     </env-entry>
     <env-entry>
     <env-entry-name>bitbucketClientSecret</env-entry-name>
     <env-entry-type>java.lang.String</env-entry-type>
     <lookup-name>java:global/env/bitbucketClientSecret</lookup-name>
     </env-entry>
     
    Since:
    5.0
    Author:
    Kaz Nishimura
    See Also:
    Serialized Form
    • Field Detail

      • BITBUCKET_CLIENT_ID

        public static final String BITBUCKET_CLIENT_ID
        Property key for the OAuth client identifier.
        See Also:
        Constant Field Values
      • BITBUCKET_CLIENT_SECRET

        public static final String BITBUCKET_CLIENT_SECRET
        Property key for the OAuth client secret.
        See Also:
        Constant Field Values
    • Constructor Detail

      • UserContext

        public UserContext()
        Constructs this object with no parameters.
    • Method Detail

      • getBitbucketClientId

        public String getBitbucketClientId()
        Returns the OAuth client identifier for the Bitbucket API. The return value may be null if not configured.
        Returns:
        the OAuth client identifier for the Bitbucket API, or null
      • setBitbucketClientId

        public void setBitbucketClientId​(String value)
        Sets the OAuth client identifier for the Bitbucket API.
        Parameters:
        value - String value to which the OAuth client identifier shall be set
      • setBitbucketClientSecret

        public void setBitbucketClientSecret​(String value)
        Sets the OAuth client secret for the Bitbucket API.
        Parameters:
        value - String value to which the OAuth client secret shall be set
      • getLoggedInUser

        public BitbucketUser getLoggedInUser()
        Returns the logged-in user.
        Returns:
        the logged-in user
      • isLoggedIn

        public boolean isLoggedIn()
        Returns true if the current user is logged in.
        Returns:
        true if logged in, or false otherwise
      • getOrigin

        protected static URI getOrigin​(ExternalContext externalContext)
        Constructs the origin of the server.
        Parameters:
        externalContext - ExternalContext object
        Returns:
        URI object of the origin
      • login

        public String login()
        Performs a login action by redirecting the user agent to the authorization endpoint.
        Returns:
        null
      • logout

        public String logout()
        Performs a logout action by clearing the current Bitbucket service.
        Returns:
        "home"
        Since:
        2.0
      • login

        public void login​(String code,
                          String state)
        Continues the current authorization flow to login.
        Parameters:
        code - an authorization code
        state - an opaque state string
      • abort

        public void abort​(String errorDescription,
                          String state)
        Aborts the current authorization flow.
        Parameters:
        errorDescription - an error description
        state - an opaque state string
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object