Hi, I want to give Clipboard access to an applet.
I edited <JAVA_HOME>\jre6\lib\security\java.policy
file to add:
grant codeBase "http://www.blahblah.net/*" {
permission java.awt.AWTPermission "accessClipboard";
};
It still throws java.security.AccessControlException.
when I add the permission to the global
grant {
}
area, it works. But for obvious security reasons
I want to limit the access to some domains.
Am I missing something? I also tried
grant codeBase "http://www.blahblah.net/"
and
grant codeBase "http://www.blahblah.net/-"
but nothing works... Any Ideas?
Thanks
BTW the applet is NOT signed.
Here a sample code for the problem:
Clippy.java
Test.htmlCode:import java.applet.*;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable;
import java.awt.Toolkit;
public class Clippy extends Applet implements ClipboardOwner
{
public void init()
{
}
public void stop()
{
}
public void paint(Graphics g)
{
}
public static String getCustomStackTrace(Throwable aThrowable) {
//add the class name and any message passed to constructor
final StringBuilder result = new StringBuilder( "EXCEPTION: " );
result.append(aThrowable.toString());
final String NEW_LINE = System.getProperty("line.separator");
result.append(NEW_LINE);
//add each element of the stack trace
for (StackTraceElement element : aThrowable.getStackTrace() ){
result.append( element );
result.append( NEW_LINE );
}
return result.toString();
}
public void copyToClipBoard(String content) {
Graphics g = getGraphics();
System.out.println("Copying!!");
try{
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection stringSelection = new StringSelection(content);
clipboard.setContents(stringSelection,this);
g.drawString("Copied!!!", 10, 10);
}
catch (Exception e)
{
g.drawString(getCustomStackTrace(e), 10, 10);
//e.printStackTrace();
System.out.println(getCustomStackTrace(e));
}
}
public void lostOwnership( Clipboard aClipboard, Transferable aContents) {
//do nothing
}
}
Code:<html>
<body>
<SCRIPT>
function getScreenDimension() {
}
</SCRIPT>
<FORM>
<INPUT type="button" value="call Java Applet method"
onClick = "document.clip.copyToClipBoard('dadada');">
</FORM>
<applet codebase="http://www.blahblah.net/" code=Clippy name="clip" id="Clippy" width=400 height=200 mayscript="true" scriptable="true">
<param name="scriptable" value="true" />
</applet>
</body>
</html>
