Class LoginDelegator

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getLoginStatus()
      Return a string indicating the current login status; corresponds to the p4 login -s command.
      boolean isDontWriteTicket​(java.lang.String cmd, java.lang.String[] cmdArgs)
      Special case handling of the "-p" flag for the "p4 login" command.
      void login​(IUser user, java.lang.StringBuffer ticket, LoginOptions opts)
      Log another user in to Perforce by obtaining a session ticket for that user.
      void login​(java.lang.String password)
      Convenience method for login(password, false).
      void login​(java.lang.String password, boolean allHosts)
      Log the current user (if any) in to a Perforce server, optionally arranging to be logged in for all hosts.
      void login​(java.lang.String password, LoginOptions opts)
      Log the current user (if any) in to a Perforce server, optionally arranging to be logged in for all hosts.
      void login​(java.lang.String password, java.lang.StringBuffer ticket, LoginOptions opts)
      Log the current user (if any) in to a Perforce server using.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LoginDelegator

        public LoginDelegator​(IOptionsServer server)
        Instantiates a new login delegator.
        Parameters:
        server - the server
    • Method Detail

      • getLoginStatus

        public java.lang.String getLoginStatus()
                                        throws P4JavaException
        Description copied from interface: ILoginDelegator
        Return a string indicating the current login status; corresponds to the p4 login -s command. The resulting string should be interpreted by the caller, but is typically something like "User p4jtestsuper ticket expires in 9 hours 42 minutes." or "'login' not necessary, no password set for this user." or "Perforce password (P4PASSWD) invalid or unset." or "Access for user 'p4jtestinvaliduser' has not been enabled by 'p4 protect'", etc.
        Specified by:
        getLoginStatus in interface ILoginDelegator
        Returns:
        non-null, but possibly-empty ticket / login status string. Interpretation of this string is up to the caller.
        Throws:
        P4JavaException - if any errors occur during the processing of this command.
      • login

        public void login​(java.lang.String password,
                          boolean allHosts)
                   throws ConnectionException,
                          RequestException,
                          AccessException,
                          ConfigException
        Description copied from interface: ILoginDelegator
        Log the current user (if any) in to a Perforce server, optionally arranging to be logged in for all hosts.

        Attempts to log in to the underlying Perforce server. If successful, successive calls to server-side services will succeed until the session is terminated by the server or the user logs out.

        Behaviour is undefined if the server's user name attribute is null (but will probably cause a NullPointerError with most implementations).

        Login will work with the Perforce SSO (single sign-on) scheme: in this case your password should be null, and the environment variable P4LOGINSSO should point to an executable SSO script as described in p4 help undoc (help for this is beyond the scope of this method doc, unfortunately, and the feature is not well tested here, but it "works" in general...).

        Specified by:
        login in interface ILoginDelegator
        Parameters:
        password - Perforce password; can be null if no password is needed (as in the case of SSO logins)
        allHosts - if true, perform the equivalent of a "login -a"
        Throws:
        ConnectionException - if the Perforce server is unreachable or is not connected.
        RequestException - if the Perforce server encounters an error during its processing of the request
        AccessException - if the Perforce server denies access to the caller
        ConfigException - if the p4tickets file could not be updated successfully
      • isDontWriteTicket

        public boolean isDontWriteTicket​(java.lang.String cmd,
                                         java.lang.String[] cmdArgs)
        Description copied from interface: ILoginDelegator
        Special case handling of the "-p" flag for the "p4 login" command. The -p flag displays the ticket, but does not store it on the client machine.
        Specified by:
        isDontWriteTicket in interface ILoginDelegator
        Parameters:
        cmd - the cmd
        cmdArgs - the cmd args
        Returns:
        true, if is dont write ticket
      • login

        public void login​(java.lang.String password,
                          LoginOptions opts)
                   throws P4JavaException
        Description copied from interface: ILoginDelegator
        Log the current user (if any) in to a Perforce server, optionally arranging to be logged in for all hosts.

        Attempts to log in to the underlying Perforce server. If successful, successive calls to server-side services will succeed until the session is terminated by the server or the user logs out.

        Behavior is undefined if the server's user name attribute is null (but will probably cause a NullPointerError with most implementations).

        Login will work with the Perforce SSO (single sign-on) scheme: in this case your password should be null, and the environment variable P4LOGINSSO should point to an executable SSO script as described in p4 help undoc (help for this is beyond the scope of this method doc, unfortunately, and the feature is not well tested here, but it "works" in general...).

        Specified by:
        login in interface ILoginDelegator
        Parameters:
        password - Perforce password; can be null if no password is needed (as in the case of SSO logins)
        opts - if LoginOptions.allHosts is true, perform the equivalent of a "login -a". A null LoginOptions parameter is equivalent to no options being set.
        Throws:
        P4JavaException - if any error occurs in the processing of this method. A specific ConfigException is thrown if the p4tickets file could not be updated successfully.
      • login

        public void login​(java.lang.String password,
                          java.lang.StringBuffer ticket,
                          LoginOptions opts)
                   throws P4JavaException
        Description copied from interface: ILoginDelegator
        Log the current user (if any) in to a Perforce server using. If the ticket StringBuffer parameter is non-null, the auth ticket returned from the server will be appended to the passed-in ticket StringBuffer.

        Optionally, if the opts.isDontWriteTicket() is true ('login -p'), the ticket is not written to file; if opts.isAllHosts is true ('login -a'), the ticket is valid on all hosts; if opts.getHost() is non-null ('login -h'), the ticket is valid on the specified host.

        Note: if the passed-in ticket StringBuffer originally has content it will remain there. The auth ticket will only be appended to the buffer. If a null ticket StringBuffer is passed in, the auth ticket will not be appended to it. The normal use case should be to pass in a new ticket StringBuffer.

        Specified by:
        login in interface ILoginDelegator
        Parameters:
        password - Perforce actuallPassword; can be null if no actuallPassword is needed (as in the case of SSO logins)
        ticket - if the ticket StringBuffer parameter is non-null, the auth ticket that was returned by the login attempt is appended to the passed-in ticket StringBuffer.
        opts - LoginOptions describing the associated options; if null, no options are set.
        Throws:
        P4JavaException - if any error occurs in the processing of this method.
      • login

        public void login​(@Nonnull
                          IUser user,
                          java.lang.StringBuffer ticket,
                          LoginOptions opts)
                   throws P4JavaException
        Description copied from interface: ILoginDelegator
        Log another user in to Perforce by obtaining a session ticket for that user. If the ticket StringBuffer parameter is non-null, the auth ticket returned from the server will be appended to the passed-in ticket StringBuffer.

        Optionally, if the opts.isDontWriteTicket() is true ('login -p'), the ticket is not written to file; if opts.isAllHosts is true ('login -a'), the ticket is valid on all hosts; if opts.getHost() is non-null ('login -h'), the ticket is valid on the specified host.

        Specifying a user as an argument requires 'super' access, which is granted by 'p4 protect'. In this case, login another user does not require a password, assuming that you (a 'super' user) had already been logged in.

        Note: if the passed-in ticket StringBuffer originally has content it will remain there. The auth ticket will only be appended to the buffer. If a null ticket StringBuffer is passed in, the auth ticket will not be appended to it. The normal use case should be to pass in a new ticket StringBuffer.

        Specified by:
        login in interface ILoginDelegator
        Parameters:
        user - non-null Perforce user; login request is for this specified user.
        ticket - if the ticket StringBuffer parameter is non-null, the auth ticket that was returned by the login attempt is appended to the passed-in ticket StringBuffer.
        opts - LoginOptions describing the associated options; if null, no options are set.
        Throws:
        P4JavaException - if any error occurs in the processing of this method.