How to Read a Clients Windows Login Name Using Ruby on Rails

is there a way to read a clients windows login name using ruby on rails

No, you will need to setup an authentication system within your rails application. Accessing the clients environment would be a huge security breach in a number of systems such as the browser. Depending on your requirements there are a number of nice plugins for rails to handle all of this authentication for you. I personally like devise. There are a few plugins for it and one that would authenticate with an LDAP server if you did not wish to store username/passwords and make users maintain a separate set of login credentials for your intranet application. This, however, is very common.

Ruby: Get currently logged in user on windows

Well, to get the current username, there's this:

puts ENV['USERNAME']

Or go to the Win32API.

require 'dl/win32'

def get_user_name
api = Win32API.new(
'advapi32.dll',
'GetUserName',
'PP',
'i'
)

buf = "\0" * 512
len = [512].pack('L')
api.call(buf,len)

buf[0..(len.unpack('L')[0])]
end

puts get_user_name

Edit: And I'm an idiot. This isn't what you asked for at all. Oh well, it took me time to dig this out of my code, so it might as well stay here for anyone else wondering :P

Edit again: OK, it turns out I'm not an idiot after all. This is what you want. When I went back and re-read your question, the HttpContext threw me off, and I thought it was the current username from HTTP auth or something.

How to specify a login_hint parameter

I got it working by setting the login_hint parameter using the additional_parameters hash which is available on Signet::OAuth2::Client.

Basically, doing the following:

client = Google::APIClient.new(application_name: 'test application', application_version: '0.0.1')
client.authorization.additional_parameters[:login_hint] = 'some_address@gmail.com'

If you get an error about additional_parameters not being defined then make sure you are using a recent version of the signet gem or use the latest from the master branch.

Single Sign-On Server Authentication in Ruby/Rack

I wrote a Rack::Auth module that implements NTLM SSO. It's maybe a little rough but it works for me. It does all that challenge/response stuff that's required for NTLM and sets REMOTE_USER to whatever the browser submitted.

Here's the code.

To make this work, the browser must be set up to send NTLM stuff to the server. In my environment this only happened when the server address was in the list of trusted domains. For Firefox, the domain has to be added to the list assigned to the key network.automatic-ntlm-auth.trusted-uris that can be accessed via about:config.

How to access the local machine's serial port data using a Heroku application

Rails is a web server technology that runs on a web server. It builds HTML pages that get sent to a client computer and are rendered by the browser.

When you run Rails locally you are mimicing a real web server - localhost is basically running a web server on your local machine. That is why you can cheat and use Ruby code in your Rails app that locally can access the port of your local machine, but once you run your Rails app on a real web server (like in Heroku) you cannot do this, so you have the wrong tool for the job you are trying to do.

Not only that but since Rails is a web technology you have a web application that runs inside the browser and you cannot easily access the port on a client machine from a web browser. More information on that is in "How to read serial port data from JavaScript".

The ONLY reason your Ruby code is able to access the port is because it is not running in the browser when you run on localhost but it is running inside the web server that gets fired up on localhost, so when the app runs on a real web server that Ruby code will try to access the port of the server not any client machine.

Native way to read smart card from browser without an applet

The only option to interact with a client device (like a smart card) using the browser is to use a separate container, such as Java applets, Flash, Silverlight or native browser extensions.

Java HttpClient and Devise Authentication Issues

Seeing as to what kind of request is working, I'd try this:

nameValuePairs.add(new BasicNameValuePair("authenticity_token", myToken));
nameValuePairs.add(new BasicNameValuePair("user[username]", username));
nameValuePairs.add(new BasicNameValuePair("user[password]", password));
nameValuePairs.add(new BasicNameValuePair("user[remember_me]", 0));
nameValuePairs.add(new BasicNameValuePair("commit", "Sign in"));

rails 3 admin edit another user

Change the 'reset password' link to the following:

<%= link_to "reset password", edit_user_path(user) %>

Change the correct_user method to the following:

def correct_user
@user = User.find(params[:id])
redirect_to root_url, notice: "You are not authorized to request this page" unless current_user.role == "admin" or current_user?(@user)
end

How to anonymously identify a user and store that information

Anonymous user identification can certainly be done (and is being done) with a fairly high degree of accuracy. Rather than reprint the methodology here's a bit of reading that will lay it all out.

First is an old bit by the EFF regarding the mathmatics of user privacy (specifically the entropy behind your data) on the internet. Certainly optional, but it expresses the model that we're looking at. You can skip this if the math behind identification doesn't interest you.

http://www.eff.org/deeplinks/2010/01/primer-information-theory-and-privacy

Basically taken in a nutshell: using just the browser-agent, IP address and other data published in one of their examples (panopticlick) http://panopticlick.eff.org/ you have a very high likelihood of uniquely identifying a user (as long as it is the same machine) without the need for cookies. Additional information regarding their research into browser detection and uniqueness is available here:

http://panopticlick.eff.org/browser-uniqueness.pdf

Visit the panopticlick page and give it a test. It will show you what to look for (and give examples and source of how to go about it) while the .pdf will detail the uniqueness and specifics of the fingerprinting method.

My system configuration, for example, is unique among the 1,301,578 total tested with 20.38 bits of identifying information (reduction of entropy). Given their research, you will have an accuracy of 94.2% and 99.1% in identifying users between visits without the use of any client side tracking.



Related Topics



Leave a reply



Submit