Comprehensive security guide for the Beas Rule Engine
The Beas Rule Engine implements multiple layers of security to protect sensitive data and ensure secure access to the system. This guide covers all security aspects including authentication, authorization, encryption, and best practices.
The system uses OAuth2 with JWT tokens for secure authentication. All API endpoints require valid JWT tokens in the Authorization header.
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: ${KEYCLOAK_AUTH_SERVER_URL}/realms/${KEYCLOAK_REALM}
jwk-set-uri: ${KEYCLOAK_AUTH_SERVER_URL}/realms/${KEYCLOAK_REALM}/protocol/openid-connect/certs
Always use HTTPS in production environments. Never transmit JWT tokens over unencrypted connections.
JWT tokens are validated for:
spring:
security:
oauth2:
resourceserver:
jwt:
claim-set-converter: org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter
claim-set-converter.claim-name: roles
claim-set-converter.authority-prefix: ROLE_
The system uses TripleDES encryption for sensitive data storage and transmission.
cryptography:
algorithm: DESede
transformation: DESede/CBC/PKCS5Padding
key: ${CRYPTO_KEY}
iv: ${CRYPTO_IV}
key-size: 168
@Service
public class Cryptography {
public String encrypt(String data) {
return cryptoState.encrypt(data);
}
public String decrypt(String encryptedData) {
return cryptoState.decrypt(encryptedData);
}
public boolean isEncrypted(String data) {
return cryptoState.isEncrypted(data);
}
}
Never hardcode encryption keys in source code. Always use environment variables or secure key management systems.
All input is validated and sanitized to prevent injection attacks and data corruption.
@Validated
@RestController
public class RuleEngine {
@PostMapping("/evaluate")
public ResponseEntity<RuleResponse> evaluateRule(
@Valid @RequestBody RuleRequest request,
@Pattern(regexp = "^[a-zA-Z0-9_-]+$") @RequestParam String ruleName
) {
// Implementation
}
}
public record RuleRequest(
@NotBlank @Size(max = 100) String ruleName,
@Valid Map<String, Object> parameters,
Object payload
) {}
Set these environment variables for secure configuration:
# 32-character encryption key
export CRYPTO_KEY="your-32-character-encryption-key-here"
# 16-character initialization vector
export CRYPTO_IV="your-16-char-iv"
# Keycloak server URL
export KEYCLOAK_AUTH_SERVER_URL="http://localhost:8080/auth"
# Keycloak realm
export KEYCLOAK_REALM="beasre"
# Client ID
export KEYCLOAK_RESOURCE="beas-rule-engine"
# JWT secret (if using symmetric signing)
export JWT_SECRET="your-jwt-secret-key"
# MongoDB credentials
export MONGODB_USERNAME="admin"
export MONGODB_PASSWORD="secure-password"
# Database name
export MONGODB_DATABASE="beasre"
Use strong, unique passwords and keys. Consider using a secrets management system in production.
Create an environment file for easy configuration management:
# Copy example file
cp env-example.sh .env
# Edit with your values
nano .env
# Source the environment variables
source .env
#!/bin/bash
# Cryptography Configuration
export CRYPTO_KEY="your-32-character-encryption-key-here"
export CRYPTO_IV="your-16-char-iv"
# Keycloak Configuration
export KEYCLOAK_AUTH_SERVER_URL="http://localhost:8080/auth"
export KEYCLOAK_REALM="beasre"
export KEYCLOAK_RESOURCE="beas-rule-engine"
# MongoDB Configuration
export MONGODB_HOST="localhost"
export MONGODB_PORT="27017"
export MONGODB_DATABASE="beasre"
export MONGODB_USERNAME="admin"
export MONGODB_PASSWORD="secure-password"
# Server Configuration
export SERVER_PORT="8070"
export SERVER_CONTEXT_PATH="/beasre"
□ Use HTTPS with valid SSL certificates
□ Configure proper firewall rules
□ Set up intrusion detection systems
□ Implement comprehensive logging
□ Use secrets management systems
□ Regular security audits
□ Backup encryption keys securely
□ Monitor for suspicious activities
□ Keep all systems updated
□ Implement proper access controls
logging:
level:
org.springframework.security: DEBUG
com.beassolution.rule.crypto: DEBUG
org.springframework.security.oauth2: DEBUG