Author: deepal
Date: Wed Jan 16 23:36:43 2008
New Revision: 12384
Log:
implemented Remote registry to work with Basic Authentication , so that when it
tries to get the resources it will send the credential.
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
Wed Jan 16 23:36:43 2008
@@ -875,12 +875,21 @@
private Registry getSecureRegistry(RequestContext request) throws
RegistryException {
String authorizationString = request.getAuthorization();
if (authorizationString != null) {
+ // spliting the Authorization string "Basic
QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
String values[] = authorizationString.split("\\ ");
- String userName = values[0];
- String password = values[1];
- // user name and password have found
- return new SecureRegistry(
- userName, password, jdbcregistry, realm);
+ if ("Basic".equals(values[0])) {
+ //decoding the username and passord
+ authorizationString = new String(Base64.decode(values[1]));
+ //spliting the decode sting to get the userName and the
password;
+ values= authorizationString.split("\\:");
+ String userName = values[0];
+ String password = values[1];
+ // user name and password have found
+ return new SecureRegistry(
+ userName, password, jdbcregistry, realm);
+ } else {
+ throw new RegistryException("Invalid Authorization string");
+ }
} else {
// seems like need to create a secure jdbcregistry with annon user
return new SecureRegistry(
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
Wed Jan 16 23:36:43 2008
@@ -26,6 +26,7 @@
import org.apache.abdera.protocol.client.RequestOptions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.util.Base64;
import org.wso2.registry.Comment;
import org.wso2.registry.*;
import org.wso2.registry.exceptions.ResourceNotFoundException;
@@ -34,6 +35,7 @@
import javax.xml.namespace.QName;
import java.io.*;
import java.net.URL;
+import java.net.URLConnection;
import java.util.*;
public class RemoteRegistry implements Registry, RegistryConstants {
@@ -41,7 +43,7 @@
private String baseURI;
private Log log = LogFactory.getLog(RemoteRegistry.class);
//This will keep the value of username and the password for authorization
- private String authorizationString ;
+ private String authorizationString = null ;
/**
* To create a remote registry need to provide a URL of a remote registry
and the URL should be
@@ -66,7 +68,8 @@
public RemoteRegistry(URL registryURL , String userName , String password){
baseURI = registryURL.toString();
if (userName !=null && password != null ) {
- authorizationString = userName + " " + password;
+ authorizationString = userName + ":" + password;
+ authorizationString = "Basic " +
Base64.encode(authorizationString.getBytes());
}
}
@@ -152,6 +155,10 @@
if (link !=null) {
try {
URL url = new URL(link.getHref().toString());
+ URLConnection uc = url.openConnection();
+ if (authorizationString != null) {
+ uc.setRequestProperty ("Authorization",
authorizationString);
+ }
InputStream in = url.openStream();
int read;
ByteArrayOutputStream out = new ByteArrayOutputStream();
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
Wed Jan 16 23:36:43 2008
@@ -19,6 +19,9 @@
package org.wso2.registry.app;
import org.wso2.registry.jdbc.JDBCRegistryTest;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
+
import java.net.URL;
//This test case run all the test cases that there in JDBCRegistry using
RemoteRegistry
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev