Class AuthzClient
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.
- Author:
- Pedro Igor
-
Method Summary
Modifier and TypeMethodDescriptionCreates aAuthorizationResource
instance which can be used to obtain permissions from the server.authorization
(String accessToken) Creates aAuthorizationResource
instance which can be used to obtain permissions from the server.authorization
(String userName, String password) Creates aAuthorizationResource
instance which can be used to obtain permissions from the server.authorization
(String userName, String password, String scope) static AuthzClient
create()
Creates a new instance.static AuthzClient
create
(InputStream configStream) Creates a new instance.static AuthzClient
create
(Configuration configuration) Creates a new instance.createPatSupplier
(String userName, String password) Obtains the client configurationReturns the configuration obtained from the server at the UMA Discovery Endpoint.Obtains an access token using the client credentials.obtainAccessToken
(String userName, String password) Obtains an access token using the resource owner credentials.Creates aProtectionResource
instance which can be used to access the Protection API.protection
(String accessToken) Creates aProtectionResource
instance which can be used to access the Protection API.protection
(String userName, String password) Creates aProtectionResource
instance which can be used to access the Protection API.
-
Method Details
-
create
Creates a new instance.
This method expects a
keycloak.json
in the classpath, otherwise an exception will be thrown.- Returns:
- a new instance
- Throws:
RuntimeException
- in case there is nokeycloak.json
file in the classpath or the file could not be parsed
-
create
Creates a new instance.
- Parameters:
configStream
- the input stream with the configuration data- Returns:
- a new instance
- Throws:
RuntimeException
-
create
Creates a new instance.
- Parameters:
configuration
- the client configuration- Returns:
- a new instance
-
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).
- Returns:
- a
ProtectionResource
-
protection
Creates a
ProtectionResource
instance which can be used to access the Protection API.- Parameters:
accessToken
- the PAT (the access token with the uma_protection scope)- Returns:
- a
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 a given user.
- Returns:
- a
ProtectionResource
-
authorization
Creates a
AuthorizationResource
instance which can be used to obtain permissions from the server.- Returns:
- a
AuthorizationResource
-
authorization
Creates a
AuthorizationResource
instance which can be used to obtain permissions from the server.- Parameters:
accessToken
- the Access Token that will be used as a bearer to access the token endpoint- Returns:
- a
AuthorizationResource
-
authorization
Creates a
AuthorizationResource
instance which can be used to obtain permissions from the server.- Parameters:
userName
- an ID Token or Access Token representing an identity and/or access contextpassword
-- Returns:
- a
AuthorizationResource
-
authorization
-
obtainAccessToken
Obtains an access token using the client credentials.- Returns:
- an
AccessTokenResponse
-
obtainAccessToken
Obtains an access token using the resource owner credentials.- Returns:
- an
AccessTokenResponse
-
getServerConfiguration
Returns the configuration obtained from the server at the UMA Discovery Endpoint.- Returns:
- the
ServerConfiguration
-
getConfiguration
Obtains the client configuration- Returns:
- the
Configuration
-
createPatSupplier
-
createPatSupplier
-