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
Nested ClassesModifier and TypeClassDescriptionstatic final classDescriptor definition for Jenkinsstatic classNested classes/interfaces inherited from class hudson.security.SecurityRealm
SecurityRealm.SecurityComponentsNested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThis constant is used to save the state of an authenticated session.static final StringThe 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
ConstructorsModifierConstructorDescriptionprotectedKeycloakSecurityRealm(String keycloakIdp, String keycloakJson, boolean keycloakValidate, boolean keycloakRespectAccessTokenTimeout) Constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanReturns true if authentication should be checked on each responseorg.kohsuke.stapler.HttpResponsedoCommenceLogin(org.kohsuke.stapler.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response, String referer) org.kohsuke.stapler.HttpResponsedoFinishLogin(org.kohsuke.stapler.StaplerRequest request) This is where the user comes back to at the end of the OpenID redirect ping-pong.voiddoLogout(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) org.keycloak.adapters.KeycloakDeploymentReturns the current KeycloakDeployment configuration.Returns the keycloak idp hint.Returns the keycloak configurationbooleanReturns the configuration parameter for the access token checkbooleanReturns the configuration parameter for the authentication check on each requestbooleanReturns true if the access token should be only refreshed after its timeoutvoidsetKeycloakIdp(String keycloakIdp) Sets the keycloak idp hint.voidsetKeycloakJson(String keycloakJson) Sets the keycloak json configuration stringvoidsetKeycloakRespectAccessTokenTimeout(boolean keycloakRespectAccessTokenTimeout) Sets the configuration parameter for the access token checkvoidsetKeycloakValidate(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:
HttpResponsethe 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:
HttpResponsethe response- Throws:
IOException
-
allowsSignup
public boolean allowsSignup()- Overrides:
allowsSignupin classSecurityRealm
-
createSecurityComponents
- Specified by:
createSecurityComponentsin classSecurityRealm
-
getLoginUrl
- Overrides:
getLoginUrlin classSecurityRealm
-
doLogout
public void doLogout(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException - Overrides:
doLogoutin classSecurityRealm- Throws:
IOExceptionjavax.servlet.ServletException
-
getKeycloakJson
Returns the keycloak configuration- Returns:
Stringthe 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:
Booleanif true, authentication is checked on each request
-
setKeycloakValidate
public void setKeycloakValidate(boolean keycloakValidate) Sets the configuration parameter for the authentication check- Parameters:
keycloakValidate-Booleanif true authentication is checked on each request
-
isKeycloakRespectAccessTokenTimeout
public boolean isKeycloakRespectAccessTokenTimeout()Returns the configuration parameter for the access token check- Returns:
Booleanwhether 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-Booleanwhether the expiration of the access token should be checked or not before a token refresh
-
getKeycloakIdp
Returns the keycloak idp hint.- Returns:
Stringthe keycloak idp hint
-
setKeycloakIdp
Sets the keycloak idp hint.- Parameters:
keycloakIdp-Stringthe 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:
KeycloakDeploymentthe keycloak configuration- Throws:
IOException
-