Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cannot access protected url by java

Status
Not open for further replies.

shai104

Programmer
Joined
Apr 30, 2003
Messages
1
Location
IL
I try to access url like by browser i can access it,but by servlet i get :
java.security.AccessControlException: access denied (java.net.NetPermission
setDefaultAuthenticator)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.net.Authenticator.setDefault(Authenticator.java:83)
...
I use a following code:
public class MyServlet extends HttpServlet {

public void service(HttpServletRequest req, HttpServletResponse res) throws IOException{
String userName = "username";
String password = "password";
URL url=new URL(" Authenticator.setDefault (new MyAuthenticator (userName,password));

URLConnection uc=url.openConnection();
uc.setAllowUserInteraction(true);

InputStream fi = uc.getInputStream();

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top