3

I am calling a jar file from CF. Inside CF I have created a java class object successfully. When I am going to call my function that time, it generates the following error:

java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:10648" "listen,resolve")

How can I overcome this exception? I have deployed our code in a CF 10 server. Here is my login.cfm file code:

<cfsetting requesttimeout="1000000"> 

<!---Setting phantomJS path start--->
<cfset phantompath = #ExpandPath("./")# & "phantomjs\phantomjs.exe">    
<cfoutput>#phantompath#</cfoutput>

<!---Setting phantomJS path ends--->
<cfset sessionCookies="">

<!---Script for setting JAR file and creating java class object--->
<cfscript>
    paths = arrayNew(1);
    paths[1] = expandPath("CFDevshop\lib\Counsel_Cookies_Phantom.jar");
    writeDump(paths);
    loader = createObject("component", "javaloader.JavaLoader").init(paths);
    writedump(loader);
    classObject = loader.create("counsel_cookies.Counsel_Cookies").init();
    writedump(classObject);

    try{
        sessiondata=classObject.getSessionCookies  ("XXX","XXX","https://paser.login.csologin/login.jsf","phantomjs.exe");
    } 
    catch(Any e) { 
        WriteOutput("<p>An Expression exception was thrown.</p>");
        WriteOutput("<p>#e.Message#</p>");
    }
    writedump(sessiondata);                 
</cfscript>

Here is my java code:

public String getSessionCookies(String user, String pass,String loginUrl,String phantomPath) {
         StringBuilder builder=new StringBuilder();        
    try{            

        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setJavascriptEnabled(true);// not really needed: JS enabled by default
        caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomPath);  
        driver = new PhantomJSDriver(caps);
        driver.get(loginUrl);
        System.out.println(driver.getTitle());
        driver.findElement(By.id("login:loginName")).sendKeys(user);
        driver.findElement(By.id("login:password")).sendKeys(pass);
        waitForJQueryProcessing(driver, 5);
        driver.findElement(By.xpath("/html/body/div[3]/div/div[1]/div[1]/div[15]/div[2]/form/div[2]/button[1]")).click();
        Thread.sleep(10000);

        Set<org.openqa.selenium.Cookie> allCookies=driver.manage().getCookies();
        builder.append(" : Thakre2");
        for ( org.openqa.selenium.Cookie loadedCookie : allCookies) {
            builder.append(String.format("%s->%s, ", loadedCookie.getName(),loadedCookie.getValue()));
                   //System.out.println(String.format("%s->%s, ", loadedCookie.getName(),loadedCookie.getValue()));
        }           

    } catch(Exception e){
        writeFile(e.toString(),logfilepath);
    }

    return builder.toString();
}

Please provide your suggestions. How can I resolve this exception?

Atul Thakre
  • 502
  • 3
  • 8
  • 24
  • Exactly what line is throwing the error? Please post the *complete* error message AND the full stack trace. Like I said [on your other thread](http://stackoverflow.com/questions/27561662/how-to-get-java-class-in-cf) it does not seem like you are posting the actual code generating the errors you have described... For example, your java method expects six (6), but your CF code is only passing in five (5), so you should be getting a "method not found error". Unless the error occurs *before* you call it. But we need to see your *actual* code and the full error to figure that out. – Leigh Dec 26 '14 at 18:18
  • .. and does the method above work when you tested it directly in java? – Leigh Dec 26 '14 at 18:45
  • @Leigh: yes above java code very well work in java. actully i have use phantomjs in java code.which execute phantomjs.exe from java code and return result to the CF file. – Atul Thakre Dec 27 '14 at 06:36
  • @leigh: when i have run this code form local system its work very well. but when i am put this code on CF 10 server it show the above Exception: java.security.AccessControlException: access denied (“java.net.SocketPermission” “localhost:10648” “listen,resolve”). – Atul Thakre Dec 27 '14 at 06:38
  • @leigh:i think it dosn't run the phantomjs.exe from server. but this exe run from local system very well. – Atul Thakre Dec 27 '14 at 06:40
  • Given you say the code works locally but not on the server, I think the issue is likely to be exactly what the error message says: permissions. Bear in mind CF doesn't run with YOUR permissions, it runs with the permissions of the local system account. – Adam Cameron Dec 27 '14 at 09:28
  • @adam: when Cf call java jar that its generate the error.inside java code we have to use phantomjs.exe.may be in server this exe not run proprerly that wahy it generate the error. – Atul Thakre Dec 27 '14 at 12:49
  • Huh? I can't make head or tail of what you said then. – Adam Cameron Dec 28 '14 at 00:07
  • 1
    You did not post the full error message and trace, so I can only guess. However, like Adam mentioned, it is probably permissions. Did you google the first line of the error message? It turns up a lot of references to [missing permissions in your `java.policy` file](http://stackoverflow.com/questions/4169717/why-does-my-applet-get-a-java-security-accesscontrolexception-access-denied-ja). See also JDK7 [Change in Default Socket Permissions](http://www.oracle.com/technetwork/java/javase/7u51-relnotes-2085002.html) and http://docs.oracle.com/javase/7/docs/technotes/guides/security/permissions.html – Leigh Dec 28 '14 at 01:21
  • .. because the variable names in your original post suggest you may already aware of policy files ie *`String policypath`* – Leigh Dec 29 '14 at 16:30

1 Answers1

0

I am guessing its a permission issue. Edit client.policy or server.policy to grant read write permissions.

More here

Tattu
  • 327
  • 1
  • 3
  • 15