Establishing Security Through the InitialContext

   

Establishing Security Through the InitialContext

Some naming service providers like LDAP might require a username and password for a client to connect to it and look up objects within the namespace. The manner in which you can do this is by setting the environment properties for an InitialContext .

Three primary environment properties are defined in the Context interface and help establish the level of security you want to use when interacting with JNDI. The three security- related environment properties are

  • java.naming.security.authentication

  • java.naming.security.principal

  • java.naming.security.credentials

The first property defines the level of security that you will use when creating the InitialContext . There are three basic types of security authentication that you can do through JNDI. The authentication environment property must be set before an InitialContext is created. The three types of authentication are

  • None

  • Simple

  • Strong

You set the authentication environment property just as you set any of the other environment properties. You can set the property in a resource file like other properties in a jndi.properties file like this:

 java.naming.security.authentication=simple 

or you can set it in your source code if you are passing in environment properties to the InitialContext constructor. To set the authentication property programmatically, you can do something like the following:

 properties.put( Context.SECURITY_AUTHENTICATION, "simple" ); 

This tells the JNDI service that you want to use the simple authentication protocol. With the simple and strong authentication, you must provide values for the java.naming. security.principal and java.naming.security.credentials properties. The principal is typically the username or login for the user and the credentials property normally represents the password for the user .

Note

If you don't provide an authentication property, the behavior is up to the JNDI service. Some will default the authentication to none and provide a login and password of "guest." Others will just ignore these values completely.


When using the strong authentication, you will normally have to provide a digital certificate to the JNDI service for a stronger form of authentication. Depending on the JNDI provider, you also might have to set the java.naming.security.protocol environment property when using the strong authentication. Some providers will automatically determine this value. An example of a security protocol is SSL . In most cases, simple will suffice and strong will not be necessary. However, it's up to your specific application requirements to determine what type of client authentication is needed.



Special Edition Using Enterprise JavaBeans 2.0
Special Edition Using Enterprise JavaBeans 2.0
ISBN: 0789725673
EAN: 2147483647
Year: 2000
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net