code: public synchronized Object put(Object name, Object credentials)
      {
          if (credentials instanceof Principal)
              return super.put(name.toString(),
                               credentials);
          
          if (credentials instanceof Password)
              return super.put(name,
                               new KnownUser(name.toString(),
                                            (Password)credentials));
          if (credentials != null)
              return super
                  .put(name,
                       new KnownUser(name.toString(),
                                     Credential.getCredential(credentials.toString())));
          return null;
      }
docs: Put user into realm.
  @param name User name
  @param credentials String password, Password or UserPrinciple
  instance.
  @return Old UserPrinciple value or null