Commit 03308ed7 authored by anku.verma370@gmail.com's avatar anku.verma370@gmail.com
Browse files

Add Docker support and multi-Java version configuration

parent 9468a283
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+45 −0
Original line number Diff line number Diff line
# Certificate files (sensitive)
*.pfx
*.p12
*.jks
*.keystore

# Properties files (sensitive configuration)
*.properties
certificate.properties

# WAR files (built artifacts)
*.war

# Log files
*.log
logs/
*.out

# OS specific files
.DS_Store
Thumbs.db

# IDE specific files
.idea/
.vscode/
*.iml
*.swp
*.swo
*~

# Build directories
build/
target/
dist/
out/

# Docker volumes
docker-volumes/

# Temporary files
*.tmp
*.temp
temp/
tmp/

Dockerfile

0 → 100644
+99 −0
Original line number Diff line number Diff line
# DocSigner Application Dockerfile
# Build with: docker build --build-arg JAVA_VERSION=17 -t docsigner:java17 .
# Supported Java versions: 17, 21, or 24

# Declare build argument before FROM statement
ARG JAVA_VERSION=17

FROM eclipse-temurin:${JAVA_VERSION}-jdk

# Metadata labels
LABEL maintainer="Leegality"
LABEL description="Document Signer Application for eSign operations"
LABEL version="1.0.1"
LABEL java.version="${JAVA_VERSION}"
LABEL tomcat.version="11.0.10"

# Set environment variables
ENV TOMCAT_VERSION=11.0.10
ENV TOMCAT_HOME=/opt/tomcat
ENV CATALINA_HOME=/opt/tomcat
ENV PATH=$PATH:$TOMCAT_HOME/bin
ENV PROPERTY_FILE="/opt/tomcat/webapps/docsigner/certificate.properties"

# Install required packages and set up Tomcat with security enhancements
RUN apt-get update && apt-get install -y \
    wget curl \
    && rm -rf /var/lib/apt/lists/* \
    && wget https://archive.apache.org/dist/tomcat/tomcat-11/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz \
    && tar -xzf apache-tomcat-${TOMCAT_VERSION}.tar.gz \
    && mv apache-tomcat-${TOMCAT_VERSION} ${TOMCAT_HOME} \
    && rm apache-tomcat-${TOMCAT_VERSION}.tar.gz \
    && mkdir -p ${TOMCAT_HOME}/webapps \
    && mkdir -p ${TOMCAT_HOME}/certificates \
    && mkdir -p ${TOMCAT_HOME}/logs

# Copy the WAR file (ensure you're using the correct Java version WAR file)
COPY docsigner.war ${TOMCAT_HOME}/webapps/docsigner.war

# Copy certificate files
COPY certificate.pfx ${TOMCAT_HOME}/certificates/certificate.pfx
# To copy multiple certificates, uncomment the following lines
# COPY certificate2.pfx ${TOMCAT_HOME}/certificates/certificate2.pfx
# COPY certificate3.pfx ${TOMCAT_HOME}/certificates/certificate3.pfx
# COPY certificate4.pfx ${TOMCAT_HOME}/certificates/certificate4.pfx

COPY certificate.properties /opt/tomcat/webapps/docsigner/certificate.properties

# Extract WAR, configure permissions, cleanup, and security settings (consolidated to reduce layers)
RUN cd ${TOMCAT_HOME}/webapps && \
    mkdir -p docsigner && \
    cd docsigner && \
    jar -xf ../docsigner.war && \
    echo "WAR file extracted successfully" && \
    ls -la ${TOMCAT_HOME}/webapps/docsigner/ && \
    # Configure WAR file permissions
    chmod 755 ${TOMCAT_HOME}/webapps/docsigner.war && \
    chown -R root:root ${TOMCAT_HOME}/webapps/ && \
    chmod -R 755 ${TOMCAT_HOME}/webapps/ && \
    # Remove unnecessary default Tomcat webapps for security
    rm -rf ${TOMCAT_HOME}/webapps/ROOT ${TOMCAT_HOME}/webapps/docs ${TOMCAT_HOME}/webapps/examples ${TOMCAT_HOME}/webapps/host-manager ${TOMCAT_HOME}/webapps/manager && \
    # Enable auto-deploy and WAR unpacking
    sed -i 's/autoDeploy="false"/autoDeploy="true"/g' ${TOMCAT_HOME}/conf/server.xml && \
    sed -i 's/unpackWARs="false"/unpackWARs="true"/g' ${TOMCAT_HOME}/conf/server.xml && \
    # Security: Disable directory listing
    sed -i 's/<param-value>true<\/param-value>/<param-value>false<\/param-value>/g' ${TOMCAT_HOME}/conf/web.xml && \
    # Security: Set secure file permissions on configuration files
    chmod 600 ${TOMCAT_HOME}/conf/server.xml ${TOMCAT_HOME}/conf/web.xml && \
    chmod 700 ${TOMCAT_HOME}/conf ${TOMCAT_HOME}/logs ${TOMCAT_HOME}/work ${TOMCAT_HOME}/temp && \
    # Security: Create a non-root user for running Tomcat
    groupadd -r tomcat && \
    useradd -r -g tomcat -d ${TOMCAT_HOME} -s /bin/false tomcat && \
    # Set permissions for certificate.properties file
    chown tomcat:tomcat /opt/tomcat/webapps/docsigner/certificate.properties && \
    chmod 644 /opt/tomcat/webapps/docsigner/certificate.properties && \
    # Verify property file exists
    echo "Checking certificate.properties file: ${PROPERTY_FILE}" && \
    if [ ! -f "${PROPERTY_FILE}" ]; then \
        echo "ERROR: property file ${PROPERTY_FILE} not found!"; \
        exit 1; \
    fi && \
    echo "property ${PROPERTY_FILE} verified successfully" && \
    # Set final ownership for all Tomcat files
    chown -R tomcat:tomcat ${TOMCAT_HOME}

# Expose port 8080
EXPOSE 8080

# Health check to monitor application status
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:8080/docsigner/actuator/health || exit 1

# Set the working directory
WORKDIR ${TOMCAT_HOME}

# Switch to non-root user for security
USER tomcat

# Start Tomcat
CMD ["./bin/catalina.sh", "run"]
+171 −5
Original line number Diff line number Diff line
# Document Signer Utility

The Document Signer application is available for multiple Java versions: **Java 17**, **Java 21**, and **Java 24**. All versions follow the same setup steps, with the only difference being the Java version requirement.

## Supported Java Versions

- **Java 17** - Use `DocSigner-Java17/docsigner.war`
- **Java 21** - Use `DocSigner-Java21/docsigner.war`
- **Java 24** - Use `DocSigner-Java24/docsigner.war`

## Setup Instructions

1. Setup a Document Signer from the Settings Tab in your Leegality Dashboard, by entering your application URL. For example, if you are deploying your application at docsigner.example.com, please save the same in the URL Field. Alternatively, you can start by entering any demo URL and update the same later. 

2. On successful set, you will receive an eSign ID. 

3. Download *docsigner.war*.
3. Download the appropriate *docsigner.war* file based on your Java version:
   - For Java 17: Download from `DocSigner-Java17/docsigner.war`
   - For Java 21: Download from `DocSigner-Java21/docsigner.war`
   - For Java 24: Download from `DocSigner-Java24/docsigner.war`

4. Please ensure that Java is installed on your server. (Recommended version: Java 17.0.11)
4. Please ensure that the corresponding Java version is installed on your server (Java 17, Java 21, or Java 24)

5. Setup TOMCAT 10.1.23 or above on your server- Read [here](https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-10-on-ubuntu-20-04) to know how.
5. Setup TOMCAT 11 .1.23 or above on your server- Download [here](https://archive.apache.org/dist/tomcat/tomcat-11/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz).

6. After installing Tomcat, go to *webapps* directory and place the *docsigner.war* file in it. Please ensure that you do not change the name of the WAR file. 

@@ -32,9 +45,162 @@
    
10. Application will run at **/docsigner**. Please ensure that it does not conflict with any other application.

Now, whenever a signing request is received for your eSign ID, the document will be eSigned using your Document Signer Certificate.
11. Verify your certificate configuration by accessing:
    ```
    http://your-server-ip:8080/docsigner/sr/status?pathId=<eSign ID>
    ```
    Replace `<eSign ID>` with your actual eSign ID configured in certificate.properties.
    
    **Example:** If your eSign ID is `myesignid123`:
    ```
    http://localhost:8080/docsigner/sr/status?pathId=myesignid123
    ```
    
    This will return the certificate details including common name and expiry date if configured correctly.

---

## Docker Deployment

If you prefer to deploy using Docker, follow these steps:

### Prerequisites

1. Docker installed on your server
2. Your eSign ID from Leegality Dashboard
3. Your PKCS12 certificate file (.pfx format)

### Step 1: Prepare Required Files

Create a directory and place the following files in it:

1. **Dockerfile** - Available in the repository
2. **docsigner.war** - Copy the appropriate version:
   - For Java 17: Copy `DocSigner-Java17/docsigner.war`
   - For Java 21: Copy `DocSigner-Java21/docsigner.war`
   - For Java 24: Copy `DocSigner-Java24/docsigner.war`
3. **certificate.pfx** - Your PKCS12 certificate file
4. **certificate.properties** - Create this file with the following content:

```properties
# Enables request and response logging
doc.signer.logs.enabled=true

# PKCS12 keystore file path (use the path as shown below)
doc.signer.certificate.<eSign ID>.path=/opt/tomcat/certificates/certificate.pfx

# PKCS12 keystore password
doc.signer.certificate.<eSign ID>.password=<Your Certificate Password>
```

Replace `<eSign ID>` with your actual eSign ID from the Leegality Dashboard, and `<Your Certificate Password>` with your certificate password.

**Example:**
```properties
doc.signer.logs.enabled=true
doc.signer.certificate.myesignid123.path=/opt/tomcat/certificates/certificate.pfx
doc.signer.certificate.myesignid123.password=MySecurePassword123
```

### Step 2: Build Docker Image

Run the following command based on your desired Java version:

**For Java 17:**
```bash
docker build --build-arg JAVA_VERSION=17 -t docsigner:java17 .
```

**For Java 21:**
```bash
docker build --build-arg JAVA_VERSION=21 -t docsigner:java21 .
```

**For Java 24:**
```bash
docker build --build-arg JAVA_VERSION=24 -t docsigner:java24 .
```

You can further configure Automated Signing using Document Signer by creating a passkey for the same in your Leegality Dashboard. Pursuant to the same, users from your Organisational Department would be able to get documents eSigned using Document Signer Certificate either using our API Gateway or using the Leegality Dashboard.
### Step 3: Run Docker Container

Run the container using the following command:

**For Java 17:**
```bash
docker run -d -p 8080:8080 --name docsigner-app docsigner:java17
```

**For Java 21:**
```bash
docker run -d -p 8080:8080 --name docsigner-app docsigner:java21
```

**For Java 24:**
```bash
docker run -d -p 8080:8080 --name docsigner-app docsigner:java24
```

### Step 4: Verify Deployment

1. Check if the container is running:
   ```bash
   docker ps
   ```

2. View application logs:
   ```bash
   docker logs -f docsigner-app
   ```

3. Access the application at:
   ```
   http://your-server-ip:8080/docsigner
   ```

4. Check health status:
   ```
   http://your-server-ip:8080/docsigner/actuator/health
   ```

5. Verify certificate configuration:
   ```
   http://your-server-ip:8080/docsigner/sr/status?pathId=<eSign ID>
   ```
   Replace `<eSign ID>` with your actual eSign ID configured in certificate.properties.
   
   **Example:** If your eSign ID is `myesignid123`:
   ```
   http://localhost:8080/docsigner/sr/status?pathId=myesignid123
   ```
   
   This will return the certificate details including common name and expiry date if configured correctly.

### Managing the Container

**Stop the container:**
```bash
docker stop docsigner-app
```

**Start the container:**
```bash
docker start docsigner-app
```

**Restart the container:**
```bash
docker restart docsigner-app
```

**Remove the container:**
```bash
docker stop docsigner-app
docker rm docsigner-app
```

---

Now, whenever a signing request is received for your eSign ID, the document will be eSigned using your Document Signer Certificate.

**Logs:** All communication with your application is loggable and is enabled by default. You have option to disable the same but that is not recommended. The logs will be created in catalina.out file in TOMCAT logs Directory. You can also change the destination if you wish so. See this link for more details.
    

docsigner.war

deleted100644 → 0
−34.5 MiB

File deleted.