first draft

This commit is contained in:
Developer1 2024-07-24 15:58:27 +05:30
parent 259005ef4a
commit a47e96619e
1125 changed files with 68824 additions and 0 deletions

0
FOSSLicense.txt Normal file
View File

33
README.md Normal file
View File

@ -0,0 +1,33 @@
<div style="text-align: center;"><img alt="Seclore Server SDK" width="1412" src="resources/seclore-logo-banner.jpg">
<p align="center" >
<a href="<link to developer site>"> <img alt="Website" src="https://img.shields.io/badge/Developer_Docs-online-blue"></a>
</p>
</div>
# Seclore Server SDK Examples
Welcome to the Seclore Server SDK Examples repository! Here, you'll find a curated collection of example projects showcasing the robust capabilities of the [Seclore Software Development Kit](https://repo.seclore.com/public/-/packages/generic/seclore-java-sdk/4.4.16.0).
## Table of Contents
1. [About this Repo](#About)
2. [Examples](#Examples)
3. [Learning Resources](#Learning)
## About this Repo <a name="About"></a>
This repository serves as a comprehensive guide to leveraging the powerful Web Service APIs exposed by the Seclore Policy Server. It includes an official list of meticulously crafted SDK examples (see ["Examples"](#Examples)) tailored to empower developers in seamlessly integrating the SDK into their applications. Each example provides practical demonstrations of common service implementations and essential infrastructure patterns, ensuring a smooth integration experience with the Seclore Server SDK.
## Examples <a name="Examples"></a>
Refer the examples in Java language, fully supported by the Seclore Server SDK. Explore the intricacies of secure data management, access controls, and much more by visiting the following link: [Examples](https://repo.seclore.com/public/seclore-java-sdk/src/branch/initial-setup/examples)
## Learning Resources <a name="Learning"></a>
While this is an excellent learning resource for the SDK, there are other resources that can be referenced to assist with your learning/development process.
### Official Resources
- [Developer Guide](https://git-link-of-Seclore-Server-SDK-Java-Guide.pdf)
- [API Reference](http://seclore-sdk.secloredevops.com/4.4.16.0/)
- [Seclore Server SDK Package](https://repo.seclore.com/public/-/packages/generic/seclore-java-sdk/4.4.16.0)

0
config-files/log4j2.xml Normal file
View File

View File

@ -0,0 +1,24 @@
Protect With Hot Folder and Wrap Sample App
============================================
Deployment Steps:
------------------
1. make sure your policy server is running . This app requires java 8 or above to run so make
sure java 8 or above is installed.
2. go inside 'bin/Protect With Hot Folder and Wrap Sample App'
3. Configure the 'tenant config.xml' in 'config/'
a. Policy Server Details:
server : Server name on which Policy Server is running
port : Server Port on which Policy Server is running
app-name : Policy Server application name
b. fill hot folder details i.e id and passphrase
4. If you are using java 8 , put libs present inside 'doc/JCE Files/java8' into
'bin/Protect With Hot Folder and Wrap Sample App/lib'
5. click on run.bat to start sample app , follow instruction on terminal

View File

@ -0,0 +1,15 @@
log4j.category.WSCLIENT=debug, WSCLIENT
# If we want to change the Appender, we have to change
# UtilFunction.initializeLoggers() too, because it assumes that the appender
# is 'org.apache.log4j.RollingFileAppender' and changes path of the file by
# getting appender from this logger.
log4j.appender.WSCLIENT=com.seclore.fs.ws.client.logger.DailyZippedRollingFileAppender
# Path of the file should be relative to application ROOT
log4j.appender.WSCLIENT.File=logs/WSClient.log
log4j.appender.WSCLIENT.MaxFileSize=10MB
#log4j.appender.REQUEST_LOGGER.MaxBackupIndex=10
log4j.appender.WSCLIENT.DatePattern='_'yyyy-MM-dd
log4j.appender.WSCLIENT.layout=org.apache.log4j.PatternLayout
log4j.appender.WSCLIENT.layout.ConversionPattern=%d{MMM dd, yyyy HH:mm:ss.SSS} %F:%L%n%p: %m%n

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" >
<Properties>
<Property name="basePath">${ctx:applicationPath}/logs</Property>
</Properties>
<Loggers>
<Asynclogger name="WSCLIENT" level="info" additivity="false" >
<appender-ref ref="WSCLIENT_APPENDER" />
</Asynclogger>
</Loggers>
<Appenders>
<RollingRandomAccessFile name="WSCLIENT_APPENDER" fileName="${basePath}/WSClient.log" filePattern="${basePath}/WSClient_%d{yyyy-MM-dd}_%i.log.zip">
<PatternLayout>
<charset>UTF-8</charset>
<pattern>%d{MMM dd, yyyy HH:mm:ss.SSS} :%t %n%p: %m%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<DefaultRolloverStrategy fileIndex="nomax">
<!--
* Uncommenting the following code will enable deletion of log files of above name and
* which are older than 90 days(configurable only days accepted)
* Be careful! There is no way to recover files deleted this way.
-->
<!--
<Delete basePath="${basePath}" >
<IfFileName glob="PolicyServer_*.log.zip" />
<IfLastModified age="90d" />
</Delete>
-->
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
</Appenders>
</Configuration>

View File

@ -0,0 +1,7 @@
FileSecure Version is 4.4.7.0
Jul 19, 2021 12:12:16.897 :main
INFO: WSCLIENT logger is initialized
Jul 19, 2021 12:12:16.903 :main
INFO: <logentry><logmessage><requestid>-1</requestid><message>SDK Logger is initialized</message></logmessage></logentry>
Jul 19, 2021 12:12:16.904 :main
INFO: <logentry><logmessage><requestid>-1</requestid><message>FSHelperLibrary::initializeSuccessfully Initialized helper library.</message></logmessage></logentry>

View File

@ -0,0 +1,18 @@
@echo off
set "CURRENT_DIR=%cd%"
echo ---------------------------------------------------------
echo Seclore 'Protect with Hot Folder Wrap Sample App' Utility
echo ---------------------------------------------------------
echo.
rem if your want to run on a different jdk or java path is not configured uncomment below line
rem for example ,
rem set path="C:\Program Files\Java\jdk-11.0.1\bin";
java -version
echo.
REM uncomment below line to see the version of sample app i.e( remove REM mentioned below)
REM java -cp "./lib/sample-app.jar"; com.seclore.fs.protect.example.Version
java -cp "./lib/*"; com.seclore.fs.protect.example.main.SecloreMain
pause

View File

@ -0,0 +1,37 @@
FileSecure Interfaces integration source code reference.
FS Helper Initialization
------------------------
- At application startup initializing FSHelperlibrary and FSHelper
- Below classes are used for the same
- SecloreMain
- static block :-
InitializeWSClient.initializeHelperLibrary((FSHELPERLIBRARY_CONFIG_XML_PATH, ););
InitializeWSClient.initializeHelper(HELPER_INSTANCE_KEY, FSHELPER_RESOURCE_PATH, FSHELPER_CONFIG_XML_PATH, );
- InitializeWSClient
- initializeHelperLibrary( ... )
- initializeHelper( ... )
Main Class
------------
- com.seclore.fs.protect.example.main
- SecloreMain class
Note:
=====
while preparing xml string for request or response. please escape below spacial character for the string which will be written within xml tag.
"&" -> "&amp;"
"<" -> "&lt;"
">", -> "&gt;"
"\"" -> "&quot;"
"'" -> "&apos;";
Refer: com.seclore.fs.protect.example.util.XMLUtil class and
- escapeForXML () method
Example: sample xml is "<request><file-name>Sample Sales & purchase report.pdf</file-name><request>"
here "Sample Sales and purchase report" should be escaped.
Use: String fileName = XMLHelper.escapeForXML( "Sample Sales & purchase report" );
"<request><file-name>"+fileName+"</file-name><request>"

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/bc-fips-1.0.2.3.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.6.jar"/>
<classpathentry kind="lib" path="lib/fs-smaillibrary.jar"/>
<classpathentry kind="lib" path="lib/juniversalchardet-1.0.3.jar"/>
<classpathentry kind="lib" path="lib/xercesImpl-X.jar"/>
<classpathentry kind="lib" path="lib/log4j-api-2.17.1.jar"/>
<classpathentry kind="lib" path="lib/log4j-core-2.17.1.jar"/>
<classpathentry kind="lib" path="lib/disruptor-3.3.7.jar"/>
<classpathentry kind="lib" path="lib/fs-ws-client.jar"/>
<classpathentry kind="lib" path="lib/seclore-io-1.0.0.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Protect With Hot Folder and Wrap Sample App Code</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,15 @@
log4j.category.WSCLIENT=debug, WSCLIENT
# If we want to change the Appender, we have to change
# UtilFunction.initializeLoggers() too, because it assumes that the appender
# is 'org.apache.log4j.RollingFileAppender' and changes path of the file by
# getting appender from this logger.
log4j.appender.WSCLIENT=com.seclore.fs.ws.client.logger.DailyZippedRollingFileAppender
# Path of the file should be relative to application ROOT
log4j.appender.WSCLIENT.File=logs/WSClient.log
log4j.appender.WSCLIENT.MaxFileSize=10MB
#log4j.appender.REQUEST_LOGGER.MaxBackupIndex=10
log4j.appender.WSCLIENT.DatePattern='_'yyyy-MM-dd
log4j.appender.WSCLIENT.layout=org.apache.log4j.PatternLayout
log4j.appender.WSCLIENT.layout.ConversionPattern=%d{MMM dd, yyyy HH:mm:ss.SSS} %F:%L%n%p: %m%n

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" >
<Properties>
<Property name="basePath">${ctx:applicationPath}/logs</Property>
</Properties>
<Loggers>
<Asynclogger name="WSCLIENT" level="info" additivity="false" >
<appender-ref ref="WSCLIENT_APPENDER" />
</Asynclogger>
</Loggers>
<Appenders>
<RollingRandomAccessFile name="WSCLIENT_APPENDER" fileName="${basePath}/WSClient.log" filePattern="${basePath}/WSClient_%d{yyyy-MM-dd}_%i.log.zip">
<PatternLayout>
<charset>UTF-8</charset>
<pattern>%d{MMM dd, yyyy HH:mm:ss.SSS}: %t: %p: %m%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<DefaultRolloverStrategy fileIndex="nomax">
<!--
* Uncommenting the following code will enable deletion of log files of above name and
* which are older than 90 days(configurable only days accepted)
* Be careful! There is no way to recover files deleted this way.
-->
<!--
<Delete basePath="${basePath}" >
<IfFileName glob="PolicyServer_*.log.zip" />
<IfLastModified age="90d" />
</Delete>
-->
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
</Appenders>
</Configuration>

View File

@ -0,0 +1,23 @@
package com.seclore.fs.protect.example;
/**
* Represents the Sample App version.
*/
public class Version
{
/**
* The version of the Sample App.
*/
public static final String Version = "3.0.0.0";
/**
* Displays the version of the Sample App
*
* @param args
*/
public static void main(String[] args)
{
System.out.println("Sample App version : " + Version);
System.out.println("Copyright (c) 2008 Seclore Technology Pvt. Ltd.");
}
}

View File

@ -0,0 +1,238 @@
package com.seclore.fs.protect.example.core;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.mozilla.universalchardet.UniversalDetector;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import com.seclore.fs.helper.exception.FSHelperException;
import com.seclore.fs.helper.library.FSHelperLibrary;
public class InitializeWSClient
{
/**
* @param configPath
* Takes the application config file path as input
* @throws Exception
*/
public static void initializeHelperLibrary(String configPath) throws Exception
{
try
{
String configContentXMLString = getConfigFileContent(configPath);
// Initialize method takes WSClient config content not the config file path.
FSHelperLibrary.initialize(configContentXMLString);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* @param helperId
* Tenant Id
* @param helperResourcePath
* Resource Path for files of Seclore Policy Server. To be left empty here.
* @param helperConfigPath
* File path for 'tenant config.xml' file
* @throws Exception
* Code snippet won't run if any exception is thrown in this block
*/
public static void initializeHelper(String helperId, String helperResourcePath, String helperConfigPath) throws Exception
{
try
{
String configContentXMLString = getConfigFileContent( helperConfigPath );
// Initialize method takes WSClient config content not the config file path.
FSHelperLibrary.initializeHelper(helperId, helperResourcePath, configContentXMLString);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* This method reads an XML file and returns the content of the XML file in string format
* @param appPath
* XML file path
* @return File content in string format
* @throws Exception
*/
private static String getConfigFileContent( String appPath ) throws Exception
{
validateConfigFile( appPath );
InputStream inputStream = null;
try
{
String lstrEncoding = detectEncoding(appPath);
if( lstrEncoding == null || lstrEncoding.trim().isEmpty() )
{
lstrEncoding = "UTF-8";
}
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(false);
builderFactory.setValidating(false);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
inputStream = new FileInputStream(appPath);
InputSource lInputSource = new InputSource( inputStream );
lInputSource.setEncoding(lstrEncoding);
Document document = builder.parse( lInputSource );
TransformerFactory lTransFactory = TransformerFactory.newInstance();
Transformer lTrans = lTransFactory.newTransformer();
DOMSource lSource = new DOMSource(document);
StringWriter lStringWriter = new StringWriter();
lTrans.transform( lSource, new StreamResult( lStringWriter ) );
return lStringWriter.toString();
}
catch (Exception e)
{
System.out.println("*** Config file should be in UTF-16LE encoding ***");
e.printStackTrace();
System.exit(0);
}
finally
{
if(inputStream != null)
{
try{
inputStream.close();
}
catch(IOException ioException)
{
//ignore
}
}
}
return "";
}
/**
* Validates whether the file exists at the given location & has valid BOM format
* @param configFilePath
* @throws Exception
* @return The file object representing the configFilePath
*/
private static File validateConfigFile(String configFilePath) throws Exception
{
if ( configFilePath == null || configFilePath.trim().isEmpty() )
{
throw new Exception("Configuration File path is not provided.");
}
File file = new File(configFilePath);
if ( !file.exists() )
{
throw new Exception("Configuration File does not exist at '"+ file.getAbsolutePath() + "'");
}
if( !file.isFile() )
{
throw new Exception("'" + file.getAbsolutePath() + "' is not a file.");
}
// Length 3 is checked to make sure that enough bytes are available for
// BOM reading.
if (file.length() < 3)
{
throw new Exception("'" + file.getAbsolutePath() + "' is not a valid configuration file.");
}
return file;
}
/**
* Detect encoding format of file
* @param pConfigXmlPath
* File path whose encoding type is to be detected
* @return encoding format (eg: utf-8, utf-16)
*/
private static String detectEncoding(String configXmlPath)
{
FileInputStream fis = null;
try
{
fis = new FileInputStream(configXmlPath);
UniversalDetector detector = new UniversalDetector(null);
byte[] buffer = new byte[512];
int read;
while( (read = fis.read(buffer)) > 0 && !detector.isDone() )
{
detector.handleData(buffer, 0, read);
}
detector.dataEnd();
String encoding = detector.getDetectedCharset();
detector.reset();
return encoding;
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if ( fis != null)
{
try
{
fis.close();
} catch (IOException e)
{
// Igniore
}
}
}
return null;
}
/**
* Terminate the created session and reset the initialized Server SDK library.
*/
public static void terminateWSClient()
{
try
{
FSHelperLibrary.logInfo("Terminating FSHelper Library");
if(FSHelperLibrary.isTerminated() == false)
{
System.out.println("FSHelperLibrary.isTerminated(): " + FSHelperLibrary.isTerminated());
FSHelperLibrary.terminate();
}
}
catch (FSHelperException e)
{
FSHelperLibrary.logError(e.getMessage(), e);
}
}
}

View File

@ -0,0 +1,185 @@
package com.seclore.fs.protect.example.main;
import java.util.Scanner;
import com.seclore.fs.helper.core.ProtectedFile;
import com.seclore.fs.helper.enums.ProtectionType;
import com.seclore.fs.helper.exception.FSHelperException;
import com.seclore.fs.helper.library.FSHelper;
import com.seclore.fs.helper.library.FSHelperLibrary;
import com.seclore.fs.protect.example.core.InitializeWSClient;
public class SecloreMain
{
//# FS Helper library is multi-tenant. Use unique tenant identifier for each tenant
private static String tenantID = "Tenant-1";
//# This file contains information about the Application into which this code snippet is to be integrated.
private static final String appConfigXMLFilePath = "config/config.xml";
//# This file contains info for creating session with Seclore Policy Server and initializing Server SDK library
private static final String tenantConfigXMLFilePath = "config/tenant config.xml";
//# Used to take user input
private static Scanner scanner = null;
/**
* <p>This block initializes the Server SDK library and creates a session with Seclore Policy Server</p>
* @exception Code snippet won't run if any exception is thrown in this block.
*/
static
{
try
{
InitializeWSClient.initializeHelperLibrary(appConfigXMLFilePath);
InitializeWSClient.initializeHelper(tenantID, "", tenantConfigXMLFilePath);
scanner = new Scanner(System.in);
}
catch (Exception e)
{
e.printStackTrace();
System.exit(0);
}
}
//# Entry point to run this application
public static void main(String[] args)
{
try
{
String outputFilePath = protectAndWrapFile();
if( outputFilePath != null && !outputFilePath.trim().isEmpty() )
{
System.out.println("File '" + outputFilePath + "' is protected and wrapped successfully");
}
else
{
throw new Exception("Unexpected error");
}
}
catch(Exception exp)
{
exp.printStackTrace();
}
finally
{
if( scanner != null )
{
scanner.close();
}
InitializeWSClient.terminateWSClient();
}
}
/**
* Protect and wrap a file using Seclore SDK
* @return the absolute file path of protected file
* @throws Exception
*/
public static String protectAndWrapFile() throws Exception
{
System.out.println("Enter absolute path of the file to be protected and wrapped:");
String filePath = scanner.nextLine();
//# get the FSHelper object by specifying the tenantId.
//note: This tenant id should be same which was used during initialization of Seclore SDK
FSHelper tenantObj = FSHelperLibrary.getHelper(tenantID);
//# does basic validation checks to see if the file is supported by SDK and is not already protected
validateIfFileSupportsProtection(tenantObj, filePath);
//# used to change display name of file in activity log
String displayFileName = filePath;
//# get XML structure to protect with hot folder
String protectionDetails = getProtectDetailsXML();
//# show details about protector
String protectorDetails = "";
//# activity comments to be shown
String actvityComments = "Protected by using FS Helper Library's protectAndWrap method";
ProtectedFile protectedWrappedFile = tenantObj.protectAndWrap(null,
filePath,
displayFileName,
ProtectionType.PROTECT_WITH_HF,
protectionDetails,
protectorDetails,
actvityComments);
System.out.println("Protected File Id: " + protectedWrappedFile.getFileId());
return protectedWrappedFile.getFilePath();
}
/**
* Validates if the file supports Seclore protection
*
* @param tenantObj - FSHelper object created for the tenant.
* @param filePath - Absolute path of the file to be protected.
* @throws Exception
*/
private static void validateIfFileSupportsProtection(FSHelper tenantObj, String filePath)
throws FSHelperException, Exception
{
//check if file is already Seclore protected
if(tenantObj.isProtectedFile(filePath) || tenantObj.isHTMLWrapped(filePath) )
{
throw new Exception("File '"+filePath+"' is already protected");
}
//check if file extension is supported by Seclore FS Helper Library
if(tenantObj.isSupportedFile(filePath) == false && tenantObj.isBasicProtectionSupported(filePath) == false )
{
String fileExt = filePath.substring( filePath.lastIndexOf(".")+1 );
//note: if file is not of standard format and does not support basic protection then throw error
throw new Exception("File with extention '"+fileExt+"' is not supported by Seclore FS Helper Library");
}
//check if file extension is supported for HTML wrapping by Seclore FS Helper Library
if(tenantObj.isHTMLWrapSupported(filePath) == false)
{
//note: file is of standard format but not supported for HTML wrapping
throw new Exception("File '"+filePath+"' does not support HTML wrapping");
}
}
/**
* Forms the protection XML request string to be sent to PS.
*
* @return protection request XML structure
*/
public static String getProtectDetailsXML() throws Exception
{
System.out.println("Enter Hot Folder id:");
String HFid = scanner.nextLine();
String protectionDetailsXML = "<hot-folder><id>" + HFid + "</id></hot-folder>";
return protectionDetailsXML;
}
}

View File

@ -0,0 +1,23 @@
#!/bin/bash
set -e
# Set the project root directory
PROJECT_ROOT=$(dirname "$0")/..
# Clean all bin folders
rm -rf "$PROJECT_ROOT/Sample Code/bin/Protect With Hot Folder and Wrap Sample App/config"/*
rm -rf "$PROJECT_ROOT/Sample Code/bin/Protect With Hot Folder and Wrap Sample App/lib"/*
# Clear the src/bin dir containing compiled class files
rm -rf "$PROJECT_ROOT/Sample Code/src/Protect With Hot Folder and Wrap Sample App Code/bin"/*
#find and compile all java files
find "$PROJECT_ROOT/Sample Code/src/Protect With Hot Folder and Wrap Sample App Code/src" -name "*.java" -exec javac -d "$PROJECT_ROOT/Sample Code/src/Protect With Hot Folder and Wrap Sample App Code/bin" -cp "$PROJECT_ROOT/Sample Code/src/Protect With Hot Folder and Wrap Sample App Code/lib/*" {} +
# Package the compiled classes into a JAR file
jar cvf "$PROJECT_ROOT/Sample Code/bin/Protect With Hot Folder and Wrap Sample App/lib/sample-app.jar" -C "$PROJECT_ROOT/Sample Code/src/Protect With Hot Folder and Wrap Sample App Code/bin" .
# Copy all libs and config files to bin
cp -r "$PROJECT_ROOT/Sample Code/src/Protect With Hot Folder and Wrap Sample App Code/lib"/* "$PROJECT_ROOT/Sample Code/bin/Protect With Hot Folder and Wrap Sample App/lib"
cp -r "$PROJECT_ROOT/Sample Code/src/Protect With Hot Folder and Wrap Sample App Code/config"/* "$PROJECT_ROOT/Sample Code/bin/Protect With Hot Folder and Wrap Sample App/config"

View File

@ -0,0 +1,24 @@
Protect With Hot Folder and Wrap Sample App
============================================
Deployment Steps:
------------------
1. make sure your policy server is running . This app requires java 8 or above to run so make
sure java 8 or above is installed.
2. go inside 'bin/Protect With Hot Folder and Wrap Sample App'
3. Configure the 'tenant config.xml' in 'config/'
a. Policy Server Details:
server : Server name on which Policy Server is running
port : Server Port on which Policy Server is running
app-name : Policy Server application name
b. fill hot folder details i.e id and passphrase
4. If you are using java 8 , put libs present inside 'doc/JCE Files/java8' into
'bin/Protect With Hot Folder and Wrap Sample App/lib'
5. click on run.bat to start sample app , follow instruction on terminal

View File

@ -0,0 +1,15 @@
log4j.category.WSCLIENT=debug, WSCLIENT
# If we want to change the Appender, we have to change
# UtilFunction.initializeLoggers() too, because it assumes that the appender
# is 'org.apache.log4j.RollingFileAppender' and changes path of the file by
# getting appender from this logger.
log4j.appender.WSCLIENT=com.seclore.fs.ws.client.logger.DailyZippedRollingFileAppender
# Path of the file should be relative to application ROOT
log4j.appender.WSCLIENT.File=logs/WSClient.log
log4j.appender.WSCLIENT.MaxFileSize=10MB
#log4j.appender.REQUEST_LOGGER.MaxBackupIndex=10
log4j.appender.WSCLIENT.DatePattern='_'yyyy-MM-dd
log4j.appender.WSCLIENT.layout=org.apache.log4j.PatternLayout
log4j.appender.WSCLIENT.layout.ConversionPattern=%d{MMM dd, yyyy HH:mm:ss.SSS} %F:%L%n%p: %m%n

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" >
<Properties>
<Property name="basePath">${ctx:applicationPath}/logs</Property>
</Properties>
<Loggers>
<Asynclogger name="WSCLIENT" level="info" additivity="false" >
<appender-ref ref="WSCLIENT_APPENDER" />
</Asynclogger>
</Loggers>
<Appenders>
<RollingRandomAccessFile name="WSCLIENT_APPENDER" fileName="${basePath}/WSClient.log" filePattern="${basePath}/WSClient_%d{yyyy-MM-dd}_%i.log.zip">
<PatternLayout>
<charset>UTF-8</charset>
<pattern>%d{MMM dd, yyyy HH:mm:ss.SSS} :%t %n%p: %m%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<DefaultRolloverStrategy fileIndex="nomax">
<!--
* Uncommenting the following code will enable deletion of log files of above name and
* which are older than 90 days(configurable only days accepted)
* Be careful! There is no way to recover files deleted this way.
-->
<!--
<Delete basePath="${basePath}" >
<IfFileName glob="PolicyServer_*.log.zip" />
<IfLastModified age="90d" />
</Delete>
-->
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
</Appenders>
</Configuration>

View File

@ -0,0 +1,7 @@
FileSecure Version is 4.4.7.0
Jul 19, 2021 12:12:16.897 :main
INFO: WSCLIENT logger is initialized
Jul 19, 2021 12:12:16.903 :main
INFO: <logentry><logmessage><requestid>-1</requestid><message>SDK Logger is initialized</message></logmessage></logentry>
Jul 19, 2021 12:12:16.904 :main
INFO: <logentry><logmessage><requestid>-1</requestid><message>FSHelperLibrary::initializeSuccessfully Initialized helper library.</message></logmessage></logentry>

View File

@ -0,0 +1,18 @@
@echo off
set "CURRENT_DIR=%cd%"
echo ---------------------------------------------------------
echo Seclore 'Protect with Hot Folder Wrap Sample App' Utility
echo ---------------------------------------------------------
echo.
rem if your want to run on a different jdk or java path is not configured uncomment below line
rem for example ,
rem set path="C:\Program Files\Java\jdk-11.0.1\bin";
java -version
echo.
REM uncomment below line to see the version of sample app i.e( remove REM mentioned below)
REM java -cp "./lib/sample-app.jar"; com.seclore.fs.protect.example.Version
java -cp "./lib/*"; com.seclore.fs.protect.example.main.SecloreMain
pause

View File

@ -0,0 +1,37 @@
FileSecure Interfaces integration source code reference.
FS Helper Initialization
------------------------
- At application startup initializing FSHelperlibrary and FSHelper
- Below classes are used for the same
- SecloreMain
- static block :-
InitializeWSClient.initializeHelperLibrary((FSHELPERLIBRARY_CONFIG_XML_PATH, ););
InitializeWSClient.initializeHelper(HELPER_INSTANCE_KEY, FSHELPER_RESOURCE_PATH, FSHELPER_CONFIG_XML_PATH, );
- InitializeWSClient
- initializeHelperLibrary( ... )
- initializeHelper( ... )
Main Class
------------
- com.seclore.fs.protect.example.main
- SecloreMain class
Note:
=====
while preparing xml string for request or response. please escape below spacial character for the string which will be written within xml tag.
"&" -> "&amp;"
"<" -> "&lt;"
">", -> "&gt;"
"\"" -> "&quot;"
"'" -> "&apos;";
Refer: com.seclore.fs.protect.example.util.XMLUtil class and
- escapeForXML () method
Example: sample xml is "<request><file-name>Sample Sales & purchase report.pdf</file-name><request>"
here "Sample Sales and purchase report" should be escaped.
Use: String fileName = XMLHelper.escapeForXML( "Sample Sales & purchase report" );
"<request><file-name>"+fileName+"</file-name><request>"

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/bc-fips-1.0.2.3.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.6.jar"/>
<classpathentry kind="lib" path="lib/fs-smaillibrary.jar"/>
<classpathentry kind="lib" path="lib/juniversalchardet-1.0.3.jar"/>
<classpathentry kind="lib" path="lib/xercesImpl-X.jar"/>
<classpathentry kind="lib" path="lib/log4j-api-2.17.1.jar"/>
<classpathentry kind="lib" path="lib/log4j-core-2.17.1.jar"/>
<classpathentry kind="lib" path="lib/disruptor-3.3.7.jar"/>
<classpathentry kind="lib" path="lib/fs-ws-client.jar"/>
<classpathentry kind="lib" path="lib/seclore-io-1.0.0.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Protect With Hot Folder and Wrap Sample App Code</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,15 @@
log4j.category.WSCLIENT=debug, WSCLIENT
# If we want to change the Appender, we have to change
# UtilFunction.initializeLoggers() too, because it assumes that the appender
# is 'org.apache.log4j.RollingFileAppender' and changes path of the file by
# getting appender from this logger.
log4j.appender.WSCLIENT=com.seclore.fs.ws.client.logger.DailyZippedRollingFileAppender
# Path of the file should be relative to application ROOT
log4j.appender.WSCLIENT.File=logs/WSClient.log
log4j.appender.WSCLIENT.MaxFileSize=10MB
#log4j.appender.REQUEST_LOGGER.MaxBackupIndex=10
log4j.appender.WSCLIENT.DatePattern='_'yyyy-MM-dd
log4j.appender.WSCLIENT.layout=org.apache.log4j.PatternLayout
log4j.appender.WSCLIENT.layout.ConversionPattern=%d{MMM dd, yyyy HH:mm:ss.SSS} %F:%L%n%p: %m%n

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" >
<Properties>
<Property name="basePath">${ctx:applicationPath}/logs</Property>
</Properties>
<Loggers>
<Asynclogger name="WSCLIENT" level="info" additivity="false" >
<appender-ref ref="WSCLIENT_APPENDER" />
</Asynclogger>
</Loggers>
<Appenders>
<RollingRandomAccessFile name="WSCLIENT_APPENDER" fileName="${basePath}/WSClient.log" filePattern="${basePath}/WSClient_%d{yyyy-MM-dd}_%i.log.zip">
<PatternLayout>
<charset>UTF-8</charset>
<pattern>%d{MMM dd, yyyy HH:mm:ss.SSS}: %t: %p: %m%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<DefaultRolloverStrategy fileIndex="nomax">
<!--
* Uncommenting the following code will enable deletion of log files of above name and
* which are older than 90 days(configurable only days accepted)
* Be careful! There is no way to recover files deleted this way.
-->
<!--
<Delete basePath="${basePath}" >
<IfFileName glob="PolicyServer_*.log.zip" />
<IfLastModified age="90d" />
</Delete>
-->
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
</Appenders>
</Configuration>

View File

@ -0,0 +1,23 @@
package com.seclore.fs.protect.example;
/**
* Represents the Sample App version.
*/
public class Version
{
/**
* The version of the Sample App.
*/
public static final String Version = "3.0.0.0";
/**
* Displays the version of the Sample App
*
* @param args
*/
public static void main(String[] args)
{
System.out.println("Sample App version : " + Version);
System.out.println("Copyright (c) 2008 Seclore Technology Pvt. Ltd.");
}
}

View File

@ -0,0 +1,238 @@
package com.seclore.fs.protect.example.core;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.mozilla.universalchardet.UniversalDetector;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import com.seclore.fs.helper.exception.FSHelperException;
import com.seclore.fs.helper.library.FSHelperLibrary;
public class InitializeWSClient
{
/**
* @param configPath
* Takes the application config file path as input
* @throws Exception
*/
public static void initializeHelperLibrary(String configPath) throws Exception
{
try
{
String configContentXMLString = getConfigFileContent(configPath);
// Initialize method takes WSClient config content not the config file path.
FSHelperLibrary.initialize(configContentXMLString);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* @param helperId
* Tenant Id
* @param helperResourcePath
* Resource Path for files of Seclore Policy Server. To be left empty here.
* @param helperConfigPath
* File path for 'tenant config.xml' file
* @throws Exception
* Code snippet won't run if any exception is thrown in this block
*/
public static void initializeHelper(String helperId, String helperResourcePath, String helperConfigPath) throws Exception
{
try
{
String configContentXMLString = getConfigFileContent( helperConfigPath );
// Initialize method takes WSClient config content not the config file path.
FSHelperLibrary.initializeHelper(helperId, helperResourcePath, configContentXMLString);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* This method reads an XML file and returns the content of the XML file in string format
* @param appPath
* XML file path
* @return File content in string format
* @throws Exception
*/
private static String getConfigFileContent( String appPath ) throws Exception
{
validateConfigFile( appPath );
InputStream inputStream = null;
try
{
String lstrEncoding = detectEncoding(appPath);
if( lstrEncoding == null || lstrEncoding.trim().isEmpty() )
{
lstrEncoding = "UTF-8";
}
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(false);
builderFactory.setValidating(false);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
inputStream = new FileInputStream(appPath);
InputSource lInputSource = new InputSource( inputStream );
lInputSource.setEncoding(lstrEncoding);
Document document = builder.parse( lInputSource );
TransformerFactory lTransFactory = TransformerFactory.newInstance();
Transformer lTrans = lTransFactory.newTransformer();
DOMSource lSource = new DOMSource(document);
StringWriter lStringWriter = new StringWriter();
lTrans.transform( lSource, new StreamResult( lStringWriter ) );
return lStringWriter.toString();
}
catch (Exception e)
{
System.out.println("*** Config file should be in UTF-16LE encoding ***");
e.printStackTrace();
System.exit(0);
}
finally
{
if(inputStream != null)
{
try{
inputStream.close();
}
catch(IOException ioException)
{
//ignore
}
}
}
return "";
}
/**
* Validates whether the file exists at the given location & has valid BOM format
* @param configFilePath
* @throws Exception
* @return The file object representing the configFilePath
*/
private static File validateConfigFile(String configFilePath) throws Exception
{
if ( configFilePath == null || configFilePath.trim().isEmpty() )
{
throw new Exception("Configuration File path is not provided.");
}
File file = new File(configFilePath);
if ( !file.exists() )
{
throw new Exception("Configuration File does not exist at '"+ file.getAbsolutePath() + "'");
}
if( !file.isFile() )
{
throw new Exception("'" + file.getAbsolutePath() + "' is not a file.");
}
// Length 3 is checked to make sure that enough bytes are available for
// BOM reading.
if (file.length() < 3)
{
throw new Exception("'" + file.getAbsolutePath() + "' is not a valid configuration file.");
}
return file;
}
/**
* Detect encoding format of file
* @param pConfigXmlPath
* File path whose encoding type is to be detected
* @return encoding format (eg: utf-8, utf-16)
*/
private static String detectEncoding(String configXmlPath)
{
FileInputStream fis = null;
try
{
fis = new FileInputStream(configXmlPath);
UniversalDetector detector = new UniversalDetector(null);
byte[] buffer = new byte[512];
int read;
while( (read = fis.read(buffer)) > 0 && !detector.isDone() )
{
detector.handleData(buffer, 0, read);
}
detector.dataEnd();
String encoding = detector.getDetectedCharset();
detector.reset();
return encoding;
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if ( fis != null)
{
try
{
fis.close();
} catch (IOException e)
{
// Igniore
}
}
}
return null;
}
/**
* Terminate the created session and reset the initialized Server SDK library.
*/
public static void terminateWSClient()
{
try
{
FSHelperLibrary.logInfo("Terminating FSHelper Library");
if(FSHelperLibrary.isTerminated() == false)
{
System.out.println("FSHelperLibrary.isTerminated(): " + FSHelperLibrary.isTerminated());
FSHelperLibrary.terminate();
}
}
catch (FSHelperException e)
{
FSHelperLibrary.logError(e.getMessage(), e);
}
}
}

Some files were not shown because too many files have changed in this diff Show More