You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Remco Poortinga <Re...@telin.nl> on 2008/07/29 14:22:20 UTC

Password protected OBR?

Hello,

Not sure if this is already possible (or indeed wanted), but I couldn't
find anything on the web or the mail archives about this.

For a project I would like to configure a 'private' OBR (somewhat
against the federated idea of OBR I guess, but anyway). In other words:
username/password protected access. Https OBR are possible, but I have
no idea if there is an 'official' way (from Felix' point of view) for
specifying credentials for the specified OBR URLs.

Just to see whether it would work I created a test version where
username/password can be specified in a RFC1738 compliant way, e.g.
https://user:password@server:port/rest and added an Authenticator to the
bundlerepository bundle, which gets the username/password from the URL
if it is set (see
http://java.sun.com/javase/6/docs/api/java/net/URL.html#getUserInfo()).

This seems to work OK; would this be interesting for others as well?

Only changes:

Add the following line to
org.apache.felix.bundlerepository.Activator.start():

Authenticator.setDefault(new UrlEmbeddedCredentialsAuthenticator());

Add this UrlEmbeddedCredentialsAuthenticator to the same package:

/**
 * 
 */
package org.apache.felix.bundlerepository;

import java.net.Authenticator;
import java.net.PasswordAuthentication;

/**
 * @author Remco Poortinga
 *
 */
public class UrlEmbeddedCredentialsAuthenticator extends Authenticator {
	protected PasswordAuthentication getPasswordAuthentication() {
		// See if something is encoded in the URL
		String userInfo = getRequestingURL().getUserInfo();
		if ((userInfo != null) && (userInfo.indexOf(':') > 0)) {
			String userName = userInfo.substring(0,
userInfo.indexOf(':'));
			String password =
userInfo.substring(userInfo.indexOf(':')+1);
			return new PasswordAuthentication(userName,
password.toCharArray());
		}

		return null;
	}
}


Best regards,

Remco


Remco Poortinga - van Wijnen
Senior Application Engineer / Software Architect

Telematica Instituut
The Netherlands
www.telin.nl
------------------------------------
An expert is a person who avoids the small errors as he sweeps on to the
grand fallacy.
  -- Benjamin Stolberg