boolean isJenkinsServerSecuredWithCSRF ( String url ) throws BuildDriverException { try { JenkinsBuildDriverModuleConfig config = configuration . getModuleConfig ( new PncConfigProvider < JenkinsBuildDriverModuleConfig > ( JenkinsBuildDriverModuleConfig . class ) ) ; String username = config . getUsername ( ) ; String password = config . getPassword ( ) ; if ( url == null || username == null || password == null ) { throw new BuildDriverException ( "Missing config to instantiate " + JenkinsBuildDriver . DRIVER_ID + "." ) ; } try { JenkinsHttpClient jenkinsHttpClient = new JenkinsHttpClient ( new URI ( url ) , username , password ) ; try { jenkinsHttpClient . get ( "/crumbIssuer/api/xml" ) ; return true ; } catch ( IOException e ) { return false ; } } catch ( URISyntaxException e ) { throw new BuildDriverException ( "Cannot instantiate " + JenkinsBuildDriver . DRIVER_ID + ". Make sure you are using valid url: " + url , e ) ; } } catch ( ConfigurationParseException e ) { throw new BuildDriverException ( "Cannot read configuration for " + JenkinsBuildDriver . DRIVER_ID + "." , e ) ; } }
This checks if jenkins does not use option Prevent Cross Site Request Forgery exploits