RE: User Authentication
RE: User Authentication
- Subject: RE: User Authentication
- From: Karl Moskowski <email@hidden>
- Date: Tue, 31 May 2005 16:02:05 -0400
Andy,
I haven't done much with WebDAV in Java other than checking if a file
exists, so I can show or hide a hyperlink to the file on a WO
component. I use something like the snippet of code below.
Also, to do LDAP directory authentication, I use the LDAPUtilities
class below (adapted from Chuck & Sacha's excellent Practical
WebObjects book).
--Karl.
====
URL url = new URL(urlString);
String host = url.getHost();
String path = url.getPath();
int port = (url.getPort() == -1 ? 80 : url.getPort());
WOHTTPConnection connection = new WOHTTPConnection(host, port);
connection.setKeepAliveEnabled(false);
WORequest request = new WORequest("GET", path, "HTTP/1.1", null,
null, null);
if (!connection.sendRequest(request))
return false; // file doesn't exist
return true; // file exists
=====
import com.webobjects.foundation.*;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.*;
public class LDAPUtilities {
public static int SUCCESS = 0;
public static int FAILED_AUTHENTICATION = 1;
public static int FAILED_SERVER_CONNECTION = 2;
public static int FAILED_OTHER = 3;
public static int authenticateWithUserIdAndPassword(String
userId, String password) {
try {
Hashtable ldapEnvironment = ldapEnvironment();
ldapEnvironment.put(Context.SECURITY_PRINCIPAL, loginDN
(userId));
ldapEnvironment.put(Context.SECURITY_CREDENTIALS,
password);
try {
DirContext ctx = new InitialDirContext
(ldapEnvironment);
ctx.close();
} catch (javax.naming.AuthenticationException
authException) {
return FAILED_AUTHENTICATION;
} catch (NamingException e) {
if (e.getRootCause() instanceof
java.net.ConnectException)
return FAILED_SERVER_CONNECTION;
else
throw new NSForwardException(e);
}
} catch (Exception e) {
return FAILED_OTHER;
}
return SUCCESS;
}
protected static String loginDN(String userId) {
return "uid=" + userId + app().LDAP_BASE_DN;
}
protected static Hashtable ldapEnvironment() {
Hashtable ldapEnvironment = new Hashtable();
ldapEnvironment.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
ldapEnvironment.put(Context.PROVIDER_URL, app
().LDAP_URL); // variable in Application class
ldapEnvironment.put(Context.SECURITY_AUTHENTICATION,
"simple"); // assumes comm channel is secure
return ldapEnvironment;
}
}
On 31-May-05, at 3:37 PM, email@hidden wrote:
Message: 9
Date: Tue, 31 May 2005 09:50:24 -0700
From: Andy Beier <email@hidden>
Subject: RE: User Authentication
To: email@hidden, email@hidden
Message-ID:
<email@hidden>
Content-Type: text/plain; charset=us-ascii
Yes it can be done with WebObjects.
One option to access the LDAP is to use Java's JNDI:
http://java.sun.com/products/jndi/tutorial/ldap/
All you need to do is retrieve from LDAP the user's home folder
path and
open it using JavaIO. Keep in mind that if your user's folders are
on a
different machine then your app server you will need to network mount
them on the app machine.
Good Luck,
Andy
-----Original Message-----
From: webobjects-dev-bounces+abeier=email@hidden
[mailto:webobjects-dev-bounces+abeier=email@hidden] On
Behalf
Of email@hidden
Sent: Sunday, May 29, 2005 6:20 AM
To: email@hidden
Subject: User Authentication
I am trying to access my Mac OS X Tiger's LDAP server to authenticate
multiple users via sessions. When the user logs in I want the
WebObject
Application to access the user's home directory. Can this be done with
WebObjects or should I use JSP, PHP, Perl, any suggestion would be
greatly recommended. I also want them to be able to write to their
directories also, either via a WebObjects Application or by WebDAV.
Comments Appreciated...
Rick Langschultz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden