Skip to content

Commit

Permalink
Some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
blootsvoets committed Oct 1, 2019
1 parent 1ca8e22 commit 9f69d76
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ Library to facilitate OAuth 2.0 integration with a Jersey-based REST API.

# Usage

Add this library to your project using the following Gradle configuration:
```gradle
repositories {
maven { url "https://dl.bintray.com/radar-base/org.radarbase" }
}
dependencies {
api("org.radarbase:radar-auth-jersey:0.1.0")
}
```

Any path or resource that should be authenticated against the ManagementPortal, should be annotated with `@Authenticated`. Specific authorization can be checked by adding a `@NeedsPermission` annotation. An `Auth` object can be injected to get app-specific information. Examples:

```kotlin
Expand Down Expand Up @@ -34,7 +45,7 @@ class Users(@Context projectService: ProjectService) {
}
```

These APIs can be activated by implementing the `ProjectService` that ensures that a project exists and by running, during ResourceConfig setup:
These APIs are activated by adding `JerseyResourceEnhancer` implementations to your resource definition:
```kotlin
val authConfig = AuthConfig(
managementPortalUrl = "http://...",
Expand All @@ -58,6 +69,8 @@ resourceConfig.register(object : AbstractBinder() {
})
```

Ensure that a class implementing `org.radarbase.auth.jersey.ProjectService` is added to the binder.

## Error handling

This package adds some error handling. Specifically, `org.radarbase.auth.jersey.exception.HttpApplicationException` can be used and extended to serve detailed error messages with customized logging and HTML templating. They can be thrown from any resource.
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/org/radarbase/auth/jersey/ProjectService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@

package org.radarbase.auth.jersey

import org.radarbase.auth.jersey.exception.HttpApplicationException

/**
* Service to keep track of active projects.
*/
interface ProjectService {
/**
* Ensure that given project ID is valid.
* @throws HttpApplicationException if the project ID is not a valid project ID.
*/
fun ensureProject(projectId: String)
}

0 comments on commit 9f69d76

Please sign in to comment.