# sonarsource-demos/demo-java-security architecture

> Architecture diagram of the GitHub repository sonarsource-demos/demo-java-security, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sonarsource-demos/demo-java-security
- Repository: https://github.com/sonarsource-demos/demo-java-security

## Overview

1. This repo is a single Maven-based Java web module, not a multi-service system. The runtime boundary is a servlet container serving JSPs from `src/main/webapp`, with Java classes under `src/main/java/demo/security`.

2. The application layer is split into servlet entry points: `HomeServlet`, `UserServlet`, `FileServlet`, `ScriptServlet`, and `Insecure`. These are the main request-handling units that receive HTTP traffic, interpret parameters, and route work to helpers or views.

3. `web.xml` is the deployment boundary that defines how the web app is wired in the container. It is the place where servlet mappings, startup behavior, and web-facing configuration would be applied.

4. The view layer is minimal and JSP-based: `index.jsp` and `user.jsp`. These pages are the UI/rendering endpoints, likely populated by servlet-provided request attributes rather than a separate frontend framework.

5. `Insecure.java` is the core demo artifact. The README says it intentionally contains vulnerabilities and security hotspots, and the project is designed to exercise SonarQube security rules, including custom source/sink/sanitizer definitions.

6. Security-related helper code is concentrated in `demo.security.util`. `DBUtils`, `WebUtils`, `Utils`, `SessionHeader`, `BrowserSearchUtility`, `RSAKeyGeneratorUtil`, and `AsymmetricEncryptionUtil` form the shared utility boundary used by the servlets and the security demo code.

7. The data flow is typical servlet-to-helper-to-view: request parameters enter a servlet, are passed through utility methods, and then either touch external systems such as the database or are rendered back into JSPs. The intentionally insecure flows in `Insecure` are there to demonstrate unsafe parameter propagation and sanitization gaps.

8. The repository includes explicit cryptography utilities, suggesting part of the demo covers key generation and asymmetric encryption behavior. `RSAKeyGeneratorUtil` and `AsymmetricEncryptionUtil` are separate from the web tier and can be tested independently.

9. There is a likely persistence boundary, but no dedicated DAO/module split. `DBUtils` and `credentials.properties` imply direct database access from the web/utility layer rather than a layered ORM architecture.

10. Testing focuses on utility behavior rather than end-to-end web flows. The test set includes `AsymmetricEncryptionUtilTest`, `RSAKeyGeneratorUtilTest`, `WebUtilsTest`, and a basic `AppTest`, which indicates the most important verification points are helper logic and security-related transformations.

11. Build and analysis tooling are part of the architecture because they drive the repo’s purpose. `pom.xml` defines the Maven build, `.github/workflows/maven.yml` and `buildspec.yml` provide CI integration, and `run.sh` re-runs the project through SonarQube with the custom security config `s3649JavaSqlInjectionConfig.json`.

12. Overall, the system boundary is a demo web app whose primary concern is security analysis rather than business functionality. The key architecture is: HTTP request -> servlet -> utility/DB/crypto helpers -> JSP response, with `Insecure.java` serving as the intentionally flawed code path for static-analysis training.

Main entry points: [`src/main/webapp/WEB-INF/web.xml`](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/webapp/WEB-INF/web.xml) (web.xml), [`src/main/java/demo/security/servlet/Insecure.java`](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/Insecure.java) (Insecure), [`src/main/java/demo/security/servlet/UserServlet.java`](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/UserServlet.java) (UserServlet), [`src/main/java/demo/security/util/WebUtils.java`](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/WebUtils.java) (WebUtils)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_web["Web tier"]
  node_node_home_servlet["HomeServlet<br/>servlet entry<br/>[HomeServlet.java]"]
  node_node_user_servlet["UserServlet<br/>servlet entry<br/>[UserServlet.java]"]
  node_node_file_servlet["FileServlet<br/>servlet entry<br/>[FileServlet.java]"]
  node_node_script_servlet["ScriptServlet<br/>servlet entry<br/>[ScriptServlet.java]"]
  node_node_insecure["Insecure<br/>vulnerable demo<br/>[Insecure.java]"]
  node_node_webxml["web.xml<br/>deployment config<br/>[web.xml]"]
  node_node_index_jsp["index.jsp<br/>jsp view<br/>[index.jsp]"]
  node_node_user_jsp["user.jsp<br/>jsp view<br/>[user.jsp]"]
end

subgraph group_group_util["Security utilities"]
  node_node_dbutils[("DBUtils<br/>db helper<br/>[DBUtils.java]")]
  node_node_webutils["WebUtils<br/>web helper<br/>[WebUtils.java]"]
  node_node_utils["Utils<br/>shared helper<br/>[Utils.java]"]
  node_node_sessionheader["SessionHeader<br/>session helper<br/>[SessionHeader.java]"]
  node_node_browsersearch["BrowserSearchUtility<br/>search helper"]
  node_node_rsa_keygen{{"RSAKeyGeneratorUtil<br/>crypto helper"}}
  node_node_asym_crypto{{"AsymmetricEncryptionUtil<br/>crypto helper"}}
end

subgraph group_group_test["Tests"]
  node_node_webutils_test["WebUtilsTest<br/>unit test<br/>[WebUtilsTest.java]"]
  node_node_rsa_test["RSAKeyGeneratorUtilTest<br/>unit test"]
  node_node_asym_test["AsymmetricEncryptionUtilTest<br/>unit test"]
  node_node_apptest["AppTest<br/>smoke test<br/>[AppTest.java]"]
end

subgraph group_group_build["Build and analysis"]
  node_node_pom["pom.xml<br/>maven build<br/>[pom.xml]"]
  node_node_ci["CI workflows<br/>ci config<br/>[maven.yml]"]
  node_node_buildspec["buildspec.yml<br/>ci config<br/>[buildspec.yml]"]
  node_node_runsh["run.sh<br/>analysis script<br/>[run.sh]"]
  node_node_s3649["s3649 config<br/>analysis config"]
end

node_node_webxml -->|"maps"| node_node_home_servlet
node_node_webxml -->|"maps"| node_node_user_servlet
node_node_webxml -->|"maps"| node_node_file_servlet
node_node_webxml -->|"maps"| node_node_script_servlet
node_node_webxml -->|"maps"| node_node_insecure
node_node_home_servlet -->|"uses"| node_node_webutils
node_node_home_servlet -->|"renders"| node_node_index_jsp
node_node_user_servlet -->|"uses"| node_node_webutils
node_node_user_servlet -->|"uses"| node_node_dbutils
node_node_user_servlet -->|"renders"| node_node_user_jsp
node_node_file_servlet -->|"uses"| node_node_utils
node_node_script_servlet -->|"uses"| node_node_browsersearch
node_node_script_servlet -->|"uses"| node_node_sessionheader
node_node_insecure -->|"uses"| node_node_dbutils
node_node_insecure -->|"uses"| node_node_webutils
node_node_insecure -->|"uses"| node_node_utils
node_node_insecure -->|"uses"| node_node_asym_crypto
node_node_rsa_keygen -->|"supports"| node_node_asym_crypto
node_node_webutils_test -.->|"tests"| node_node_webutils
node_node_rsa_test -.->|"tests"| node_node_rsa_keygen
node_node_asym_test -.->|"tests"| node_node_asym_crypto
node_node_apptest -.->|"runs under"| node_node_pom
node_node_ci -->|"builds"| node_node_pom
node_node_buildspec -->|"builds"| node_node_pom
node_node_runsh -->|"loads"| node_node_s3649
node_node_runsh -->|"runs"| node_node_pom

click node_node_home_servlet "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/HomeServlet.java"
click node_node_user_servlet "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/UserServlet.java"
click node_node_file_servlet "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/FileServlet.java"
click node_node_script_servlet "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/ScriptServlet.java"
click node_node_insecure "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/Insecure.java"
click node_node_webxml "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/webapp/WEB-INF/web.xml"
click node_node_index_jsp "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/webapp/index.jsp"
click node_node_user_jsp "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/webapp/user.jsp"
click node_node_dbutils "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/DBUtils.java"
click node_node_webutils "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/WebUtils.java"
click node_node_utils "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/Utils.java"
click node_node_sessionheader "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/SessionHeader.java"
click node_node_browsersearch "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/BrowserSearchUtility.java"
click node_node_rsa_keygen "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/RSAKeyGeneratorUtil.java"
click node_node_asym_crypto "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/AsymmetricEncryptionUtil.java"
click node_node_webutils_test "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/test/java/WebUtilsTest.java"
click node_node_rsa_test "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/test/java/RSAKeyGeneratorUtilTest.java"
click node_node_asym_test "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/test/java/AsymmetricEncryptionUtilTest.java"
click node_node_apptest "https://github.com/sonarsource-demos/demo-java-security/blob/main/src/test/java/AppTest.java"
click node_node_pom "https://github.com/sonarsource-demos/demo-java-security/blob/main/pom.xml"
click node_node_ci "https://github.com/sonarsource-demos/demo-java-security/blob/main/.github/workflows/maven.yml"
click node_node_buildspec "https://github.com/sonarsource-demos/demo-java-security/blob/main/buildspec.yml"
click node_node_runsh "https://github.com/sonarsource-demos/demo-java-security/blob/main/run.sh"
click node_node_s3649 "https://github.com/sonarsource-demos/demo-java-security/blob/main/s3649JavaSqlInjectionConfig.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_home_servlet,node_node_user_servlet,node_node_file_servlet,node_node_script_servlet,node_node_insecure,node_node_webxml,node_node_index_jsp,node_node_user_jsp toneBlue
class node_node_dbutils,node_node_webutils,node_node_utils,node_node_sessionheader,node_node_browsersearch,node_node_rsa_keygen,node_node_asym_crypto toneAmber
class node_node_webutils_test,node_node_rsa_test,node_node_asym_test,node_node_apptest toneMint
class node_node_pom,node_node_ci,node_node_buildspec,node_node_runsh,node_node_s3649 toneRose
```

## Components

### Web tier

Servlet entry points, JSP views, and deployment wiring.

- [HomeServlet](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/HomeServlet.java): servlet entry · Home request handler and route entry point. · `src/main/java/demo/security/servlet/HomeServlet.java`
- [UserServlet](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/UserServlet.java): servlet entry · User-facing request handler for profile or form flows. · `src/main/java/demo/security/servlet/UserServlet.java`
- [FileServlet](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/FileServlet.java): servlet entry · Request handler for file-oriented operations. · `src/main/java/demo/security/servlet/FileServlet.java`
- [ScriptServlet](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/ScriptServlet.java): servlet entry · Request handler for script-driven or demo flows. · `src/main/java/demo/security/servlet/ScriptServlet.java`
- [Insecure](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/servlet/Insecure.java): vulnerable demo · Intentionally flawed security-demo code path. · `src/main/java/demo/security/servlet/Insecure.java`
- [web.xml](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/webapp/WEB-INF/web.xml): deployment config · Container wiring, servlet mappings, and web deployment setup. · `src/main/webapp/WEB-INF/web.xml`
- [index.jsp](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/webapp/index.jsp): jsp view · Primary landing page rendered by the web tier. · `src/main/webapp/index.jsp`
- [user.jsp](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/webapp/user.jsp): jsp view · User-facing JSP rendered from servlet data. · `src/main/webapp/user.jsp`

### Security utilities

Shared helpers for validation, storage, session handling, and crypto.

- [DBUtils](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/DBUtils.java): db helper · Direct database access and persistence helper. · `src/main/java/demo/security/util/DBUtils.java`
- [WebUtils](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/WebUtils.java): web helper · Common web/parameter processing helper. · `src/main/java/demo/security/util/WebUtils.java`
- [Utils](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/Utils.java): shared helper · General-purpose utility methods used across the app. · `src/main/java/demo/security/util/Utils.java`
- [SessionHeader](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/SessionHeader.java): session helper · Session and header handling helper. · `src/main/java/demo/security/util/SessionHeader.java`
- [BrowserSearchUtility](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/BrowserSearchUtility.java): search helper · Browser or search-related helper logic. · `src/main/java/demo/security/util/BrowserSearchUtility.java`
- [RSAKeyGeneratorUtil](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/RSAKeyGeneratorUtil.java): crypto helper · RSA key generation utility. · `src/main/java/demo/security/util/RSAKeyGeneratorUtil.java`
- [AsymmetricEncryptionUtil](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/main/java/demo/security/util/AsymmetricEncryptionUtil.java): crypto helper · Asymmetric encryption and decryption utility. · `src/main/java/demo/security/util/AsymmetricEncryptionUtil.java`

### Tests

Focused unit tests for utility and crypto behavior.

- [WebUtilsTest](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/test/java/WebUtilsTest.java): unit test · Tests web utility behavior. · `src/test/java/WebUtilsTest.java`
- [RSAKeyGeneratorUtilTest](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/test/java/RSAKeyGeneratorUtilTest.java): unit test · Tests RSA key generation behavior. · `src/test/java/RSAKeyGeneratorUtilTest.java`
- [AsymmetricEncryptionUtilTest](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/test/java/AsymmetricEncryptionUtilTest.java): unit test · Tests asymmetric crypto behavior. · `src/test/java/AsymmetricEncryptionUtilTest.java`
- [AppTest](https://github.com/sonarsource-demos/demo-java-security/blob/main/src/test/java/AppTest.java): smoke test · Basic repository smoke test. · `src/test/java/AppTest.java`

### Build and analysis

Maven build, CI, and security-analysis configuration.

- [pom.xml](https://github.com/sonarsource-demos/demo-java-security/blob/main/pom.xml): maven build · Maven project definition and dependency/build setup. · `pom.xml`
- [CI workflows](https://github.com/sonarsource-demos/demo-java-security/blob/main/.github/workflows/maven.yml): ci config · GitHub Actions and buildspec automation for build and analysis. · `.github/workflows/maven.yml`
- [buildspec.yml](https://github.com/sonarsource-demos/demo-java-security/blob/main/buildspec.yml): ci config · Build pipeline definition for hosted CI. · `buildspec.yml`
- [run.sh](https://github.com/sonarsource-demos/demo-java-security/blob/main/run.sh): analysis script · Script to run the project through SonarQube analysis. · `run.sh`
- [s3649 config](https://github.com/sonarsource-demos/demo-java-security/blob/main/s3649JavaSqlInjectionConfig.json): analysis config · Custom security-source/sink configuration for analysis. · `s3649JavaSqlInjectionConfig.json`

## Connections

- web.xml → HomeServlet: maps · Deployment descriptor wires servlet entry points.
- web.xml → UserServlet: maps · Deployment descriptor wires servlet entry points.
- web.xml → FileServlet: maps · Deployment descriptor wires servlet entry points.
- web.xml → ScriptServlet: maps · Deployment descriptor wires servlet entry points.
- web.xml → Insecure: maps · Deployment descriptor wires servlet entry points.
- HomeServlet → WebUtils: uses · Servlet delegates request handling to web helpers.
- HomeServlet → index.jsp: renders · Servlet forwards to JSP view.
- UserServlet → WebUtils: uses · Servlet delegates request handling to web helpers.
- UserServlet → DBUtils: uses · User flow reaches persistence helper.
- UserServlet → user.jsp: renders · Servlet forwards to JSP view.
- FileServlet → Utils: uses · File flow relies on shared helpers.
- ScriptServlet → BrowserSearchUtility: uses · Script flow uses browser/search helper logic.
- ScriptServlet → SessionHeader: uses · Script flow touches session/header helper logic.
- Insecure → DBUtils: uses · Intentionally unsafe flow can reach persistence boundary.
- Insecure → WebUtils: uses · Intentionally unsafe parameter flow through web helpers.
- Insecure → Utils: uses · Demo vulnerability path exercises shared utilities.
- Insecure → AsymmetricEncryptionUtil: uses · Security demo may route into crypto helpers.
- RSAKeyGeneratorUtil → AsymmetricEncryptionUtil: supports · Key generation underpins asymmetric encryption workflows.
- WebUtilsTest → WebUtils: tests · Unit coverage for web utility behavior.
- RSAKeyGeneratorUtilTest → RSAKeyGeneratorUtil: tests · Unit coverage for key generation behavior.
- AsymmetricEncryptionUtilTest → AsymmetricEncryptionUtil: tests · Unit coverage for asymmetric encryption behavior.
- AppTest → pom.xml: runs under · Smoke test is part of the Maven project.
- CI workflows → pom.xml: builds · CI uses the Maven project definition.
- buildspec.yml → pom.xml: builds · Hosted CI uses the Maven project definition.
- run.sh → s3649 config: loads · Analysis script invokes custom security configuration.
- run.sh → pom.xml: runs · Script executes the Maven-based project analysis.
