code: public Session login(final Credentials credentials, String workspaceName) throws LoginException,
        NoSuchWorkspaceException, RepositoryException
     {
  
        if (getState() == OFFLINE)
        {
           LOG.warn("Repository " + getName() + " is OFFLINE.");
        }
  
        ConversationState state;
  
        PrivilegedExceptionAction<ConversationState> action = new PrivilegedExceptionAction<ConversationState>()
        {
           public ConversationState run() throws Exception
           {
              if (credentials != null)
              {
                 return authenticationPolicy.authenticate(credentials);
              }
              else
              {
                 return authenticationPolicy.authenticate();
              }
           }
        };
        try
        {
           state = SecurityHelper.doPrivilegedExceptionAction(action);
        }
        catch (PrivilegedActionException pae)
        {
           Throwable cause = pae.getCause();
           if (cause instanceof LoginException)
           {
              throw (LoginException)cause;
           }
           else if (cause instanceof RuntimeException)
           {
              throw (RuntimeException)cause;
           }
           else
           {
              throw new RuntimeException(cause);
           }
        }
  
        return internalLogin(state, workspaceName);
     }
docs: {@inheritDoc}