Writing File to a shared Drive

Which IIQ version are you inquiring about?

8.3

Share all details about your problem, including any error messages you may have received.

I have a rule that generates a report in form of txt. Is there a way I can have this rule export this file to a shared folder instead of exporting it internally?

@Aaronlobo11

One option you can use powershell to do that job. Like write file at same location then call powershell to move to shared location.

Use PowerShell to Copy Files to a Shared Drive - Scripting Blog [archived]

# Define the source file path
$sourceFile = "C:\Path\To\Your\File\abc.txt"

# Define the destination path on the shared drive
$destinationPath = "\\ServerName\SharedDriveName\DestinationFolder"

# Copy the file
Copy-Item -Path $sourceFile -Destination $destinationPath

You will get more ideas

You can use the Java APIs to just stream the output to the local file system which could be an NFS mount/share.

Can you please elaborate. I’m confused how I would do so. Right now I have it as
Util.writeFile(pathtofile + “.txt”, sb.toString());

That works, what is the issue?

When I enter the path has the shared drive, I get an error that the path cannot be found. Is there a specific way I need to specify the path?

you can use something like this:

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;

public class WriteFileToWindowsShare {
    public static void main(String[] args) {
        String user = "username";
        String pass = "password";
        String sharedFolder = "smb://windows-server/shared-folder/";
        String fileName = "example.txt";
        String fileContent = "Hello, this is a test file.";

        try {
            NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", user, pass);
            SmbFile smbFile = new SmbFile(sharedFolder + fileName, auth);
            SmbFileOutputStream smbFileOutputStream = new SmbFileOutputStream(smbFile);

            smbFileOutputStream.write(fileContent.getBytes());
            smbFileOutputStream.close();

            System.out.println("File written successfully to the Windows share.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Recently, Microsoft has deprecated NTLM authentication. However, it remains possible to utilize SMB2 or SMB3 protocols. In considering these alternatives, I consistently recommend the use of SMB3 for its enhanced security features.

Thanks,
Siva

To Siva’s point there are other ways to authenticate and the SailPoint libraries support those i.e. Kerberos.

1 Like

I just tried doing this via powershell and get the error that the constructor doesn’t exist:
An unexpected error occurred: java.lang.Exception: sailpoint.tools.GeneralException: BeanShell script error: bsh.EvalError: Sourced file: inline evaluation of: ``import sailpoint.object.Identity; import java.util.List; import java.util.A . . . ‘’ : Typed variable declaration : Constructor error: Can’t find constructor: sailpoint.connector.RPCService(java.lang.String, java.lang.String) in class: sailpoint.connector.RPCService

This is the rule I’m using to execute powershell scripts:

import sailpoint.object.Identity;
 
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import sailpoint.object.RpcRequest;
import sailpoint.object.RpcResponse;
import sailpoint.connector.RPCService;

// Let's suppose we've already run "Generate Local File Rule" or we know the path
String localFilePath = "C:\\temp\\generatedFile.txt";
String sharedFilePath = "\\\\Server\\Share\\generatedFile.txt";

// Prepare data for the IQService script
Map data = new HashMap();
data.put("postScript", "Powershell Rule");  // Ties to your <Rule name="Powershell Rule" ... />

// If you want to reference an application, as in your original code:
Application ad = context.getObjectByName(Application.class, "AD");
data.put("Application", ad.getAttributes());

// Build an AccountRequest
AccountRequest accountRequest = new AccountRequest();
accountRequest.setApplication("IIQ");
accountRequest.setOperation(AccountRequest.Operation.Modify);

// Add the localFilePath and sharedFilePath as new attributes
accountRequest.add(new AttributeRequest("localFilePath", ProvisioningPlan.Operation.Add, localFilePath));
accountRequest.add(new AttributeRequest("sharedFilePath", ProvisioningPlan.Operation.Add, sharedFilePath));

// Optionally keep the existing attribute for email, if needed:
accountRequest.add(new AttributeRequest("email", ProvisioningPlan.Operation.Add, "test@gmail.com"));

// Pass the accountRequest to IQService
data.put("Request", accountRequest);

// Example: Connect to your IQService
// (Make sure the host, port, TLS, etc. are correct for your environment)
RPCService service = new RPCService("iqServiceHost","iqServicePort",useTLS);
RpcRequest request = new RpcRequest("ScriptExecutor", "runAfterScript", data);
RpcResponse response = service.execute(request);

// Parse response
Map res = response.getResultAttributes();
if (res.getMessages() != null && res.getMessages().size() > 0){
    // For example, check if the first message is "Success!"
    if(res.getMessages().get(0).equals("Success!")){
        System.out.println("PowerShell script executed successfully.");
    }
}

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.