Package org.jenkinsci.plugins
Class KeycloakSecurityRealm
java.lang.Object
hudson.model.AbstractDescribableImpl<SecurityRealm>
hudson.security.SecurityRealm
org.jenkinsci.plugins.KeycloakSecurityRealm
- All Implemented Interfaces:
ExtensionPoint
,Describable<SecurityRealm>
Implementation of the AbstractPasswordBasedSecurityRealm that uses keycloak
oauth for sso.
This is based on the MySQLSecurityRealm from the mysql-auth-plugin written by
Alex Ackerman.
- Author:
- Mohammad Nadeem, devlauer
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Descriptor definition for Jenkinsstatic class
Nested classes/interfaces inherited from class hudson.security.SecurityRealm
SecurityRealm.SecurityComponents
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
This constant is used to save the state of an authenticated session.static final String
The default URL to finish the login process of this pluginFields inherited from class hudson.security.SecurityRealm
AUTHENTICATED_AUTHORITY, AUTHENTICATED_AUTHORITY2, LIST, NO_AUTHENTICATION
-
Constructor Summary
ModifierConstructorDescriptionprotected
KeycloakSecurityRealm
(String keycloakIdp, String keycloakJson, boolean keycloakValidate, boolean keycloakRespectAccessTokenTimeout) Constructor -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
Returns true if authentication should be checked on each responseorg.kohsuke.stapler.HttpResponse
doCommenceLogin
(org.kohsuke.stapler.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response, String referer) org.kohsuke.stapler.HttpResponse
doFinishLogin
(org.kohsuke.stapler.StaplerRequest request) This is where the user comes back to at the end of the OpenID redirect ping-pong.void
doLogout
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) org.keycloak.adapters.KeycloakDeployment
Returns the current KeycloakDeployment configuration.Returns the keycloak idp hint.Returns the keycloak configurationboolean
Returns the configuration parameter for the access token checkboolean
Returns the configuration parameter for the authentication check on each requestboolean
Returns true if the access token should be only refreshed after its timeoutvoid
setKeycloakIdp
(String keycloakIdp) Sets the keycloak idp hint.void
setKeycloakJson
(String keycloakJson) Sets the keycloak json configuration stringvoid
setKeycloakRespectAccessTokenTimeout
(boolean keycloakRespectAccessTokenTimeout) Sets the configuration parameter for the access token checkvoid
setKeycloakValidate
(boolean keycloakValidate) Sets the configuration parameter for the authentication checkMethods inherited from class hudson.security.SecurityRealm
all, canLogOut, commenceSignup, commonFilters, createCliAuthenticator, createFilter, doCaptcha, getAuthenticationGatewayUrl, getCaptchaSupport, getCaptchaSupportDescriptors, getDescriptor, getFrom, getGroupIdStrategy, getPostLogOutUrl, getPostLogOutUrl2, getSecurityComponents, getUserIdStrategy, loadGroupByGroupname, loadGroupByGroupname, loadGroupByGroupname2, loadUserByUsername, loadUserByUsername2, setCaptchaSupport, validateCaptcha
-
Field Details
-
JENKINS_FINISH_LOGIN_URL
The default URL to finish the login process of this plugin- See Also:
-
AUTH_REQUESTED
This constant is used to save the state of an authenticated session. If the login process starts it is set to true, if a logout process is initiated it is set to false.- See Also:
-
-
Constructor Details
-
KeycloakSecurityRealm
@DataBoundConstructor public KeycloakSecurityRealm(String keycloakIdp, String keycloakJson, boolean keycloakValidate, boolean keycloakRespectAccessTokenTimeout) throws IOException Constructor- Throws:
IOException
- -
-
KeycloakSecurityRealm
protected KeycloakSecurityRealm()
-
-
Method Details
-
doCommenceLogin
public org.kohsuke.stapler.HttpResponse doCommenceLogin(org.kohsuke.stapler.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response, @Header("Referer") String referer) throws IOException - Parameters:
request
- the Jenkins requestresponse
- the Jenkins responsereferer
- the referrer- Returns:
HttpResponse
the response- Throws:
IOException
-
doFinishLogin
public org.kohsuke.stapler.HttpResponse doFinishLogin(org.kohsuke.stapler.StaplerRequest request) throws IOException This is where the user comes back to at the end of the OpenID redirect ping-pong.- Parameters:
request
- the Jenkins request- Returns:
HttpResponse
the response- Throws:
IOException
-
allowsSignup
public boolean allowsSignup()- Overrides:
allowsSignup
in classSecurityRealm
-
createSecurityComponents
- Specified by:
createSecurityComponents
in classSecurityRealm
-
getLoginUrl
- Overrides:
getLoginUrl
in classSecurityRealm
-
doLogout
public void doLogout(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException - Overrides:
doLogout
in classSecurityRealm
- Throws:
IOException
javax.servlet.ServletException
-
getKeycloakJson
Returns the keycloak configuration- Returns:
String
the configuration string
-
setKeycloakJson
Sets the keycloak json configuration string- Parameters:
keycloakJson
- the configuration
-
isKeycloakValidate
public boolean isKeycloakValidate()Returns the configuration parameter for the authentication check on each request- Returns:
Boolean
if true, authentication is checked on each request
-
setKeycloakValidate
public void setKeycloakValidate(boolean keycloakValidate) Sets the configuration parameter for the authentication check- Parameters:
keycloakValidate
-Boolean
if true authentication is checked on each request
-
isKeycloakRespectAccessTokenTimeout
public boolean isKeycloakRespectAccessTokenTimeout()Returns the configuration parameter for the access token check- Returns:
Boolean
whether the expiration of the access token should be checked or not before a token refresh
-
setKeycloakRespectAccessTokenTimeout
public void setKeycloakRespectAccessTokenTimeout(boolean keycloakRespectAccessTokenTimeout) Sets the configuration parameter for the access token check- Parameters:
keycloakRespectAccessTokenTimeout
-Boolean
whether the expiration of the access token should be checked or not before a token refresh
-
getKeycloakIdp
Returns the keycloak idp hint.- Returns:
String
the keycloak idp hint
-
setKeycloakIdp
Sets the keycloak idp hint.- Parameters:
keycloakIdp
-String
the keycloak idp hint
-
checkKeycloakOnEachRequest
public boolean checkKeycloakOnEachRequest()Returns true if authentication should be checked on each response- Returns:
Boolean
-
respectAccessTokenTimeout
public boolean respectAccessTokenTimeout()Returns true if the access token should be only refreshed after its timeout- Returns:
Boolean
-
getKeycloakDeployment
Returns the current KeycloakDeployment configuration.- Returns:
KeycloakDeployment
the keycloak configuration- Throws:
IOException
-