All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.helger.photon.security.user.IUser Maven / Gradle / Ivy

There is a newer version: 8.1.0
Show newest version
/**
 * Copyright (C) 2014-2016 Philip Helger (www.helger.com)
 * philip[at]helger[dot]com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.helger.photon.security.user;

import java.time.LocalDateTime;
import java.util.Locale;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.helger.commons.annotation.MustImplementEqualsAndHashcode;
import com.helger.commons.annotation.Nonempty;
import com.helger.commons.string.StringHelper;
import com.helger.commons.text.IHasDescription;
import com.helger.photon.basic.auth.subject.IAuthSubject;
import com.helger.photon.basic.object.IObjectWithCustomAttrs;
import com.helger.security.password.hash.PasswordHash;

/**
 * Interface for a single user
 *
 * @author Philip Helger
 */
@MustImplementEqualsAndHashcode
public interface IUser extends IObjectWithCustomAttrs, IHasDescription, IAuthSubject
{
  /**
   * @return true if the user has the ID
   *         {@link com.helger.photon.security.CSecurity#USER_ADMINISTRATOR_ID}
   *         , false otherwise
   */
  boolean isAdministrator ();

  /**
   * @return The login name of the user.
   */
  @Nonnull
  @Nonempty
  String getLoginName ();

  /**
   * The email address is optional since 2.6.3
   *
   * @return The email address of the user. May be null.
   */
  @Nullable
  String getEmailAddress ();

  /**
   * @return The hashed password of the user. Never null.
   */
  @Nonnull
  PasswordHash getPasswordHash ();

  /**
   * @return The first name of the user. May be null.
   */
  @Nullable
  String getFirstName ();

  /**
   * @return The last name of the user. May be null.
   */
  @Nullable
  String getLastName ();

  /**
   * @return The display name of the user. May be empty if both first and last
   *         name are empty but never null.
   */
  @Nonnull
  default String getDisplayName ()
  {
    return StringHelper.getConcatenatedOnDemand (getFirstName (), " ", getLastName ());
  }

  /**
   * @return The desired locale of the user. May be null.
   */
  @Nullable
  Locale getDesiredLocale ();

  /**
   * @return The date time when the user last logged in. May be
   *         null if the user never logged in.
   * @since 2.4.2
   */
  @Nullable
  LocalDateTime getLastLoginDateTime ();

  /**
   * @return The number of times the user logged in. Always ≥ 0.
   * @since 2.4.2
   */
  @Nonnegative
  int getLoginCount ();

  /**
   * @return The number of consecutive failed logins of this user.
   * @since 2.6.3
   */
  @Nonnegative
  int getConsecutiveFailedLoginCount ();

  /**
   * @return true if this user is enabled, false if it
   *         is disabled
   * @see #isDisabled()
   */
  default boolean isEnabled ()
  {
    return !isDisabled ();
  }

  /**
   * @return true if this user is disabled, false if
   *         it is enabled
   * @see #isEnabled()
   */
  boolean isDisabled ();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy