Monday, July 24, 2006

Subversion with Apache 2.2: incorrect mod_dav_svn.so

I was trying to set up subversion's latest binary on windows (version 1.3.2) with Apache's latest version on windows (version2.2) and just couldn't get the darn thing to work. It kept on saying that it couldn't load mod_dav_svn.so even after copying the .so files from the subversion zip file.
After much wasted effort, I found that the subversion binary (1.3.2) had the .so files compiled against apache 2.0 and not 2.2.
But don't worry! It's not necessary for you to compile these. Someone else was smart enough to do it and yes, kind enough to share it :). The correct binary files for the same are posted here:

http://www.nabble.com/Windows-binaries-of-mod_dav_svn.so-and-mod_authz_svn.so-for-apache-2.2-t1221958.html
http://rapidshare.de/files/14820216/svn130_apache22_mods.zip.html

I have verified that after putting these files in apache's modules directory, subversion works fine with Apache 2.2.

Apache 2.2 - Active Directory authentication

Using ldap_module for Apache to authenticate against an Active Directory Server



I recently configured our intranet site to use Active Directory for authentication/authorization. Though I found a number of conflicting mail threads, postings on the web, here's the configuration that worked for me. I was doing this with my Apache server on Windows 2003, however it would also apply to an apache installation on linux just as is.
First load the two apache modules required for ldap authentication:

LoadModule ldap_module modules/util_ldap.so
LoadModule auth_ldap_module modules/mod_auth_ldap.so


Now edit your httpd.conf file as follows.
Simply change the lines in bold according to your environment.


<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Satisfy all
AuthBasicProvider ldap
# This must be set to off for the ldap "require valid-user" directive to work.
AuthzLDAPAuthoritative off
# Do basic password authentication in the clear
AuthType Basic
# The name of the protected area or "realm"
AuthName "Secured Area"
# Active Directory requires an authenticating DN to access records
AuthLDAPBindDN "CN=Existing User,CN=users,DC=yourcompany,DC=com"
# This is the password for the AuthLDAPBindDN user in Active Directory
AuthLDAPBindPassword "yourPasswordInClearText"
# The LDAP query URL
AuthLDAPURL "ldap://myADServer:389/cn=Users,dc=myCompany,dc=com?sAMAccountName?sub?(objectClass=user)"
require valid-user
</Directory>

Friday, July 21, 2006

Java JNDI : Look up IP address by host name

NSLookup using pure Java?


So, is it even possible to do this in pure Java code?
That's the question I was struggling with for one of my recent projects.

If you googled for something like that, you came to the right place.

This is not a tutorial. So without much lecture, here's some sample code that works.


import java.util.Hashtable;

import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class IPLookup {

private static final String IP_ADDR_ATTR = "A";

private static final Log LOG = LogFactory.getLog(IPLookup.class);

private static Hashtable conf = new Hashtable();

public static final void init(String dnsServer, String domain) {
conf.put("java.naming.factory.initial",
"com.sun.jndi.dns.DnsContextFactory");
conf.put("java.naming.provider.url", "dns://" + dnsServer + "/"
+ domain);
}

public static final String lookupIPAddress(String dnsHostName) {
String ipAddress = null;

try {
DirContext ictx = new InitialDirContext(conf);
System.out.println("Created initial context. Looking up "
+ dnsHostName + "...");
Attributes attrs = ictx.getAttributes(dnsHostName,
new String[] { IP_ADDR_ATTR });
Attribute ipAddrAttr = attrs.get(IP_ADDR_ATTR);
if (ipAddrAttr != null) {
ipAddress = (String) ipAddrAttr.get();
}
} catch (NamingException ne) {
LOG.error("Failed to Lookup IP address for " + dnsHostName, ne);
}
return ipAddress;
}

}

This page is powered by Blogger. Isn't yours?