Forum Stats

  • 3,828,084 Users
  • 2,260,861 Discussions
  • 7,897,472 Comments

Discussions

signed applet get access denied java.net.SocketPermision smtp.gmail.com

821042
821042 Member Posts: 11
edited Dec 4, 2010 10:20AM in Java Programming
Hi, i have a signed applet which send emails. It works fine on netbeans, but when i run it in browsers(ie,mozila,crome,opera) i get this error: java.security.AccessControlException access denied java.net.SocketPermission smtp.gmail.com

This is the code but i'm sure is not the problem:

//start code_____________________________________________________________________________
public class ABC {
public String to="";
public String file="";
static GMailAuthenticator auth=new GMailAuthenticator("myemail", "mypassword");
public ABC(String to_,String file_)
{
this.to=to_;
file=file_;
}

public boolean send()
{ boolean ok=true;

try {
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587"); // smtp port
Session session = Session.getInstance(props,auth );


MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]"));
msg.setSubject(file+" attachment");
msg.setRecipient(RecipientType.TO, new InternetAddress(to));

//add atleast simple body
MimeBodyPart body = new MimeBodyPart();
body.setText("on-xml " + file + " file saved attachment");

//do attachment
MimeBodyPart attachMent = new MimeBodyPart();
FileDataSource dataSource = new FileDataSource(new File(file));
attachMent.setDataHandler(new DataHandler(dataSource));
attachMent.setFileName(file);
attachMent.setDisposition(MimeBodyPart.ATTACHMENT);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(body);
multipart.addBodyPart(attachMent);
msg.setContent(multipart);
Transport.send(msg);
} catch (Exception ex)
{ok=false;JOptionPane.showMessageDialog(null, "Failed to send: "+ex.toString() , "Failed to send: "+ex.toString(), JOptionPane.INFORMATION_MESSAGE);}
return ok;
}

}

//end code______________________________________________________________________________

PS: i also signed mail.jar and activation.jar but make no difference :)
Thx
Tagged:

Best Answer

«1

Answers

  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    user13415120 wrote:
    Hi, i have a signed applet which send emails. It works fine on netbeans, but when i run it in browsers(ie,mozila,crome,opera) i get this error: java.security.AccessControlException access denied java.net.SocketPermission smtp.gmail.com
    That comes from the VM and not your code.

    So probably something wrong with your jar - like it isn't actually signed.
    Although, as only a guess, what happens if the firewall denies access to that server - what error would one see? (Again just guessing.)
  • baftos
    baftos Member Posts: 3,431
    edited Dec 3, 2010 4:54PM
    When you go to the page, do you get a prompt about the certificate?
    If not, it's not properly signed.
    Do you use javascript in the page? Do you call the applet from javascript?
    If yes, signing is not enough.

    The exception has nothing to do with firewalls. It would have been some IOException.

    Edit: Posting the exact exception stack trace would help.
    It might also be that some classes that are on the stack leading to the fatal call may still originate from unsigned jars.

    Edited by: baftos on Dec 3, 2010 4:53 PM
  • 821042
    821042 Member Posts: 11
    My applet and other jar (mail.jar) are signed because i get a prompt about the certificate and i can open,save file in my main project .
    I found and i tried this but with no hope,

    AccessController.doPrivileged(new PrivilegedAction()
    {
    public Object run()
    {
    try {
    Transport.send(msg);// THIS GENERATE MY EXCEPTION
    } catch (Exception ex) {
    JOptionPane.showMessageDialog(null, "0 Failed to send: "+ex.toString() , "0 Failed to send: "+ex.toString(), JOptionPane.INFORMATION_MESSAGE);
    }
    return null;
    }
    });
    PS: i will post the trace later because i don't have the time right now
    Thx for your answers
  • 821042
    821042 Member Posts: 11
    and i don't use javascript...:)
  • 821042
    821042 Member Posts: 11
    oki i'm back with the trace

    java.security.AccessControlException: access denied (java.net.SocketPermission smtp.gmail.com resolve)
    access denied (java.net.SocketPermission smtp.gmail.com resolve)
    TRACE________________________________________________________________________________________________________________________________________________
    CLASS METHOD STRING
    class: java.security.AccessControlContext method: checkPermission string: java.security.AccessControlContext.checkPermission(Unknown Source)
    class: java.security.AccessController method: checkPermission string: java.security.AccessController.checkPermission(Unknown Source)
    class: java.lang.SecurityManager method: checkPermission string: java.lang.SecurityManager.checkPermission(Unknown Source)
    class: java.lang.SecurityManager method: checkConnect string: java.lang.SecurityManager.checkConnect(Unknown Source)
    class: sun.plugin2.applet.Applet2SecurityManager method: checkConnect string: sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
    class: java.net.InetAddress method: getAllByName0 string: java.net.InetAddress.getAllByName0(Unknown Source)
    class: java.net.InetAddress method: getAllByName string: java.net.InetAddress.getAllByName(Unknown Source)
    class: java.net.InetAddress method: getAllByName string: java.net.InetAddress.getAllByName(Unknown Source)
    class: java.net.InetAddress method: getByName string: java.net.InetAddress.getByName(Unknown Source)
    class: javax.mail.URLName method: getHostAddress string: javax.mail.URLName.getHostAddress(URLName.java:473)
    class: javax.mail.URLName method: hashCode string: javax.mail.URLName.hashCode(URLName.java:449)
    class: java.util.Hashtable method: get string: java.util.Hashtable.get(Unknown Source)
    class: javax.mail.Session method: getPasswordAuthentication string: javax.mail.Session.getPasswordAuthentication(Session.java:811)
    class: javax.mail.Service method: connect string: javax.mail.Service.connect(Service.java:258)
    class: javax.mail.Service method: connect string: javax.mail.Service.connect(Service.java:156)
    class: javax.mail.Service method: connect string: javax.mail.Service.connect(Service.java:105)
    class: javax.mail.Transport method: send0 string: javax.mail.Transport.send0(Transport.java:168)
    class: javax.mail.Transport method: send string: javax.mail.Transport.send(Transport.java:98)
    class: A.ABC method: send string: A.ABC.send(ABC.java:83)
    class: A.onxml_1$1 method: actionPerformed string: A.onxml_1$1.actionPerformed(onxml_1.java:329)
    class: javax.swing.AbstractButton method: fireActionPerformed string: javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    class: javax.swing.AbstractButton$Handler method: actionPerformed string: javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    class: javax.swing.DefaultButtonModel method: fireActionPerformed string: javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    class: javax.swing.DefaultButtonModel method: setPressed string: javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    class: javax.swing.plaf.basic.BasicButtonListener method: mouseReleased string: javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    class: java.awt.AWTEventMulticaster method: mouseReleased string: java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    class: java.awt.Component method: processMouseEvent string: java.awt.Component.processMouseEvent(Unknown Source)
    class: javax.swing.JComponent method: processMouseEvent string: javax.swing.JComponent.processMouseEvent(Unknown Source)
    class: java.awt.Component method: processEvent string: java.awt.Component.processEvent(Unknown Source)
    class: java.awt.Container method: processEvent string: java.awt.Container.processEvent(Unknown Source)
    class: java.awt.Component method: dispatchEventImpl string: java.awt.Component.dispatchEventImpl(Unknown Source)
    class: java.awt.Container method: dispatchEventImpl string: java.awt.Container.dispatchEventImpl(Unknown Source)
    class: java.awt.Component method: dispatchEvent string: java.awt.Component.dispatchEvent(Unknown Source)
    class: java.awt.LightweightDispatcher method: retargetMouseEvent string: java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    class: java.awt.LightweightDispatcher method: processMouseEvent string: java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    class: java.awt.LightweightDispatcher method: dispatchEvent string: java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    class: java.awt.Container method: dispatchEventImpl string: java.awt.Container.dispatchEventImpl(Unknown Source)
    class: java.awt.Component method: dispatchEvent string: java.awt.Component.dispatchEvent(Unknown Source)
    class: java.awt.EventQueue method: dispatchEvent string: java.awt.EventQueue.dispatchEvent(Unknown Source)
    class: UndoCopy.U1 method: dispatchEvent string: UndoCopy.U1.dispatchEvent(U1.java:47)
    class: java.awt.EventDispatchThread method: pumpOneEventForFilters string: java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    class: java.awt.EventDispatchThread method: pumpEventsForFilter string: java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    class: java.awt.EventDispatchThread method: pumpEventsForHierarchy string: java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    class: java.awt.EventDispatchThread method: pumpEvents string: java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    class: java.awt.EventDispatchThread method: pumpEvents string: java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    class: java.awt.EventDispatchThread method: run string: java.awt.EventDispatchThread.run(Unknown Source)
  • baftos
    baftos Member Posts: 3,431
    I don't know:(
    All I can suggest is to check every line in the stack trace for classes that are not part of the JRE, like A.ABC, A.onxml_1$1 and make sure they originate from your signed jars and not from class files on your disk. By the way, how does the applet tag look like?
  • 821042
    821042 Member Posts: 11
    I checked that :)
    Tag look like this:
    <applet code="A/onxml_1.class" archive="GONXML.jar" align="absmiddle" width="100%" height="100%">
    <param name="java_arguments" value="-Xmx1024m"/>
    <?php echo'<PARAM name="a" '; echo 'value="'; echo $k; echo '"'; ?> />
    <?php echo'<PARAM name="email" '; echo 'value="'; echo $_COOKIE['email']; echo '"';?> />
    </applet>

    I searched on other forums and the problem is with security of java.net.InetAddress.getAllByName() , but i don't know what to do ...they suggest not to use javascript and sign all my jars which i've done...
    I will try without PARAM php code...
  • 821042
    821042 Member Posts: 11
    nope...same story without PARAM php code :(
    I don't know what to do with java.net.InetAddress.getAllByName security
  • baftos
    baftos Member Posts: 3,431
    <applet code="A/onxml_1.class" archive="GONXML.jar" align="absmiddle" width="100%" height="100%">
    Not that I can see any relation to your problem, but:
    <applet code="A.onxml_1" ....
  • 821042
    821042 Member Posts: 11
    If there was a problem with applet tag or with signed applet my main project(GONXML.jar) couldn't open, save, copy paste files on the client pc...but it can......so i don't know i'm stuck:)
This discussion has been closed.