2

I am currently using interprolog - which is basically java with a prolog backend, allowing both java and prolog calls from each other respectively.

Now If i had say a frontend GUI coded in java swing, say a login dialog, which requested a username and password, instead of using java code to authenticate and store passwords, could I somehow use prolog to check the passwords instead? I've searched the term "access control prolog" and found nothing.

Sorry, i understand this question is a big vague and foggy but any help would be appreciated.

false
  • 10,264
  • 13
  • 101
  • 209
KP65
  • 13,315
  • 13
  • 45
  • 46

2 Answers2

1

You need to get an instance of a Prolog engine and execute any prolog command. I suppose you will have the prolog database set up in advance and you can create the prolog command that will evaluate to true when a username/password pair authenticates.

Calling this from Java is then easy. You obtain a Prolog Engine implementation say SWISubprocessEngine, and execute your prolog command with the command() method.

This article How can I make a Java program that calls Prolog ? will be most helpful.

Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192
  • I see, Thanks for the reply..In think database will I have a pair such as hasaccess(tom,123) //where tom is the user and 123 is the password? – KP65 Feb 09 '10 at 11:43
  • @keval That is a start yes. With a set of clauses like that you can quite simply query for a given username and password. – Vincent Ramdhanie Feb 09 '10 at 13:11
  • Thank you very much. I'm using XSBSubprocessEngine, say if my database : access.pl had: hasAccess(tom,123) how would i pass information from two string variables in java to pl to check the db? Im quite new to prolog, so im trying my hardest. thanks – KP65 Feb 09 '10 at 17:06
  • also how would you make java/prolog aware of where the database is? – KP65 Feb 09 '10 at 17:30
  • It depends. If you want to store the database in a traditional relational database then I would use Java to create the clauses and have the prolog engine initialized with the data at application startup. Otherwise you can use something like consultFromPackage(filename,MyClass.class) to load some prolog data from a file. So when the application starts the engine is told where to find the data that prolog will use. When you query from Java it uses the data from the file. – Vincent Ramdhanie Feb 09 '10 at 17:59
  • I see, thank you again. I would probably use the second approach. Does this look about right? XSBSubprocessEngine myEngine; myEngine.consultFromPackage("userlist.pl", LoginHandler.class); myEngine.deterministicGoal("hasAccess(user,pass)"); Having tried this, i seem to get null pointer exception on the second line – KP65 Feb 09 '10 at 18:16
  • It doesn't look as if you instantiated the engine. Try XSBSubprocessEngine myEngine = new XSBSubprocessEngine(); as the first line. – Vincent Ramdhanie Feb 09 '10 at 20:59
  • Hi Vincent, After trying that I seem to have a new error - although I'm not sure what it means? Exception in thread "AWT-EventQueue-0" com.declarativa.interprolog.util.IPException: Could not launch Prolog executable:java.io.IOException: Cannot run program "null\xsb": CreateProcess error=2, The system cannot find the file specified – KP65 Feb 09 '10 at 22:38
  • You may need to ensure that the file userlist.pl is right next to the .class file on the filesystem OR specify the fully qualified name of the file. For example: myEngine.consultFromPackage("c:\\temp\\userlist.pl", LoginHandler.class); I am not sure if that is the problem but it is worth a try. – Vincent Ramdhanie Feb 09 '10 at 23:32
  • Again it is much appreciated you assistance. I tried you suggestions, the userlist.pl is right in the same folder as the class files, and i also tried to specify the directory, but i have the same problem as my previous post above! thanks – KP65 Feb 09 '10 at 23:37
  • @keval I am out of ideas then. When I get a chance I will try out some of this code and see what I come up with. – Vincent Ramdhanie Feb 10 '10 at 01:32
  • Hi thanks, look forward to hearing from you. In the meantime I will keep trying and will let you know if I get anywhere! – KP65 Feb 10 '10 at 17:40
  • Hi vincent thought Id give you an update. The error was due to me not setting the run configuration arguments pointing to the XSB prolog directory executable, thats all fixed now, but i seem to get this error when i try to log in with tom and 123: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 and it specifies also this line is a problem : java.lang.StringIndexOutOfBoundsException: String index out of range: -1 oh well, a little bit closer eh?! – KP65 Feb 10 '10 at 22:26
0

Yes you can use that

gmhk
  • 15,598
  • 27
  • 89
  • 112