Class ApiKeyService

java.lang.Object
edu.ucsb.cs156.frontiers.services.ApiKeyService

@Service public class ApiKeyService extends Object
  • Constructor Details

  • Method Details

    • apiKeysEnabled

      public boolean apiKeysEnabled(Long courseId)
      Whether the ENABLE_API_KEYS course option is on for the course. Keys can only be created for, and used with, a course that has the option on; turning it off disables every key of the course at once.
      Parameters:
      courseId - the id of the course
      Returns:
      true if the option is enabled, false if it is disabled or has never been set
    • createApiKey

      public ApiKeyService.IssuedCourseApiKey createApiKey(Course course, ApiKeyService.ExpirationChoice choice, String label)
      Creates a key for the course.
      Parameters:
      course - the course the key is for
      choice - how long the key lasts
      label - an optional short name for the key; blank is stored as null
      Returns:
      the key and its metadata
    • authenticateKey

      public ApiKeyToken authenticateKey(String key)
    • getApiKeysForCourse

      public List<CourseApiKey> getApiKeysForCourse(Long courseId)
    • listApiKeys

      public List<CourseApiKeyView> listApiKeys(Long courseId)
      The keys of a course as an instructor may see them (never the key itself), newest first.
      Parameters:
      courseId - the id of the course
      Returns:
      one view per key, including revoked and expired ones
    • revokeApiKeyById

      public boolean revokeApiKeyById(Long id, Long courseId)
      Revokes a key by id, for the instructor's key table. The course id must match the key's, so that an instructor of one course cannot revoke another course's keys by guessing ids.
      Parameters:
      id - the key's id
      courseId - the course the key is expected to belong to
      Returns:
      true if the key was found in that course (and is now revoked), false otherwise
    • getApiKeysForUser

      public List<CourseApiKey> getApiKeysForUser(User user)
    • revokeApiKey

      public boolean revokeApiKey(String key)