Class AuthorizedSessionHelper
java.lang.Object
com.janeirodigital.sai.authentication.AuthorizedSessionHelper
Assorted helper methods related to working with OAuth2 / OpenID Connect sessions, tokens,
and authorization servers. Makes liberal use of the
Nimbus SDK.
-
Method Summary
Modifier and TypeMethodDescriptionstatic okhttp3.Response
deleteProtectedResource
(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri) CallsdeleteProtectedResource(AuthorizedSession, OkHttpClient, URI, Headers)
with no additional headers provided.static okhttp3.Response
deleteProtectedResource
(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, okhttp3.Headers headers) Deletes a protected resource that requires additional Authorization headers to be added to the request.static AccessToken
getAccessTokenFromRequest
(okhttp3.Request request) Extracts the value of an access token from the Authorization header of an HTTP request.static org.apache.jena.rdf.model.Resource
getClientIdDocument
(okhttp3.OkHttpClient httpClient, URI clientId) Get the client identifier document as a Jena Resource associated with the providedclientId
static URI
getOidcIssuerForSocialAgent
(okhttp3.OkHttpClient httpClient, URI socialAgentId) static com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata
getOIDCProviderConfiguration
(URI providerUri) Get the configuration of an OpenID Provider based on the discovery and contents of its .well-known/openid-configuration resource.static okhttp3.Response
getProtectedRdfResource
(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri) CallsgetProtectedRdfResource(AuthorizedSession, OkHttpClient, URI, Headers)
with no additional headers provided.static okhttp3.Response
getProtectedRdfResource
(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, okhttp3.Headers headers) Gets a protected RDF resource that requires additional Authorization headers to be added to the request.static okhttp3.Response
getProtectedResource
(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri) CallsgetProtectedResource(AuthorizedSession, OkHttpClient, URI, Headers)
with no additional headers provided.static okhttp3.Response
getProtectedResource
(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, okhttp3.Headers headers) Gets a protected resource that requires additional Authorization headers to be added to the request.static okhttp3.Response
putProtectedRdfResource
(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, org.apache.jena.rdf.model.Resource resource, com.janeirodigital.sai.httputils.ContentType contentType) CallsputProtectedRdfResource(AuthorizedSession, OkHttpClient, URI, Resource, ContentType, String, Headers)
with no additional headers provided.static okhttp3.Response
putProtectedRdfResource
(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, org.apache.jena.rdf.model.Resource resource, com.janeirodigital.sai.httputils.ContentType contentType, String jsonLdContext) CallsputProtectedRdfResource(AuthorizedSession, OkHttpClient, URI, Resource, ContentType, String, Headers)
with additional headers providedstatic okhttp3.Response
putProtectedRdfResource
(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, org.apache.jena.rdf.model.Resource resource, com.janeirodigital.sai.httputils.ContentType contentType, String jsonLdContext, okhttp3.Headers headers) Puts a protected RDF resource that requires additional Authorization headers to be added to the request.static okhttp3.Response
putProtectedRdfResource
(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, org.apache.jena.rdf.model.Resource resource, com.janeirodigital.sai.httputils.ContentType contentType, okhttp3.Headers headers) CallsputProtectedRdfResource(AuthorizedSession, OkHttpClient, URI, Resource, ContentType, String, Headers)
with additional headers providedstatic okhttp3.Headers
setAuthorizationHeaders
(AuthorizedSession authorizedSession, com.janeirodigital.sai.httputils.HttpMethod method, URI uri, okhttp3.Headers headers) Sets the appropriate HTTP Authorization headers based on the characteristics of theAuthorizedSession
.static AccessToken
translateAccessToken
(com.nimbusds.oauth2.sdk.token.AccessToken nimbusAccessToken) Translates a nimbus native AccessToken into the generic sai-java formatstatic RefreshToken
translateRefreshToken
(com.nimbusds.oauth2.sdk.token.RefreshToken nimbusRefreshToken) Translates a nimbus native AccessToken into the generic sai-java format
-
Method Details
-
getOidcIssuerForSocialAgent
public static URI getOidcIssuerForSocialAgent(okhttp3.OkHttpClient httpClient, URI socialAgentId) throws SaiAuthenticationException - Throws:
SaiAuthenticationException
-
getOIDCProviderConfiguration
public static com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata getOIDCProviderConfiguration(URI providerUri) throws SaiAuthenticationException Get the configuration of an OpenID Provider based on the discovery and contents of its .well-known/openid-configuration resource.- Parameters:
providerUri
- URI of the OpenID Provider- Returns:
- OIDCProviderMetadata
- Throws:
SaiAuthenticationException
-
getClientIdDocument
public static org.apache.jena.rdf.model.Resource getClientIdDocument(okhttp3.OkHttpClient httpClient, URI clientId) throws SaiAuthenticationException Get the client identifier document as a Jena Resource associated with the providedclientId
- Parameters:
httpClient
- OkHttpClient to perform the GET withclientId
- URI of the client identifier to get- Returns:
- Jena RDF Resource
- Throws:
SaiAuthenticationException
-
getProtectedResource
public static okhttp3.Response getProtectedResource(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, okhttp3.Headers headers) throws SaiAuthenticationException, com.janeirodigital.sai.httputils.SaiHttpException Gets a protected resource that requires additional Authorization headers to be added to the request.- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourceshttpClient
- OkHttpClient to perform the GET withuri
- URI of the resource to GETheaders
- Optional OkHttp Headers- Returns:
- OkHttp Response
- Throws:
SaiAuthenticationException
com.janeirodigital.sai.httputils.SaiHttpException
-
getProtectedResource
public static okhttp3.Response getProtectedResource(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri) throws SaiAuthenticationException, com.janeirodigital.sai.httputils.SaiHttpException CallsgetProtectedResource(AuthorizedSession, OkHttpClient, URI, Headers)
with no additional headers provided.- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourceshttpClient
- OkHttpClient to perform the GET withuri
- URI of the resource to GET- Returns:
- OkHttp Response
- Throws:
SaiAuthenticationException
com.janeirodigital.sai.httputils.SaiHttpException
-
getProtectedRdfResource
public static okhttp3.Response getProtectedRdfResource(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, okhttp3.Headers headers) throws SaiAuthenticationException, com.janeirodigital.sai.httputils.SaiHttpException Gets a protected RDF resource that requires additional Authorization headers to be added to the request.- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourceshttpClient
- OkHttpClient to perform the GET withuri
- URI of the resource to GETheaders
- Optional OkHttp Headers- Returns:
- OkHttp Response
- Throws:
SaiAuthenticationException
com.janeirodigital.sai.httputils.SaiHttpException
-
getProtectedRdfResource
public static okhttp3.Response getProtectedRdfResource(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri) throws SaiAuthenticationException, com.janeirodigital.sai.httputils.SaiHttpException CallsgetProtectedRdfResource(AuthorizedSession, OkHttpClient, URI, Headers)
with no additional headers provided.- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourceshttpClient
- OkHttpClient to perform the GET withuri
- URI of the resource to GET- Returns:
- OkHttp Response
- Throws:
SaiAuthenticationException
com.janeirodigital.sai.httputils.SaiHttpException
-
putProtectedRdfResource
public static okhttp3.Response putProtectedRdfResource(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, org.apache.jena.rdf.model.Resource resource, com.janeirodigital.sai.httputils.ContentType contentType, String jsonLdContext, okhttp3.Headers headers) throws SaiAuthenticationException, com.janeirodigital.sai.httputils.SaiHttpException Puts a protected RDF resource that requires additional Authorization headers to be added to the request.- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourceshttpClient
- OkHttpClient to perform the PUT withuri
- URI of the resource to PUTresource
- Jena resource to PUT withcontentType
- ContentType of the requestjsonLdContext
- Optional JSON-LD context string to includeheaders
- Optional OkHttp Headers- Returns:
- OkHttp Response
- Throws:
SaiAuthenticationException
com.janeirodigital.sai.httputils.SaiHttpException
-
putProtectedRdfResource
public static okhttp3.Response putProtectedRdfResource(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, org.apache.jena.rdf.model.Resource resource, com.janeirodigital.sai.httputils.ContentType contentType) throws SaiAuthenticationException, com.janeirodigital.sai.httputils.SaiHttpException CallsputProtectedRdfResource(AuthorizedSession, OkHttpClient, URI, Resource, ContentType, String, Headers)
with no additional headers provided.- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourceshttpClient
- OkHttpClient to perform the PUT withuri
- URI of the resource to PUTresource
- Jena resource to PUT withcontentType
- ContentType of the request- Returns:
- OkHttp Response
- Throws:
SaiAuthenticationException
com.janeirodigital.sai.httputils.SaiHttpException
-
putProtectedRdfResource
public static okhttp3.Response putProtectedRdfResource(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, org.apache.jena.rdf.model.Resource resource, com.janeirodigital.sai.httputils.ContentType contentType, okhttp3.Headers headers) throws SaiAuthenticationException, com.janeirodigital.sai.httputils.SaiHttpException CallsputProtectedRdfResource(AuthorizedSession, OkHttpClient, URI, Resource, ContentType, String, Headers)
with additional headers provided- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourceshttpClient
- OkHttpClient to perform the PUT withuri
- URI of the resource to PUTresource
- Jena resource to PUT withcontentType
- ContentType of the requestheaders
- Optional OkHttp Headers- Returns:
- OkHttp Response
- Throws:
SaiAuthenticationException
com.janeirodigital.sai.httputils.SaiHttpException
-
putProtectedRdfResource
public static okhttp3.Response putProtectedRdfResource(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, org.apache.jena.rdf.model.Resource resource, com.janeirodigital.sai.httputils.ContentType contentType, String jsonLdContext) throws SaiAuthenticationException, com.janeirodigital.sai.httputils.SaiHttpException CallsputProtectedRdfResource(AuthorizedSession, OkHttpClient, URI, Resource, ContentType, String, Headers)
with additional headers provided- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourceshttpClient
- OkHttpClient to perform the PUT withuri
- URI of the resource to PUTresource
- Jena resource to PUT withcontentType
- ContentType of the requestjsonLdContext
- Optional JSON-LD context string to include- Returns:
- OkHttp Response
- Throws:
SaiAuthenticationException
com.janeirodigital.sai.httputils.SaiHttpException
-
deleteProtectedResource
public static okhttp3.Response deleteProtectedResource(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri, okhttp3.Headers headers) throws SaiAuthenticationException, com.janeirodigital.sai.httputils.SaiHttpException Deletes a protected resource that requires additional Authorization headers to be added to the request.- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourceshttpClient
- OkHttpClient to perform the DELETE withuri
- URI of the resource to DELETEheaders
- Optional OkHttp Headers- Returns:
- OkHttp Response
- Throws:
SaiAuthenticationException
com.janeirodigital.sai.httputils.SaiHttpException
-
deleteProtectedResource
public static okhttp3.Response deleteProtectedResource(AuthorizedSession authorizedSession, okhttp3.OkHttpClient httpClient, URI uri) throws SaiAuthenticationException, com.janeirodigital.sai.httputils.SaiHttpException CallsdeleteProtectedResource(AuthorizedSession, OkHttpClient, URI, Headers)
with no additional headers provided.- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourceshttpClient
- OkHttpClient to perform the DELETE withuri
- URI of the resource to DELETE- Returns:
- OkHttp Response
- Throws:
SaiAuthenticationException
com.janeirodigital.sai.httputils.SaiHttpException
-
setAuthorizationHeaders
public static okhttp3.Headers setAuthorizationHeaders(AuthorizedSession authorizedSession, com.janeirodigital.sai.httputils.HttpMethod method, URI uri, okhttp3.Headers headers) throws SaiAuthenticationException Sets the appropriate HTTP Authorization headers based on the characteristics of theAuthorizedSession
.- Parameters:
authorizedSession
-AuthorizedSession
for access to protected resourcesmethod
-HttpMethod
of the requesturi
- Target URI of the requestheaders
- Optional OkHttp Headers- Returns:
- Populated OkHttp Headers
- Throws:
SaiAuthenticationException
-
getAccessTokenFromRequest
Extracts the value of an access token from the Authorization header of an HTTP request. Returns null if no Authorization header exists or the token type isn't recognized.- Parameters:
request
- OkHttp Request- Returns:
- Access token value or null
-
translateAccessToken
public static AccessToken translateAccessToken(com.nimbusds.oauth2.sdk.token.AccessToken nimbusAccessToken) Translates a nimbus native AccessToken into the generic sai-java format- Parameters:
nimbusAccessToken
- Nimbus AccessToken- Returns:
- AccessToken in sai-java format
-
translateRefreshToken
public static RefreshToken translateRefreshToken(com.nimbusds.oauth2.sdk.token.RefreshToken nimbusRefreshToken) Translates a nimbus native AccessToken into the generic sai-java format- Parameters:
nimbusRefreshToken
- Nimbus RefreshToken- Returns:
- RefreshToken in sai-java format
-