public class AuthzClient extends Object
This is class serves as an entry point for clients looking for access to Keycloak Authorization Services.
When creating a new instances make sure you have a Keycloak Server running at the location specified in the client configuration. The client tries to obtain server configuration by invoking the UMA Discovery Endpoint, usually available from the server at http(s)://{server}:{port}/auth/realms/{realm}/.well-known/uma-configuration.
Modifier and Type | Method and Description |
---|---|
AuthorizationResource |
authorization()
Creates a
AuthorizationResource instance which can be used to obtain permissions from the server. |
AuthorizationResource |
authorization(String accessToken)
Creates a
AuthorizationResource instance which can be used to obtain permissions from the server. |
AuthorizationResource |
authorization(String userName,
String password)
Creates a
AuthorizationResource instance which can be used to obtain permissions from the server. |
static AuthzClient |
create()
Creates a new instance.
|
static AuthzClient |
create(Configuration configuration)
Creates a new instance.
|
static AuthzClient |
create(Configuration configuration,
ClientAuthenticator authenticator)
Creates a new instance.
|
static AuthzClient |
create(InputStream configStream)
Creates a new instance.
|
Configuration |
getConfiguration()
Obtains the client configuration
|
ServerConfiguration |
getServerConfiguration()
Returns the configuration obtained from the server at the UMA Discovery Endpoint.
|
AccessTokenResponse |
obtainAccessToken()
Obtains an access token using the client credentials.
|
AccessTokenResponse |
obtainAccessToken(String userName,
String password)
Obtains an access token using the resource owner credentials.
|
ProtectionResource |
protection()
Creates a
ProtectionResource instance which can be used to access the Protection API. |
ProtectionResource |
protection(String accessToken)
Creates a
ProtectionResource instance which can be used to access the Protection API. |
ProtectionResource |
protection(String userName,
String password)
Creates a
ProtectionResource instance which can be used to access the Protection API. |
public static AuthzClient create() throws RuntimeException
Creates a new instance.
This method expects a keycloak.json
in the classpath, otherwise an exception will be thrown.
RuntimeException
- in case there is no keycloak.json
file in the classpath or the file could not be parsedpublic static AuthzClient create(InputStream configStream) throws RuntimeException
Creates a new instance.
configStream
- the input stream with the configuration dataRuntimeException
public static AuthzClient create(Configuration configuration)
Creates a new instance.
configuration
- the client configurationpublic static AuthzClient create(Configuration configuration, ClientAuthenticator authenticator)
Creates a new instance.
configuration
- the client configurationauthenticator
- the client authenticatorpublic ProtectionResource protection()
Creates a ProtectionResource
instance which can be used to access the Protection API.
When using this method, the PAT (the access token with the uma_protection scope) is obtained for the client itself, using any of the supported credential types (client/secret, jwt, etc).
ProtectionResource
public ProtectionResource protection(String accessToken)
Creates a ProtectionResource
instance which can be used to access the Protection API.
accessToken
- the PAT (the access token with the uma_protection scope)ProtectionResource
public ProtectionResource protection(String userName, String password)
Creates a ProtectionResource
instance which can be used to access the Protection API.
When using this method, the PAT (the access token with the uma_protection scope) is obtained for a given user.
ProtectionResource
public AuthorizationResource authorization()
Creates a AuthorizationResource
instance which can be used to obtain permissions from the server.
AuthorizationResource
public AuthorizationResource authorization(String accessToken)
Creates a AuthorizationResource
instance which can be used to obtain permissions from the server.
accessToken
- the Access Token that will be used as a bearer to access the token endpointAuthorizationResource
public AuthorizationResource authorization(String userName, String password)
Creates a AuthorizationResource
instance which can be used to obtain permissions from the server.
userName
- an ID Token or Access Token representing an identity and/or access contextpassword
- AuthorizationResource
public AccessTokenResponse obtainAccessToken()
AccessTokenResponse
public AccessTokenResponse obtainAccessToken(String userName, String password)
AccessTokenResponse
public ServerConfiguration getServerConfiguration()
ServerConfiguration
public Configuration getConfiguration()
Configuration
Copyright © 2019 JBoss by Red Hat. All rights reserved.