Mutual authentication with Spark Java


I am trying to achieve a mutually authenticated REST API server using spark-java and from the <a href="http://sparkjava.com/documentation.html#secure" rel="nofollow">documentation</a> I see:

secure(keystoreFilePath, keystorePassword, truststoreFilePath, truststorePassword);

... which looks like exactly what I need. However I am only able to do one way authentication of the server, the client certificate never seems to be verified against the truststore. I'm using version 2.1, any advise or pointers would be greatly appreciated.


It seems that Spark in version 2.6.0 has added what you need. Now, there is a second version of secure:

/** (...) * @param needsClientCert Whether to require client certificate to be supplied in * request (...) */ public synchronized Service secure(String keystoreFile, String keystorePassword, String truststoreFile, String truststorePassword, boolean needsClientCert)

It sets setNeedClientAuth(true) and setWantClientAuth(true) on the underlying Jetty webserver SslContextFactory object.


  • How can I view the https calls in Fiddler when using jaxws
  • How to configure JBOSS connectivity with Websphere SSL enabled MQ?
  • Java SSL handshake exception - “unable to find valid certification path”
  • How to set System Properties on run time Spring 3 MVC
  • Typescript compile on save not working in cordova .jsproject - 2015
  • Managing branches in subversion
  • How do completely disable signed assemblies?
  • Add-In Commands Ribbon shows in Excel Online but not in Excel for Windows
  • Android signing problem
  • Getting SerializeObject to use JsonProperty “name” defined inside interface
  • Asking SslStream to accept ONLY a certificate signed by a particular public key
  • Execute a piece of code from the data-section
  • Warning: ldap_start_tls() [function.ldap-start-tls]: Unable to start TLS: Server is unavailable
  • IIS7 Application Request Routing HTTPS
  • cURL for Windows can't make a secure connection to the Stack API
  • How to use HTTP Authentication with PHP and then run the entered data against a database?
  • Giving security priviliege to a scheduler in Java EE 6
  • node-postgres UTF password bug
  • SSLRead() return error -9806/15958)
  • Push Changes to Git not Functioning
  • Success handler not working after Symfony2 login
  • Java : Simple XML not parsing the xml. Gives Exception
  • Why is OpenID Connect considered mobile friendly compared to SAML
  • Slicing an SPA into several components and use AngularJS
  • sudo easy_install for SimpleITK not that easy
  • GeoTrust SSL certificate on Android not trusted
  • Problem with Django using Apache2 (mod_wsgi), Occassionally is “unable to import from module” for no
  • Python pandas melting data to multiple columns and coulmn names in another column
  • Facebook iOS SDK Not Calling Completion Handler
  • what makes a request a new request in asp.net C#
  • How to programatically 'login' a user based on 'remember me' cookie when using j
  • Suppressing passwd when calling sqlplus from shell script
  • Authentication in Play! and RestEasy
  • Spring Cloud Microservice Architecture Confusion
  • Transactional Create with Validation in ServiceStack Redis Client
  • Abort upload large uploads after reading headers
  • Handling un-mapped Rest path
  • PHP - How to update data to MySQL when click a radio button
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • How to recover from a Spring Social ExpiredAuthorizationException