Fetching user name (windows) from a java application - java

Problem:
I am logging into a virtual machine(RDC) using the below credentials:
The user is part of a domain group called as teldept
user:147852 pass:helloworld
when i try to get the user details from java application it gives me : 147852
but when i click on start menu at the top i can see my Name displayed.
How is this done? i want to access this name from java application
I use the below snippet:
System.getProperty("user.name");
Whatever the above snippet gives me is correct as aper oracle docs.
I am logging in with ID: 147852 and above snippet gives me 14852
but some how in windows this ID:147852 is mapped with my name so only in the start menu in XP i am getting my name displyed instead of 147852. we need to know how this mapping is done between the ID & Name . I am guessing it has something to do with Domain or some network logic which i am not good with .

The name shown on XP's start menu is not the logon name. It's Full Name Corresponding to the Logon Name. Not sure if your login is a local login or a domain login. If it's a local login, go to Admin Tools -> Computer Management -> Users and Groups -> Here against your username (147852), you will find a full name.
If your login is a domain login, you can similarly lookup your name in Active Directory - or search for it at other places.
This is very OS Specific and cannot be found by Java.
You will need to do this using JNI and Windows API - Calling GetUserNameEx or NetUserGetInfo depending on type of user.
If you just want to get your logon name (147852), calling com.sun.security.auth.module.NTSystem().getName is a better way than using System.getProperty("user.name")

From this SO question, you can use:
System.getProperty("user.name");
to return the currently logged in user. This will return the username string. I believe this is what you're asking for, but your question is rather unclear.

Related

How to get a user role

I have a project based on documentum, and after user login I'd like to know what's his role.
The reason is that there is a requirment for a menu-action to be enabled just for users who has the specific role.
Assume I have the username (being taken from the login page), how can I do this?
Do I have to put this data on session once the user logged in? I'd prefer to have a one line code that could be called from the client side (javascript) and on the fly doing the disabling of the menu action.
When you login at that service u can create a JSON which will have value of which all menus are enabled for the logged in user.Now when the screen loads with menus u can use this JSON data to hide/display or enable/disable the menu items.
Or else u can write a scriplet tag in the the disables attribute and in the scriplet tag you can call a class static method which returns true or false based in the user details sent.
You can use the following condition to determine the role of a user. I have provided it as a DQL, but you can use the logic to fit it in your code.
select group_name from dm_group where any i_all_users_names = "user_name"
Hope this helps.

ThriftSecurityException (user:root, code:BAD_CREDENTIALS)

When I try to connect to accumulo from a java client, it is failing. I am using the 'root' user but have changed the password. I debugged my code, it is in fact getting the correct user name and password, the same I one I use to log into the shell with.
I read on some other sites that I have to set 'trace.user' and 'trace.password' in my accumulo-site.xml file, so I did that and restarted accumulo. Unfortunately it did not change a thing.
When I try to connect from java, these are the important lines from the stack:
Caused by: org.apache.accumulo.core.client.AccumuloSecurityException: Error BAD_CREDENTIALS for user root - Username or Password is Invalid
Caused by: ThriftSecurityException(user:root, code:BAD_CREDENTIALS)
From my accumulo console, I see this:
08 15:44:06,0544 tserver:michael-GA-890GPA-UD3H 4
ERROR
ThriftSecurityException(user:root, code:BAD_CREDENTIALS)
When I look through my accumulo logs I just see the same exception and its stack getting printed every second that goes by.
I went looking through the accumulo manual and couldn't find anything that I'm missing. A google search and SO search also did not help me.
Would somebody please tell me what I'm doing wrong?
Depending on the version you're using, you may also have trace.token.property.password defined in accumulo-site.xml which is the replacement for trace.password. >=1.6.0 introduced the trace.token.property.password property. If both that property and trace.password are present in the configuration, trace.token.property.password will take precedence over trace.password.
Look at the $ACCUMULO_LOG_DIR/tracer_$hostname.debug.log file, you'll likely have numerous exceptions in there.
The "proper" way (read as: how you'd want to do it in a production environment) to configure the tracer is to create the 'trace' table as 'root', create a 'trace' user, and give the 'trace' user READ, WRITE and ALTER_TABLE permissions on the 'trace' table. Then, update trace.user and trace.token.property.password in accumulo-site.xml.
Not sure if you still want the solution or not, what helped me is changing the value of trace.token.property.password to the correct password, i.e., the value of instance.secret for the trace.user 'root' in accumulo-site.xml file.
Or you could open the acccumulo shell using the 'root' user and create a new user inside the shell and then update the values of both the trace user and it's current password.

Java EE : Prevent application URL hacking

I am working on an existing Web based application.
Now, I need to secure the application against what I think is called url hacking. For instance, if the customer with customerId 1 is logged in and viewing his profile, the following http get variable will be visible in the address field: customerId=1.
I need to prevent a customer from being able to set customerId=2 and see the profile of another customer.
The problem is that, the application is already in production and in good working condition, so the changes should be minimal with respect to this change.
How is this best achieved?
Any sugggestions/comments?
why do you give the id in the URL when the user should only be allowed to change his profile? I don't see any need for this. Rather get the current user from SecurityConext and display its profile on an URL without the id.
with the new information you gave in the comments I suggest sth. like this:
just check if the given orderid in the URL belongs to the current user.
You're saying you use "normal web based Application" so I assume Servlet/jsp based. In your servlet you would do something like this:
int orderId = Integer.parseInt(request.getParameter("orderId"));
String username = request.getUserPrincipal().getName();
/*now you need to check if username match with the username of the order e.g. by using hibernate to get the order by id and check its user and if not throw PermissionDeniedException or similiar*/
95% agree with Korgen's answer above.
5% - if you want to allow administrator access to edit user profiles using the same functionality just switch to UUID to identify edited user.

Twitter4j search by user name and user bio

I am using twitter4j library to access twitter api.
I can sucessfully retrieve information about user by user screen name (like #username) but I wonder is it possible to search by user display name (like 'Firstname Lastname')
Also is it possible to search within user description by some keyword, any advices are warmly appricated
Maybe you can get along with searchUsers.

Wicket request mapping

I am trying to map my requests in a special way to achieve a very simple purpose.
Say the root website is abc.com and has several users. Each user has a home page, admin page, requests page, etc.
Let us assume we have users user1 and user 2
I want the urls to be coded as:
abc.com/user1/admin
abc.com/user1/home
abc.com/user1/requests
So basically abc.com/user1/home is the home page for user 1 and abc.com/user1/admin is the the admin page for user 1.
I have tried using the request mapping in wicket using named parameters etc. I can encode my URL'S as abc.com/home/user1 but I can not get the encoding I desire.
Any help is welcome.
Thanks
Anant
I'm just starting with the version 1.5 of wicket but I think the new mapping system will resolve your point quite easily :
mountPage("{userCode}/home", UserHomePage.class);
mountPage("{userCode}/admin", UserAdminPage.class);
Then, in the page you just have to retrieve the page parameter to load your model.
String userCode = pageParameter.get("userCode").toString();

Categories

Resources