Class ApiKeyService
java.lang.Object
edu.ucsb.cs156.frontiers.services.ApiKeyService
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic final recordA freshly created key. -
Constructor Summary
ConstructorsConstructorDescriptionApiKeyService(org.springframework.data.auditing.DateTimeProvider dateTimeProvider, CourseApiKeyRepository courseApiKeyRepository, CurrentUserService currentUserService, SecureRandom secureRandom, CourseOptionRepository courseOptionRepository) -
Method Summary
Modifier and TypeMethodDescriptionbooleanapiKeysEnabled(Long courseId) Whether the ENABLE_API_KEYS course option is on for the course.authenticateKey(String key) createApiKey(Course course, ApiKeyService.ExpirationChoice choice, String label) Creates a key for the course.getApiKeysForCourse(Long courseId) getApiKeysForUser(User user) listApiKeys(Long courseId) The keys of a course as an instructor may see them (never the key itself), newest first.booleanrevokeApiKey(String key) booleanrevokeApiKeyById(Long id, Long courseId) Revokes a key by id, for the instructor's key table.
-
Constructor Details
-
ApiKeyService
public ApiKeyService(org.springframework.data.auditing.DateTimeProvider dateTimeProvider, CourseApiKeyRepository courseApiKeyRepository, CurrentUserService currentUserService, SecureRandom secureRandom, CourseOptionRepository courseOptionRepository)
-
-
Method Details
-
apiKeysEnabled
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 forchoice- how long the key lastslabel- an optional short name for the key; blank is stored as null- Returns:
- the key and its metadata
-
authenticateKey
-
getApiKeysForCourse
-
listApiKeys
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
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 idcourseId- 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
-
revokeApiKey
-