grant SQLPermission and permission to connect to the database in policy file java -


how grant sqlpermission codebase in java? trying connect database (mysql) using jdbc.

the helpful information found @ sqlpermission not clear enough.

do have grant socket permission along it?

policy file have used

  grant  {  permission java.net.socketpermission "*", "listen, connect, accept"; permission java.sql.sqlpermission "setlog"; permission java.sql.sqlpermission "callabort"; permission java.sql.sqlpermission "setsyncfactory"; permission java.sql.sqlpermission "setnetworktimeout";  }; 

statck trace:

exception in thread "abandoned connection cleanup thread" java.security.accesscontrolexception: access denied ("java.lang.runtimepermission" "setcontextclassloader") 

when add permission java.lang.runtimepermission "setcontextclassloader"; policy file there no exception connection , statement not created null.on debugging application jumps directly return flag;at end of try block after conn = drivermanager.getconnection(db_url,user,pass);

of course works when security manager not set or when allpermission granted.

public boolean validate(string name,string password)         {        connection conn = null;        statement stmt = null;        try{          system.out.println("retrieving data");           class.forname("com.mysql.jdbc.driver");           conn = drivermanager.getconnection(db_url,user,pass);           system.out.println("connection successful");           stmt = conn.createstatement();           string sql;           sql = "select * employees";           resultset rs = stmt.executequery(sql);           while(rs.next())           {               string username = rs.getstring("username");                   system.out.println(username+" "+name);              if(name.equals(username))              {             string pwd=rs.getstring("pass");                 system.out.println(pwd+" "+password);             if(pwd.equalsignorecase(password))             {              string position = rs.getstring("position");                  flag=true;                 map.put("username", username) ;                 map.put("password", pwd) ;                 map.put("position", position) ;                 system.out.println(map);                 system.out.println("user authenticated");             }             }             }            rs.close();           stmt.close();           conn.close();           return flag;        }catch(sqlexception se)        {            se.printstacktrace();                system.out.println(se.getmessage());           return flag;        }finally        {            try               {              if(stmt!=null)                 stmt.close();           }catch(sqlexception se2)           {                   se2.printstacktrace();                   system.out.println(se2.getmessage());           }           try               {              if(conn!=null)                 conn.close();           }               catch(sqlexception se)           {              se.printstacktrace();           }           return flag;        } 

ya indeed problem permission connect database.things work fine new policy file.

grant  {   permission java.net.socketpermission "*", "accept, connect, listen, resolve";  permission java.util.propertypermission "*", "read, write";  permission java.lang.runtimepermission "*";  }; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -