Windows logged user informations - java

I want to create an application in java that is monitoring logged users activities(create, delete, update folders/files).
The problem is that I didn't found how to get the OS of the logged user (java app is running on a windows server and users have windows on their machine, I want to know if there is a way to get the windows version of the logged users).
BRs,
Mihai

You would use JNI and call a native (windows-specific DLL) method to get the information. You would have to create this DLL yourself in (likely in C/C++)

System.getProperty("os.version")
If it's a web application you can use user-agent header. It can change easily, but worth to try. Check https://stackoverflow.com/a/1328393/5684110.

You're asking for a Windows-specific feature. I doubt Java would support that, so you will need a native module (written in C/C++ or something) to read that information and pass it into your Java application via JNI or a local socket connection. Maybe you could poll that data from Active Directory.
Another idea is, you could get the info through another Java app running on the client PC at startup. That way you would be able to monitor changes in the file system and some basic system properties like OS name and version (see Mustafa's answer). The app would be silently downloaded into the workstation and run automatically through Active Directory, sending the data to your server app via socket, web or a webservice.
Hope this helps you.

Related

WebDAV authentication through Java

I've made a program which copies files from phone to windows folder. Connection to phone via WebDAV server. The problem is that I cannot connect to phone through Java until I open for ex. htpp://192.168.1.40:8080 in my windows explorer. After that phone is visible in Java. But that ruins all the meaning of my program.
Does anyone knows how to get access to phone through Java in the first place? Do I need to change something in registry or?
Thanks a lot!
P.S. copying procedure goes by:
File src = new File("\\\\" + address + "\\DavWWWRoot\\DCIM\\Camera");
where address is "192.168.x.xx:8080"
and then it goes to Files.walkFileTree to copy all the files.
You have to use a WebDAV client if you do not want to rely on the OS. I suggest Apache Virtual Filesystem (VFS). It provides an additional layer over different types of filesystems and seems to have also support for WebDAV.
https://commons.apache.org/proper/commons-vfs/index.html
Well..I've made a bit different but most simplest way to solve my problem.
The whole problem was in this goddamn Windows OS. It has WebClient service on demand by default. I switched it to auto and now I can connect to phone (or any other WebDAV server) after reboot.
CMD code to switch to auto WebClient service:
sc config webclient start=auto
Run as Admin.
P.S. But I have to admit that my way (walkFileTree) to copy files from WebDAV server may be way far from the optimal.

How can I allow other computers to access my programm's database?

I have a java application that I programmed, and I also created a Wampserver database to store the app's data. When I install the application in another computer, it basically can't do anything because wampserver isn't installed on that computer, and even if it was, the database wouldn't be imported on that same computer.
Can I install the database with the program itself, without making a database server in my computer? (For security reasons)
Sorry if this is a dumb question, im new to programming.
Assuming you are doing this in a Home/office environment. Where your IP Addresses do not change so often. Or you have the power to assign them statically.
You could try using a multi-threaded client server model. Where your wampserver computer(server) will accept a connection from another computer(client), and from there any queries to the database will be handled by that thread. This way, you could get away without installing wampserver on every client.
It would require some networking codes to be added to your java program. There are many examples on multi-threaded client server model -> Multithreading with client server program
You can open your MySQL server to the outside world or to certain IP (comment or edit bind value in your MySQL configuration file).
This can be a security issue. What is your objective? Usually, you'd do an API allowing access to your data from your application.
You are talking about "hosting" your database. You need to either:
Create, develop, and run a hosting service (not trivial), or
Pay to one the myriad of hosting services available, and install your database there (cheap these days). Just a couple of well known examples: Digital Ocean or Amazon Web Services.
In any case, it's a huge security risk to open your database to any client online.
Normally you write a program/application that accesses the database in the same [local] network, and that application serves web pages (or other web service) to the world.

How to make a local test server for an android app?

I basically need to create a test server, something that I can use locally to perform tasks for my application.
So my android app is basically a search engine, however the search queries will be made on the server and the results then fetched from the server on the mobile device as JSON objects.
Is there any way to replicate this functionality locally? I would just like to set up a server, include the Spring framework, the Google Custom Search API and develop it all in Java, then ship it to a live server directly when it's finished. (Most presumably a free tier Amazon AWS server, either EC2 or Lambda, not sure what the difference is).
Not quite sure where or how to get started so any help is appreciated, thank you!
p.s. I may try dabbling in some machine learning at a later date, but I don't know if this will affect anything, this will most likely be after I've got a live server up and running.
EDIT: Sorry, so how would I fetch data from a local server from my mobile device? Do I need special software? Do I need to configure a local server? How can my mobile device fetch data from a second project when its being run on the first?
My app will fetch data from a server, so how can I create a dummy server, for it to fetch data from? Will I need to create a fully functioning online server, or can this just be done through creating a local server of some sort and then simply plugging my android device in and running the code? I have absolutely no idea how to test it without putting it online.
You can run a local installation of Tomcat server on your own machine.
Access the server by visiting "http://localhost:8080/" (or) http://127.0.0.1:8080". You can basically listening to your own local machine / host's 8080 port. Sometimes, it could be port 80 instead of 8080.
Please explore on how to host a Spring or Java application on a local server.
A good starting point would be to learn J2EE or Enterprise Java. You can configure Databases from your local installation.
If you opt for PHP as your language on server side, there is a pre-defined package called WAMP (for Windows), LAMP (for Linux), MAMP (for MAC) and XAMPP.
The above package are nothing but a package which contains a Server, Database and a Server side language usually PHP, if needed Python or Perl.
Please explain in which step you are getting issues so that anyone can help you exactly.

coldfusion.security.NTAuthentication: Error in locating groups for user XXX in domain XXX

I'm using coldfusion.security.NTAuthentication provided with ColdFusion to inteorrgate an active directory setup on a Windows SBS, with the intention of returning the groups a specific user belongs to.
On my development machine, this is working absolutely fine - however on the live machine I'm seeing the following error:
Error in locating groups for user XXX in domain XXX.
The two machines are quite different, but not in any way that I think should matter.
Here's the set up:
Dev machine
Windows 2008
ColdFusion 11 Developer edition
Java 8.0.25.18
Production machine
Windows 2008 R2
ColdFusion 10 Standard edition
Java 8.0.710.15
Active directory machine
Windows SBS 2011
It's worth noting that while these machines aren't identical, both are able to authenticate a user via the authenticateUser() method.
This suggests that the class is functioning and able to connect to the AD server without problems.
I'm also able to use <cfldap> to retrieve information about a user.
Here's some very simple code:
Local.ntauth = createObject("java", "coldfusion.security.NTAuthentication");
Local.ntauth.init('MyDomain');
Local.Authenticated = Local.ntauth.authenticateUser('Username', 'Password'); // Returns 'YES'
Local.Groups = Local.ntauth.GetUserGroups('Username') // Throws error
The issue isn't limited to the GetUserGroups method, a similar error occurs when attempting to use IsUserInGroup.
Can anyone help?
This turned out to be an issue with Windows permissions. (Isn't everything?)
So, something I neglected to mention in the question is that the production server had been secured using the techniques detailed in the CF10 Lockdown Guide.
Part of this procedure involves creating a dedicated user for the ColdFusion service.
It seems that the GetUserGroups function worked if I used the standard 'Local System' user, but not if I used my dedicated ColdFusion user.
With a bit of help from the Process Monitor, I noticed that when the GetUserGroups function is called, a call is made to the Active Directory server to /PIPE/Samr.
When ColdFusion is running with the Local System user, this call is made by NT AUTHORITY\SYSTEM and returns a whole bunch of information - however when ColdFusion is running as the new dedicated user account, the call is made by that account and returns LOGIN FAILED.
Presumably there must be a way of granting the ColdFusion user, which is Local to the server, access to the Active Directory in such a way that a GetUserGroups call is allowed.
I'm not sure how to achieve that, so for now have reverted back to the Local System user, but I may revisit this and update my answer.

How to execute a batch file on a remote system

I have a java web app running on a server. I will click a button on the UI on the server It should invoke the batch file on the client machine and execute it on the client. Please suggest me how to go on doing it?
If you're talking about a web app and it involves a browser as a client, then you cannot invoke a script on every client machine (I mean, you can do it in Windows, but not Linux).
Javascript is a client scripting language and runs in a sand-boxed environment often inside a web browser which prevents it from accessing resources on the computer.
Nevertheless in Windows, you probably could do this:
var cmdshell = WScript.CreateObject("WScript.Shell");
cmdshell.Run("the command to run a batch script goes here");
Check this for more details.
But in Linux, I haven't seen a way to do it since the environment is different altogether.

Categories

Resources