{"id":19645765,"url":"https://github.com/approov/quickstart-java-spring-token-check","last_synced_at":"2026-01-21T12:35:28.686Z","repository":{"id":96186238,"uuid":"184083966","full_name":"approov/quickstart-java-spring-token-check","owner":"approov","description":"An Appoov token integration example forJava with the Spring framework. Article: https://blog.approov.io/approov-integration-in-a-java-spring-stateless-api","archived":false,"fork":false,"pushed_at":"2026-01-15T09:49:56.000Z","size":3277,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-01-15T15:36:40.710Z","etag":null,"topics":["api","approov","approov-demo","approov-token","backend-service","java","java-api","java-apis","java-spring","java-spring-api","java-spring-boot","java-spring-framework","jwt","jwt-api","jwt-auth","jwt-token","jwt-tokens","jwt-validation"],"latest_commit_sha":null,"homepage":"https://approov.io","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/approov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-04-29T14:13:37.000Z","updated_at":"2025-08-19T14:24:15.000Z","dependencies_parsed_at":"2023-03-23T08:48:33.890Z","dependency_job_id":null,"html_url":"https://github.com/approov/quickstart-java-spring-token-check","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/approov/quickstart-java-spring-token-check","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-java-spring-token-check","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-java-spring-token-check/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-java-spring-token-check/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-java-spring-token-check/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/approov","download_url":"https://codeload.github.com/approov/quickstart-java-spring-token-check/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-java-spring-token-check/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28632848,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","approov","approov-demo","approov-token","backend-service","java","java-api","java-apis","java-spring","java-spring-api","java-spring-boot","java-spring-framework","jwt","jwt-api","jwt-auth","jwt-token","jwt-tokens","jwt-validation"],"created_at":"2024-11-11T14:35:10.561Z","updated_at":"2026-01-21T12:35:28.671Z","avatar_url":"https://github.com/approov.png","language":"Java","readme":"# Approov QuickStart - Java Spring Token Check\n\n[Approov](https://approov.io) is an API security solution used to verify that requests received by your backend services originate from trusted versions of your mobile apps.\n\nThis repo implements the Approov server-side request verification code with the Java Spring framework in a simple Hello API server, which performs the verification check before allowing valid traffic to be processed by the API endpoint.\n\nOriginally this repo was just to show the Approov token integration example on a Java Spring API as described in the article: [Approov Integration in a Java Spring API](https://approov.io/blog//approov-integration-in-a-python-flask-api), that you can still find at [/servers/shapes-api](/servers/shapes-api).\n\n\n## Approov Integration Quickstart\n\nThe quickstart was tested with the following Operating Systems:\n\n* Ubuntu 20.04\n* MacOS Big Sur\n* Windows 10 WSL2 - Ubuntu 20.04\n\nFirst, setup the [Approov CLI](https://approov.io/docs/latest/approov-installation/index.html#initializing-the-approov-cli).\n\nNow, register the API domain for which Approov will issues tokens:\n\n```bash\napproov api -add api.example.com\n```\n\n\u003e **NOTE:** By default a symmetric key (HS256) is used to sign the Approov token on a valid attestation of the mobile app for each API domain it's added with the Approov CLI, so that all APIs will share the same secret and the backend needs to take care to keep this secret secure.\n\u003e\n\u003e A more secure alternative is to use asymmetric keys (RS256 or others) that allows for a different keyset to be used on each API domain and for the Approov token to be verified with a public key that can only verify, but not sign, Approov tokens.\n\u003e\n\u003e To implement the asymmetric key you need to change from using the symmetric HS256 algorithm to an asymmetric algorithm, for example RS256, that requires you to first [add a new key](https://approov.io/docs/latest/approov-usage-documentation/#adding-a-new-key), and then specify it when [adding each API domain](https://approov.io/docs/latest/approov-usage-documentation/#keyset-key-api-addition). Please visit [Managing Key Sets](https://approov.io/docs/latest/approov-usage-documentation/#managing-key-sets) on the Approov documentation for more details.\n\nNext, enable your Approov `admin` role with:\n\n```bash\neval `approov role admin`\n````\n\nFor the Windows powershell:\n\n```bash\nset APPROOV_ROLE=admin:___YOUR_APPROOV_ACCOUNT_NAME_HERE___\n````\n\nNow, get your Approov Secret with the [Approov CLI](https://approov.io/docs/latest/approov-installation/index.html#initializing-the-approov-cli):\n\n```bash\napproov secret -get base64\n```\n\nNext, add the [Approov secret](https://approov.io/docs/latest/approov-usage-documentation/#account-secret-key-export) to your project `.env` file:\n\n```env\nAPPROOV_BASE64_SECRET=approov_base64_secret_here\n```\n\nNow, to check the Approov token you need to add the [jwtk/jjwt](https://github.com/jwtk/jjwt) package to your `build.gradle` dependencies:\n\n```gradle\ndependencies {\n\n    // omitted..\n\n    implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2'\n    runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2',\n        'io.jsonwebtoken:jjwt-jackson:0.11.2'\n}\n```\n\nNext, add the package `com.criticalblue.approov.jwt.authentication` to your current project by copying (from this repo) the entire [authentication](/servers/hello/src/approov-protected-server/token-check/src/main/java/com/criticalblue/approov/jwt/authentication) folder into your project.\n\n\nNow, use it from the class in your project that extends the `WebSecurityConfigurerAdapter`. For example:\n\n```java\npackage com.yourcompany.projectname;\n\nimport com.criticalblue.approov.jwt.authentication.*;\nimport org.springframework.core.annotation.Order;\nimport org.springframework.security.config.annotation.web.builders.WebSecurity;\nimport org.springframework.security.config.http.SessionCreationPolicy;\nimport org.springframework.web.cors.CorsConfiguration;\nimport org.springframework.web.cors.CorsConfigurationSource;\nimport org.springframework.web.cors.UrlBasedCorsConfigurationSource;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.http.HttpMethod;\nimport org.springframework.security.config.annotation.web.builders.HttpSecurity;\nimport org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;\nimport org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;\nimport java.util.Arrays;\n\n@Configuration\n@EnableWebSecurity\npublic class WebSecurityConfig extends WebSecurityConfigurerAdapter {\n\n    private static ApproovConfig approovConfig = ApproovConfig.getInstance();\n\n    @Bean\n    CorsConfigurationSource corsConfigurationSource() {\n        CorsConfiguration configuration = new CorsConfiguration();\n        configuration.setAllowedMethods(Arrays.asList(\"GET\"));\n        configuration.addAllowedHeader(\"Authorization\");\n        configuration.addAllowedHeader(\"Approov-Token\");\n        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();\n        source.registerCorsConfiguration(\"/**\", configuration);\n        return source;\n    }\n\n    @Override\n    public void configure(WebSecurity web) throws Exception {\n        web.ignoring().antMatchers(\"/error\");\n    }\n\n    @Configuration\n    // @IMPORTANT Approov token check must be at Order 1. Any other type of\n    //            Authentication (User, API Key, etc.) for the request should go\n    //            after with @Order(2)\n    @Order(1)\n    public static class ApproovWebSecurityConfig extends WebSecurityConfigurerAdapter {\n\n        @Override\n        protected void configure(HttpSecurity http) throws Exception {\n\n            http.cors();\n\n            http\n                .httpBasic().disable()\n                .formLogin().disable()\n                .logout().disable()\n                .csrf().disable()\n                // @APPROOV The Approov Token check is triggered here.\n                .authenticationProvider(new ApproovAuthenticationProvider(approovConfig))\n                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);\n\n            http\n                .securityContext()\n                // @APPROOV The Approov Token check is configured here.\n                .securityContextRepository(new ApproovSecurityContextRepository(approovConfig))\n                .and()\n                    .exceptionHandling()\n                    // @APPROOV The Approov Token check is done here\n                    .authenticationEntryPoint(new ApproovAuthenticationEntryPoint())\n                .and()\n                    // @APPROOV This matcher will require the Approov token for\n                    // all API endpoints.\n                    .antMatcher(\"/\")\n                        .authorizeRequests()\n                        .antMatchers(HttpMethod.GET, \"/**\").authenticated();\n        }\n    }\n}\n```\n\n\u003e **NOTE:** When the Approov token validation fails we return a `401` with an empty body, because we don't want to give clues to an attacker about the reason the request failed, and you can go even further by returning a `400`.\n\nNot enough details in the bare bones quickstart? No worries, check the [detailed quickstarts](QUICKSTARTS.md) that contain a more comprehensive set of instructions, including how to test the Approov integration.\n\n\n## More Information\n\n* [Approov Overview](OVERVIEW.md)\n* [Detailed Quickstarts](QUICKSTARTS.md)\n* [Examples](EXAMPLES.md)\n* [Testing](TESTING.md)\n\n### System Clock\n\nIn order to correctly check for the expiration times of the Approov tokens is very important that the backend server is synchronizing automatically the system clock over the network with an authoritative time source. In Linux this is usually done with a NTP server.\n\n\n## Issues\n\nIf you find any issue while following our instructions then just report it [here](https://github.com/approov/quickstart-java-spring-token-check/issues), with the steps to reproduce it, and we will sort it out and/or guide you to the correct path.\n\n\n## Useful Links\n\nIf you wish to explore the Approov solution in more depth, then why not try one of the following links as a jumping off point:\n\n* [Approov Free Trial](https://approov.io/signup)(no credit card needed)\n* [Approov QuickStarts](https://approov.io/docs/latest/approov-integration-examples/)\n* [Approov Get Started](https://approov.io/product/demo)\n* [Approov Docs](https://approov.io/docs)\n* [Approov Blog](https://approov.io/blog/)\n* [Approov Resources](https://approov.io/resource/)\n* [Approov Customer Stories](https://approov.io/customer)\n* [Approov Support](https://approov.io/contact)\n* [About Us](https://approov.io/company)\n* [Contact Us](https://approov.io/contact)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapproov%2Fquickstart-java-spring-token-check","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapproov%2Fquickstart-java-spring-token-check","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapproov%2Fquickstart-java-spring-token-check/lists"}