Interface CurrentSessionInfo

All Known Implementing Classes:
CurrentSessionInfo.NoOpCurrentSessionInfo

public interface CurrentSessionInfo
Simple interface for reading information about the current user, session, and roles. Implementations should depend on as few Daos, Services, etc., as possible to minimize risk of circular dependencies. Only getSession(ServletRequest), and getRoles(ServletRequest) need to be implemented.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default Optional<String>
    findNonEmptyUsername(javax.servlet.ServletRequest request)
    find the username
    default String
    getNonEmptyUsernameOrElse(javax.servlet.ServletRequest request, String other)
    Gets the username or an alternate value
    default Session
    getRequiredSession(javax.servlet.ServletRequest request)
     
    getRoles(javax.servlet.ServletRequest request)
    returns the Roles associated with the current user/session, an empty set if there is no current session
    Optional<? extends Session>
    getSession(javax.servlet.ServletRequest request)
     
    default boolean
    hasAnyRole(javax.servlet.ServletRequest request, Collection<Role> targetRoles)
     
    default boolean
    hasAnyRoleEnum(javax.servlet.ServletRequest request, Collection<RoleEnum<?>> targetRoles)
     
    default boolean
    hasRole(javax.servlet.ServletRequest request, Role role)
    returns whether the current user/session is associated with the given Role, false if there is no current session
    default boolean
    hasRole(javax.servlet.ServletRequest request, RoleEnum<?> role)
    returns whether the current user/session is associated with the given Role, false if there is no current session
  • Method Details

    • findNonEmptyUsername

      default Optional<String> findNonEmptyUsername(javax.servlet.ServletRequest request)
      find the username
    • getNonEmptyUsernameOrElse

      default String getNonEmptyUsernameOrElse(javax.servlet.ServletRequest request, String other)
      Gets the username or an alternate value
    • getSession

      Optional<? extends Session> getSession(javax.servlet.ServletRequest request)
    • getRequiredSession

      default Session getRequiredSession(javax.servlet.ServletRequest request)
    • getRoles

      Set<Role> getRoles(javax.servlet.ServletRequest request)
      returns the Roles associated with the current user/session, an empty set if there is no current session
    • hasRole

      default boolean hasRole(javax.servlet.ServletRequest request, Role role)
      returns whether the current user/session is associated with the given Role, false if there is no current session
    • hasRole

      default boolean hasRole(javax.servlet.ServletRequest request, RoleEnum<?> role)
      returns whether the current user/session is associated with the given Role, false if there is no current session
    • hasAnyRole

      default boolean hasAnyRole(javax.servlet.ServletRequest request, Collection<Role> targetRoles)
    • hasAnyRoleEnum

      default boolean hasAnyRoleEnum(javax.servlet.ServletRequest request, Collection<RoleEnum<?>> targetRoles)