Class CurrentUserServiceImpl

java.lang.Object
edu.ucsb.cs156.dining.services.CurrentUserService
edu.ucsb.cs156.dining.services.CurrentUserServiceImpl

@Service("currentUser") @Primary public class CurrentUserServiceImpl extends CurrentUserService
This is a service that provides information about the current user. This is the version of the service used in production.
  • Constructor Details

    • CurrentUserServiceImpl

      public CurrentUserServiceImpl()
  • Method Details

    • getCurrentUser

      public CurrentUser getCurrentUser()
      This method returns the current user as a User object.
      Specified by:
      getCurrentUser in class CurrentUserService
      Returns:
      the current user
    • getOAuth2AuthenticatedUser

      public User getOAuth2AuthenticatedUser(org.springframework.security.core.context.SecurityContext securityContext, org.springframework.security.core.Authentication authentication)
      This method obtains the current user that is logged in with OAuth2, if any. The parameters are automatically injected by Spring. This method also has a side effect of storing the user in the database if they are not already there.
      Parameters:
      securityContext - the security context (provided by Spring)
      authentication - the authentication token (provided by Spring)
      Returns:
      the User object representing the current user
    • getUser

      public User getUser()
      This method returns the current user as a User object.
      Specified by:
      getUser in class CurrentUserService
      Returns:
      the current user
    • getRoles

      public Collection<? extends org.springframework.security.core.GrantedAuthority> getRoles()
      This method returns the roles of the current user.
      Specified by:
      getRoles in class CurrentUserService
      Returns:
      a collection of roles