1

I have a Java application that I want to add a licencing system to. I have created a serial key system that will be used to validate the software before launch on a remote server.

What I really wish to do, is host a .jar or .zip file on the remote server and use a URL class loader to import the classes. I also need this transaction to be secure so that only products with the valid key can load the classes into RAM.

I am thinking this might be achievable with PHP and some rewrite rules on the server end. I however don't know how I would handle this from Java's end. I have made modular systems in the past using URL class loaders but have been unable to find a way to do this remotely.

Anybody able to explain and or give examples?

Michael
  • 41,989
  • 11
  • 82
  • 128
  • Just so I understand your requirements: the application is running on the client's machine and you want the classloader to remotely load the classes and only when the user is authorized? – Thomas Nov 29 '17 at 10:48
  • Adding an effective licensing system to a Java application is notoriously difficult. In the system you're suggesting, I could simply listen to web traffic to grab the JAR, then write a small app which mimics your class-loading client but skips all of the server validation. Write it as a web app next time - it's easier to control licensing. – Michael Nov 29 '17 at 10:49
  • Unfortunately this is expanded on from another platform, so I am unable to change the language. – Christopher Goluch Rusketh Nov 29 '17 at 10:59

1 Answers1

0

There is more than one question

What I really wish to do, is host a .jar or .zip file on the remote server and use a URL class loader to import the classes

That's is totally possible, take a look at this answer, just pasting ONE of many answers

File file = ...
URL url = file.toURI().toURL();

URLClassLoader classLoader = 
(URLClassLoader)ClassLoader.getSystemClassLoader();
Method method = 
 URLClassLoader.class.getDeclaredMethod("addURL", 
URL.class);
 method.setAccessible(true);
 method.invoke(classLoader, url);

Then just use classforname

Class.forName("ExampleClass").newInstance()

I also need this transaction to be secure so that only products with the valid key can load the classes into RAM

It depends of what technologies are you using, maybe better to create another question specific for that but in a generic answer just find or write a authentication system and you are okay, for example if you are using spring you can use Spring Security, a standard for authentication is OAUTH

deFreitas
  • 4,196
  • 2
  • 33
  • 43
  • Authentication will be done though LDAP (Active directory). So i'm guessing the File class used with the URL loader supports a full URL. File remoteJar = new File("http://Example.Domain.com/myfile.jar"); ? – Christopher Goluch Rusketh Nov 29 '17 at 13:08
  • I just tried that with local files eg `URL url = new File("/home/elvis/Downloads/jar/log4j-1.2.14.jar").toURI().toURL();` anyway as it is a URL class the ln I guess yes, anyway if it doesn't work you can just use some code to download it to a temp folder then load it in classloader – deFreitas Nov 29 '17 at 13:13