The Artima Developer Community
Sponsored Link

Java Answers Forum
Security Manager file access for mail

5 replies on 1 page. Most recent reply: Sep 16, 2005 5:51 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Qaisar

Posts: 3
Nickname: qiqbal
Registered: Sep, 2005

Security Manager file access for mail Posted: Sep 12, 2005 10:36 PM
Reply to this message Reply
Advertisement
I am using javax.mail API(1.2), bundled with the j2ee package, for an automated email generation of user registration,and getting the following exception

access denied (java.io.FilePermission /web/tomcat/work/hosting/www.myDomainName.com/_/loader/META-INF write)

The full stack trace is
java.security.AccessControlContext.checkPermission(AccessControlContext.java :264)
java.security.AccessController.checkPermission(AccessController.java:427)
java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
java.lang.Se curityManager.checkWrite(SecurityManager.java:962)
java.io.File.mkdir(File.java: 1119)
java.io.File.mkdirs(File.java:1148)
org.apache.catalina.loader.WebappClass Loader.findResourceInternal(WebappClassLoader.java:1811)
org.apache.catalina.loa der.WebappClassLoader.findResource(WebappClassLoader.java:920)
org.apache.catali na.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1138)
jav a.lang.Class.getResourceAsStream(Class.java:1998)
javax.mail.Session.loadProvide rs(Session.java:793)
javax.mail.Session.(Session.java:81)
javax.mail.Session.get Instance(Session.java:103)
website.Email.sendThanksToUser(Email.java:37)
blah
bl ah
blah

My site is designed using jsp
It uses a shared server instance (tomcat 5.0.27)
All other smtp configurations are fine, I 've tested them on my local server.
Some body Pls Help


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Security Manager file access for mail Posted: Sep 12, 2005 11:05 PM
Reply to this message Reply
We can always tell you what a particular Exception means,
better yet you can always check it on the Java/J2EE API
(javadoc) online. Hence just pasting a stacktrace and
noting that those are the exceptions you get is not really
helpful to either us or you. What would be helpful
is a code snippet of where your exception is thrown.

i.e. it gets thrown or caught after trying which block.

Believe me we don't want to see your exact code but
simple explanations or even pseudo-code would go a long
way. e.g:

try{
    //  here I try to create a Message
    //  as well as invoke the send method
    //  from a class in JavaMail- (keep in 
    //  mind I've never gone through the 
    //  JavaMail API so this is simply an 
    //  educated guess of what the pseudo 
    //  would look like)
}catch(AServerException se){
    System.out.println("Connection failed - or send failed");
    //  Once again AServerException is a fictitions
    //  class that handles one form of an exception.
    se.printStackTrace();
}catch(SendFailedExcpetion fe){
    System.out.println("Send Failed");
    fe.printStackTrace();
}

Something like this would be useful, I'm not saying you'd
get an answer, but you'd definitely have a better shot at
getting one. Most of us have been around Java for years
so even if we are not familiar with a particular API
e.g. JavaMail, we just might be able to point you in the
right direction.

Spike

Qaisar

Posts: 3
Nickname: qiqbal
Registered: Sep, 2005

Re: Security Manager file access for mail Posted: Sep 14, 2005 3:25 AM
Reply to this message Reply
Thanks buddy
here is the code snippet:

Properties props = new Properties();
props.put("mail.smtp.host", "my.smtp.server");
// Session mailSession = Session.getInstance(props, null);

the remarked line of code throws an exception which is caught by which raises a JSPException, thrown to the browser.

Pls help ASAP
Thnx

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Security Manager file access for mail Posted: Sep 14, 2005 4:24 AM
Reply to this message Reply
Session.getInstance(Properties, Authenticator);
// see JavaMail API
[/null]
No clearly if you pass in null when it is expecting
a properly set Authenticatory object, it will
definitely be throwing those Security Exceptions.
 
Try setting up a proper javax.mail.Authenticator and
pass it in accordingly.  E.g:
 
[java]
my_session = Session.getInstance(yourProperty, new Authenticator(){
      //  override the abstract methods or simply
      //  pass this one in by creating a class extension
});

Hope that helps and good luck.

Spike

Qaisar

Posts: 3
Nickname: qiqbal
Registered: Sep, 2005

Re: Security Manager file access for mail Posted: Sep 16, 2005 5:28 AM
Reply to this message Reply
thnx man!
But no use.

here is the modified code:

Session mailSession = Session.getInstance(props, new MailAuthenticator());


class MailAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("myid", "mypwd");
}
}

Still getting the same error
please help

thnx again
Qaisar

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Security Manager file access for mail Posted: Sep 16, 2005 5:51 AM
Reply to this message Reply
HEY!!!!

Format your damn code properly!!

Here's a little debugging trick. You know that your
code crashes on creation of Mail Session see where it
crashes (most likely when you instantiate MailAuthenticator)
Stick in some print statements.

System.out.println("Creating Mail Session");
Session mailSession = Session.getInstance(props, new
        new MailAuthenticator());
System.out.println("created mail Session");
 
class MailAuthenticator extends Authenticator
{
   public PasswordAuthentication
         getPasswordAuthentication() {
       System.out.println("Password Authentication");
       return new PasswordAuthentication("myid", "mypwd");
   }
}
[/java

Flat View: This topic has 5 replies on 1 page
Topic: applet source code Previous Topic   Next Topic Topic: equals doubt

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use