Author: deepal
Date: Thu Jan  3 20:32:30 2008
New Revision: 11820

Log:

making app communication secure. Now for each and every request client send the 
security headers and in the server side it will create a SecureRegistry (Once 
we fix Abdera , we do not need to create SR for each request rather we can 
store values in the session) 

Done few code cleanup 

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/main/java/org/wso2/registry/secure/SecureRegistry.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
   
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceHandler.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
   Thu Jan  3 20:32:30 2008
@@ -36,6 +36,8 @@
 import org.apache.commons.logging.LogFactory;
 import org.wso2.registry.Comment;
 import org.wso2.registry.*;
+import org.wso2.registry.secure.SecureRegistry;
+import org.wso2.registry.jdbc.realm.RegistryRealm;
 import org.wso2.registry.exceptions.ResourceNotFoundException;
 import org.wso2.registry.i18n.Messages;
 
@@ -51,16 +53,18 @@
 
     private Log log = LogFactory.getLog(AtomRegistry.class);
 
-    private Registry registry;
+    private Registry jdbcregistry;
+    private  RegistryRealm realm;
 
 
     public AtomRegistry() {
         super(10);
-        registry = 
(Registry)System.getProperties().get(RegistryConstants.REGISTRY);
+        jdbcregistry = 
(Registry)System.getProperties().get(RegistryConstants.REGISTRY);
+        realm = 
(RegistryRealm)System.getProperties().get(RegistryConstants.REGISTRY_REALM);
     }
 
     /**
-     * To post an entry we can use  this method , however when it come to 
registry posting means
+     * To post an entry we can use  this method , however when it come to 
jdbcregistry posting means
      * adding new resources , adding comments , adding tags , rating etc..
      * <p/>
      * Depending on the type of the operation URl will change , and the URL 
will contain operation
@@ -88,15 +92,15 @@
                         Entry entry = entry_doc.getRoot();
                         String entryContent = entry.getContent();
                         if 
(RegistryConstants.PARAMETER_TAGS.equals(operation)) {
-                            registry.applyTag(resourcePath, entryContent);
+                            getSecureRegistry(request).applyTag(resourcePath, 
entryContent);
                         } else if 
(RegistryConstants.PARAMETER_COMMENTS.equals(operation)) {
                             Comment comment = new Comment();
                             comment.setCommentText(entryContent);
                             
comment.setCommentedUser(entry.getAuthor().getName());
                             comment.setCommentedTime(entry.getUpdated());
-                            registry.addComment(resourcePath, comment);
+                            
getSecureRegistry(request).addComment(resourcePath, comment);
                         } else if 
(RegistryConstants.PARAMETER_RATINGS.equals(operation)) {
-                            registry.rateResource(resourcePath, 
Integer.parseInt(entryContent));
+                            
getSecureRegistry(request).rateResource(resourcePath, 
Integer.parseInt(entryContent));
                         } else {
                             //TODO : We need to implement the other operation 
as well
                             return new EmptyResponseContext(500);
@@ -137,7 +141,7 @@
                         }
                         //entry-id will tell where to put the resource.
                         if (entry_id != null) {
-                            registry.put(entry_id, resource);
+                            getSecureRegistry(request).put(entry_id, resource);
                         }
                     }
                 }
@@ -162,7 +166,7 @@
                     //deleting something else, not a resource like Tag or 
comment
                 } else {
                     // deleting a resource
-                    registry.delete(entry_id);
+                    getSecureRegistry(request).delete(entry_id);
                 }
                 return new EmptyResponseContext(204);
             } catch (RegistryException e) {
@@ -197,19 +201,19 @@
                 String operation = values[1];
                 if (RegistryConstants.PARAMETER_RESTORE.equals(operation)) {
                     String version = values[0];
-                    registry.restoreVersion(version);
+                    getSecureRegistry(request).restoreVersion(version);
                 } else if (RegistryConstants.PARAMETER_TAGS.equals(operation)) 
{
                     String path = values[0];
                     String tags = entry.getContent();
-                    registry.applyTag(path, tags);
+                    getSecureRegistry(request).applyTag(path, tags);
                 } else if 
(RegistryConstants.PARAMETER_TAGS_REMOVED.equals(operation)) {
                     String path = values[0];
                     String tag = entry.getContent();
-                    registry.removeTag(path, tag);
+                    getSecureRegistry(request).removeTag(path, tag);
                 } else if 
(RegistryConstants.PARAMETER_RATINGS.equals(operation)) {
                     String path = values[0];
                     String rate = entry.getContent();
-                    registry.rateResource(path, Integer.parseInt(rate));
+                    getSecureRegistry(request).rateResource(path, 
Integer.parseInt(rate));
                 } else if 
(RegistryConstants.PARAMETER_COMMENTS.equals(operation)) {
                     String path = values[0];
                     String author = entry.getAuthor().getName();
@@ -218,7 +222,7 @@
                     comment.setCommentedTime(entry.getUpdated());
                     comment.setCommentedUser(author);
                     comment.setCommentText(commentString);
-                    registry.addComment(path, comment);
+                    getSecureRegistry(request).addComment(path, comment);
                 }
             }
             return new EmptyResponseContext(200);
@@ -229,7 +233,7 @@
 
 
     /**
-     * This method used to get an atom feed representing the registry and the 
depending on the URL
+     * This method used to get an atom feed representing the jdbcregistry and 
the depending on the URL
      * the format of the feed will differ
      *
      * @param request : RequestContext
@@ -246,7 +250,7 @@
         // returning a 404...
         Resource resource;
         try {
-            resource = registry.get(resourcePath);
+            resource = getSecureRegistry(request).get(resourcePath);
         } catch (ResourceNotFoundException e) {
             return new EmptyResponseContext(404);
         } catch (RegistryException e) {
@@ -268,10 +272,10 @@
             if (RegistryConstants.PARAMETER_VERSION.equals(operation)) {
                 // Need to return list of version for the given resource , 
[resourcePath]
                 try {
-                    String[] versions = registry.getVersions(resourcePath);
+                    String[] versions = 
getSecureRegistry(request).getVersions(resourcePath);
                     Factory factory = abdera.getFactory();
                     feed = factory.newFeed();
-                    feed.setId("http://wso2.org/registry,atom:version";);
+                    feed.setId("http://wso2.org/jdbcregistry,atom:version";);
                     feed.setTitle("Available versions for " + resourcePath);
                     feed.setSubtitle(Messages.getMessage("resource.version", 
resourcePath));
                     feed.setUpdated(new Date());
@@ -287,31 +291,31 @@
                 // if the user [parameter]  name is null then need to return 
all the
                 // tags for the given path
                 if (parameter == null) {
-                    feed = getFeedForTags(abdera, resourcePath, baseURI);
+                    feed = getFeedForTags(abdera, resourcePath, baseURI 
,request);
                 } else {
                     // Need to return only the tags which are done by given 
user
-                    // TODO registry need to provide this feature
+                    // TODO jdbcregistry need to provide this feature
                 }
 
             } else if 
(RegistryConstants.PARAMETER_AVERAGE_RATINGS.equals(operation)) {
                 feed = getRatingsFeed(abdera, resourcePath, baseURI);
             } else if (RegistryConstants.PARAMETER_RATINGS.equals(operation)) {
                 if (parameter != null) {
-                    feed = getFeedForRating(abdera, resourcePath, parameter);
+                    feed = getFeedForRating(abdera, resourcePath, parameter , 
request);
                 } else {
                     feed = getRatingsFeed(abdera, resourcePath, baseURI);
                 }
             } else if (RegistryConstants.PARAMETER_COMMENTS.equals(operation)) 
{
-                feed = getFeedForComments(abdera, resourcePath);
+                feed = getFeedForComments(abdera, resourcePath , request);
             } else if 
(RegistryConstants.PARAMETER_TAG_PATHS.equals(operation)) {
-                feed = getFeedForTagPaths(abdera, parameter, baseURI);
+                feed = getFeedForTagPaths(abdera, parameter, baseURI , 
request);
             } else if (RegistryConstants.PARAMETER_LOGS.equals(operation)) {
                 Date to = request.getDateHeader("ToDate");
                 Date from = request.getDateHeader("FromDate");
                 String action = request.getHeader("Action");
                 String author = request.getHeader("Author");
                 try {
-                    feed = getFeedForLogs(abdera, resourcePath, from, to, 
author, action);
+                    feed = getFeedForLogs(abdera, resourcePath, from, to, 
author, action , request);
                 } catch (RegistryException e) {
                     return new EmptyResponseContext(500);
                 }
@@ -321,13 +325,13 @@
                     String parms = request.getHeader("parameters");
                     String[] parameters =
                             RemoteRegistry.decodeParametesAsString(parms);
-                    resource = registry.executeQuery(resourcePath, parameters);
+                    resource = 
getSecureRegistry(request).executeQuery(resourcePath, parameters);
                     feed = populateFeed(abdera, baseURI, resourcePath, 
resource, true);
                 } catch (RegistryException e) {
                     return new EmptyResponseContext(500);
                 }
             } else if 
(RegistryConstants.PARAMETER_RESOURCE_EXIST.equals(operation)) {
-                feed = getFeedResourceExist(abdera, resourcePath);
+                feed = getFeedResourceExist(abdera, resourcePath , request);
             } else {
                 return createErrorResponse();
             }
@@ -373,7 +377,7 @@
      * become base64 , if the content is String then that will appear as it is.
      *
      * @param abdera       : Reference to Abdera object
-     * @param baseURI      : BaseURI of the registry
+     * @param baseURI      : BaseURI of the jdbcregistry
      * @param path         : resource path
      * @param resource     : Resource object that we need to generate feed
      * @param exceuteQuery : To indicate whether the method call is for query 
execute result or
@@ -401,7 +405,7 @@
         if (resource.getState() == RegistryConstants.DELETED_STATE) {
             feed.addSimpleExtension(new QName("state"), "Deleted");
         }
-        feed.setId("http://wso2.org/registry:atom"; + resource.getId());
+        feed.setId("http://wso2.org/jdbcregistry:atom"; + resource.getId());
         feed.setSubtitle(resource.getDescription());
         feed.addAuthor(resource.getAuthorUserName());
         feed.setTitle(path);
@@ -475,7 +479,7 @@
      * This will create incomplete entry for a given String array
      *
      * @param values  : String array
-     * @param baseURI : Base URI of the registry
+     * @param baseURI : Base URI of the jdbcregistry
      * @param abdera  : Instance of Abdera object
      * @param rel     : The rel value
      * @param feed    : Feed object where we need to add the created entry
@@ -503,7 +507,7 @@
         Entry entry = null;
         if ("".equals(entry_id)) {
             try {
-                Resource reosurce = 
registry.get(RegistryConstants.PATH_SEPARATOR);
+                Resource reosurce = 
getSecureRegistry(request).get(RegistryConstants.PATH_SEPARATOR);
                 if (reosurce == null) {
                     entry = getEmptyEntry(abdera, baseURI, 
get_feed_doc(abdera, baseURI));
                 }
@@ -530,7 +534,7 @@
         Factory factory = abdera.getFactory();
         Feed feed = factory.newFeed();
         try {
-            feed.setId("http://wso2.org/registry,2007:feed";);
+            feed.setId("http://wso2.org/jdbcregistry,2007:feed";);
             feed.setTitle("WSO2 Registry");
             feed.setUpdated(new Date());
             feed.addLink(baseUri);
@@ -598,17 +602,19 @@
      *
      * @param abdera  : Instance of Abdera object
      * @param path    : Path of which need to get the tags
-     * @param baseUri : Base URI of the registry
+     * @param baseUri : Base URI of the jdbcregistry
      * @return : Feed object which contains the tags
+     * @param request : RequestContext
      */
     private Feed getFeedForTags(Abdera abdera,
                                 String path,
-                                String baseUri) {
+                                String baseUri ,
+                                RequestContext request) {
         try {
             Factory factory = abdera.getFactory();
             Feed feed = factory.newFeed();
-            Tag tags[] = registry.getTags(path);
-            feed.setId("http://wso2.org/registry:tags"; + path);
+            Tag tags[] = getSecureRegistry(request).getTags(path);
+            feed.setId("http://wso2.org/jdbcregistry:tags"; + path);
             feed.setTitle("Tags for " + path);
             String nodeLink = baseUri + "atom" + path +
                               RegistryConstants.URL_SEPARATOR +
@@ -635,7 +641,7 @@
      *
      * @param abdera  : Abdera instance
      * @param path    : Resource path
-     * @param baseUri : Base URI of the registry
+     * @param baseUri : Base URI of the jdbcregistry
      * @return Feed representing the average feed
      */
     private Feed getRatingsFeed(Abdera abdera, String path, String baseUri) {
@@ -643,14 +649,14 @@
             Factory factory = abdera.getFactory();
             Feed feed = factory.newFeed();
             feed.setUpdated(new Date());
-            feed.setId("http://wso2.org/registry:avarageRating";);
+            feed.setId("http://wso2.org/jdbcregistry:avarageRating";);
             feed.setTitle("Avarage Rating for the resource " + path);
             String nodeLink = baseUri + "atom" + path +
                               RegistryConstants.URL_SEPARATOR +
                               RegistryConstants.PARAMETER_AVERAGE_RATINGS;
             feed.addLink(nodeLink);
             feed.addSimpleExtension(RegistryConstants.QNAME_AVGRATING,
-                                    "" + registry.getAverageRating(path));
+                                    "" + jdbcregistry.getAverageRating(path));
             return feed;
         } catch (RegistryException e) {
             return null;
@@ -665,15 +671,19 @@
      * @param path     : Resource path
      * @param userName : user name
      * @return : Created feed
+     * @param request : RequestContext
      */
-    private Feed getFeedForRating(Abdera abdera, String path, String userName) 
{
+    private Feed getFeedForRating(Abdera abdera,
+                                  String path,
+                                  String userName,
+                                  RequestContext request) {
         try {
             Factory factory = abdera.getFactory();
             Feed feed = factory.newFeed();
             feed.setUpdated(new Date());
-            feed.setId("http://wso2.org/registry:Rating"; + path);
+            feed.setId("http://wso2.org/jdbcregistry:Rating"; + path);
             feed.setTitle(userName + " ratings for " + path);
-            feed.setSubtitle("" + registry.getRating(path, userName));
+            feed.setSubtitle("" + getSecureRegistry(request).getRating(path, 
userName));
             return feed;
         } catch (RegistryException e) {
             return null;
@@ -688,18 +698,21 @@
      * @param abdera : An instance of Abdera
      * @param path   : Resource path
      * @return : created Feed object
+     * @param request : RequestContext
      */
-    private Feed getFeedForComments(Abdera abdera, String path) {
+    private Feed getFeedForComments(Abdera abdera,
+                                    String path,
+                                    RequestContext request) {
         try {
             Factory factory = abdera.getFactory();
             Feed feed = factory.newFeed();
-            Comment comments[] = registry.getComments(path);
-            feed.setId("http://wso2.org/registry,Comments"; + path);
+            Comment comments[] = getSecureRegistry(request).getComments(path);
+            feed.setId("http://wso2.org/jdbcregistry,Comments"; + path);
             feed.setUpdated(new Date());
             feed.setTitle("comments for the resource " + path);
             for (Comment comment : comments) {
                 Entry entry = abdera.getFactory().newEntry();
-                entry.setId("http://wso2.org/registry/atom/comment";);
+                entry.setId("http://wso2.org/jdbcregistry/atom/comment";);
                 entry.addAuthor(comment.getCommentedUser());
                 entry.setUpdated(comment.getCommentedTime());
                 entry.setContent(comment.getCommentText());
@@ -720,15 +733,19 @@
      *
      * @param abdera  : An instance of Abdera
      * @param tag     : Nam of the tag
-     * @param baseUri : Base URI of the registry
+     * @param baseUri : Base URI of the jdbcregistry
      * @return : Feed containing one or more entries
+     * @param request : RequestContext
      */
-    private Feed getFeedForTagPaths(Abdera abdera, String tag, String baseUri) 
{
+    private Feed getFeedForTagPaths(Abdera abdera,
+                                    String tag,
+                                    String baseUri ,
+                                    RequestContext request) {
         try {
             Factory factory = abdera.getFactory();
             Feed feed = factory.newFeed();
-            TaggedResourcePath tagpaths[] = 
registry.getResourcePathsWithTag(tag);
-            feed.setId("http://wso2.org/registry/TagPaths";);
+            TaggedResourcePath tagpaths[] = 
getSecureRegistry(request).getResourcePathsWithTag(tag);
+            feed.setId("http://wso2.org/jdbcregistry/TagPaths";);
             feed.setUpdated(new Date());
             feed.setTitle("TagPaths for" + tag);
             for (TaggedResourcePath tagPath : tagpaths) {
@@ -747,13 +764,13 @@
 
     public ResponseContext getService(RequestContext request) {
         Abdera abdera = request.getAbdera();
-        EntityTag service_etag = new EntityTag("registry");
+        EntityTag service_etag = new EntityTag("jdbcregistry");
         Document<Service> service;
         Factory factory = abdera.getFactory();
         Service serviceElement = factory.newService();
         Workspace workspace = serviceElement.addWorkspace("Registry");
         try {
-            Collection collection = workspace.addCollection("registry", 
"atom/feed");
+            Collection collection = workspace.addCollection("jdbcregistry", 
"atom/feed");
             collection.setAccept("entry");
             collection.addCategories().setFixed(false);
         } catch (Exception e) {
@@ -779,18 +796,20 @@
      * @param action : Log action , will be a string header in the request
      * @return : Feed containing results
      * @throws RegistryException : If something went wrong
+     * @param request : RequestContext
      */
     private Feed getFeedForLogs(Abdera abdera,
                                 String path,
                                 Date from,
                                 Date to,
                                 String author,
-                                String action) throws RegistryException {
-        LogEntry[] entries = registry.getLogs(
+                                String action ,
+                                RequestContext request) throws 
RegistryException {
+        LogEntry[] entries = getSecureRegistry(request).getLogs(
                 path, Integer.parseInt(action), author, from, to, true);
         Factory factory = abdera.getFactory();
         Feed feed = factory.newFeed();
-        feed.setId("http://wso2.org/registry,2007:logs";);
+        feed.setId("http://wso2.org/jdbcregistry,2007:logs";);
         feed.setTitle("Logs for the resource" + path);
         feed.addLink("", "self");
         feed.setUpdated(new Date());
@@ -812,14 +831,17 @@
      * @param abdera : An instance  of Abdera
      * @param path   : Resource path
      * @return : Feed object
+     * @param request : RequestContext
      */
-    private Feed getFeedResourceExist(Abdera abdera, String path) {
+    private Feed getFeedResourceExist(Abdera abdera,
+                                      String path,
+                                      RequestContext request) {
         try {
-            boolean isResourceExsit = registry.resourceExists(path);
+            boolean isResourceExsit = 
getSecureRegistry(request).resourceExists(path);
             Factory factory = abdera.getFactory();
             Feed feed = factory.newFeed();
             feed.setUpdated(new Date());
-            feed.setId("http://wso2.org/registry:resourceExist"; + path);
+            feed.setId("http://wso2.org/jdbcregistry:resourceExist"; + path);
             if (isResourceExsit) {
                 feed.setSubtitle("True");
             } else {
@@ -831,4 +853,28 @@
         }
     }
 
+    /**
+     * This method will create a SecureRegistry for APP. If the user has send 
the user name
+     * and the password then the jdbcregistry will be created using the value 
he has given, else
+     * the jdbcregistry instance will be created as annon user.
+     * @return : Created jdbcregistry
+     * @throws RegistryException : If something went wrong
+     * @param request : RequestContext to get the authorization header
+     */
+    private Registry getSecureRegistry(RequestContext request) throws 
RegistryException {
+        String authorizationString = request.getAuthorization();
+        if (authorizationString != null) {
+            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);
+            return jdbcregistry;
+        } else {
+            // seems like need to create a secure jdbcregistry with annon user
+            return new SecureRegistry(
+                    RegistryConstants.ANONYMOUS_USER, "guest", jdbcregistry, 
realm);
+        }
+    }
 }

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
 Thu Jan  3 20:32:30 2008
@@ -44,22 +44,40 @@
 
     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 ;
 
     /**
      * To create a remote registry need to provide a URL of a remote registry 
and the URL should be
      * something like http://localhost:8080/wso2registry/atom/r1
      *
      * @param registryURL : URL to the registry or to the resource
-     * @throws RegistryException : If something went wrong
      */
-    public RemoteRegistry(URL registryURL) throws RegistryException {
+    public RemoteRegistry(URL registryURL){
         baseURI = registryURL.toString();
     }
 
+    /**
+     * To create a remote registry to connect to a secure registry or a 
registry where
+     * we need to pass userName and the password to perform any operation. 
Passing not
+     * null value registry will send the username and the password for each 
request.
+     * Need to remember here is that the username and the password send as 
plain text.
+     * @param registryURL : URL to the registry or to the resource
+     * @param userName : user name of the registry , value can be null , if 
the value is null
+     * then the user will be the anonymous.
+     * @param password : password , value can be null
+     */
+    public RemoteRegistry(URL registryURL , String userName , String password){
+        baseURI = registryURL.toString();
+        if (userName !=null && password != null ) {
+            authorizationString = userName + " " + password;
+        }
+    }
+
     public Resource get(String path) throws RegistryException {
         Abdera abdera = new Abdera();
         AbderaClient abderaClient = new AbderaClient(abdera);
-        ClientResponse clientResponse = abderaClient.get(baseURI + path);
+        ClientResponse clientResponse = abderaClient.get(baseURI + path , 
getAuthorization());
         if (clientResponse.getType() == Response.ResponseType.CLIENT_ERROR) {
             throw new ResourceNotFoundException(path);
         }
@@ -143,7 +161,7 @@
         AbderaClient abderaClient = new AbderaClient(abdera);
         ClientResponse clientResponse = abderaClient.get(baseURI + path +
                 URL_SEPARATOR +
-                PARAMETER_RESOURCE_EXIST);
+                PARAMETER_RESOURCE_EXIST , getAuthorization());
         Document introspection =
                 clientResponse.getDocument();
         Feed feed = (Feed) introspection.getRoot();
@@ -184,7 +202,7 @@
                 entry.setContent((String) content);
             }
         }
-        ClientResponse resp = abderaClient.post(baseURI + path, entry);
+        ClientResponse resp = abderaClient.post(baseURI + path, entry, 
getAuthorization());
         if (resp.getType() == Response.ResponseType.SUCCESS) {
             log.info(Messages.getMessage("resource.add", path));
         } else {
@@ -196,7 +214,7 @@
     public void delete(String path) throws RegistryException {
         Abdera abdera = new Abdera();
         AbderaClient abderaClient = new AbderaClient(abdera);
-        ClientResponse resp = abderaClient.delete(baseURI + path);
+        ClientResponse resp = abderaClient.delete(baseURI + path , 
getAuthorization());
         if (resp.getType() == Response.ResponseType.SUCCESS) {
             log.info(Messages.getMessage("resource.deleted", path));
         } else {
@@ -210,7 +228,7 @@
         AbderaClient abderaClient = new AbderaClient(abdera);
         ClientResponse clientResponse = abderaClient.get(baseURI + path +
                 URL_SEPARATOR +
-                PARAMETER_VERSION);
+                PARAMETER_VERSION,getAuthorization());
         Document introspection =
                 clientResponse.getDocument();
         Feed feed = (Feed) introspection.getRoot();
@@ -232,7 +250,7 @@
         Entry entry = abdera.getFactory().newEntry();
         ClientResponse resp = abderaClient.put(baseURI + versionPath +
                 URL_SEPARATOR +
-                PARAMETER_RESTORE, entry);
+                PARAMETER_RESTORE, entry , getAuthorization());
         if (resp.getType() == Response.ResponseType.SUCCESS) {
             log.info(Messages.getMessage("resource.restoreded", versionPath));
         } else {
@@ -248,7 +266,7 @@
         entry.setContent(tag);
         ClientResponse resp = abderaClient.put(baseURI + resourcePath +
                 URL_SEPARATOR +
-                PARAMETER_TAGS, entry);
+                PARAMETER_TAGS, entry , getAuthorization());
         if (resp.getType() == Response.ResponseType.SUCCESS) {
             log.info(Messages.getMessage("resource.tagged", resourcePath));
         } else {
@@ -263,7 +281,7 @@
         ClientResponse clientResponse = abderaClient.get(baseURI +
                 URL_SEPARATOR +
                 PARAMETER_TAG_PATHS +
-                ":" + tag);
+                ":" + tag , getAuthorization());
         Document introspection =
                 clientResponse.getDocument();
         Feed feed = (Feed) introspection.getRoot();
@@ -288,7 +306,7 @@
         ClientResponse clientResponse = abderaClient.get(baseURI +
                 resourcePath +
                 URL_SEPARATOR +
-                PARAMETER_TAGS);
+                PARAMETER_TAGS , getAuthorization());
         Document introspection =
                 clientResponse.getDocument();
         Feed feed = (Feed) introspection.getRoot();
@@ -314,7 +332,7 @@
         entry.setContent(tag);
         ClientResponse resp = abderaClient.put(baseURI + path +
                 URL_SEPARATOR +
-                PARAMETER_TAGS_REMOVED, entry);
+                PARAMETER_TAGS_REMOVED, entry , getAuthorization());
         if (resp.getType() == Response.ResponseType.SUCCESS) {
             log.info(Messages.getMessage("tag.removed", path));
         } else {
@@ -332,7 +350,7 @@
         entry.setContent(comment.getCommentText());
         ClientResponse resp = abderaClient.put(baseURI + resourcePath +
                 URL_SEPARATOR +
-                PARAMETER_COMMENTS, entry);
+                PARAMETER_COMMENTS, entry , getAuthorization());
         if (resp.getType() == Response.ResponseType.SUCCESS) {
             log.info(Messages.getMessage("resource.commented", resourcePath));
         } else {
@@ -346,7 +364,7 @@
         AbderaClient abderaClient = new AbderaClient(abdera);
         ClientResponse clientResponse = abderaClient.get(baseURI + 
resourcePath +
                 URL_SEPARATOR +
-                PARAMETER_COMMENTS);
+                PARAMETER_COMMENTS , getAuthorization());
         Document introspection =
                 clientResponse.getDocument();
         Element element = introspection.getRoot();
@@ -375,7 +393,7 @@
         entry.setSummary(PARAMETER_RATINGS);
         ClientResponse resp = abderaClient.put(baseURI + resourcePath +
                 URL_SEPARATOR +
-                PARAMETER_RATINGS, entry);
+                PARAMETER_RATINGS, entry , getAuthorization());
         if (resp.getType() == Response.ResponseType.SUCCESS) {
             log.info(Messages.getMessage("resource.rated", resourcePath));
         } else {
@@ -388,7 +406,7 @@
         Abdera abdera = new Abdera();
         AbderaClient abderaClient = new AbderaClient(abdera);
         ClientResponse clientResponse = abderaClient.get(baseURI + 
resourcePath +
-                URL_SEPARATOR + PARAMETER_RATINGS);
+                URL_SEPARATOR + PARAMETER_RATINGS , getAuthorization());
         Document introspection = clientResponse.getDocument();
         Feed feed = (Feed) introspection.getRoot();
         String floatvalue = feed.getSimpleExtension(QNAME_AVGRATING);
@@ -400,7 +418,7 @@
         AbderaClient abderaClient = new AbderaClient(abdera);
         ClientResponse clientResponse =
                 abderaClient.get(baseURI + path + URL_SEPARATOR +
-                                 PARAMETER_RATINGS + ":" + userName);
+                                 PARAMETER_RATINGS + ":" + userName , 
getAuthorization());
         Document introspection =
                 clientResponse.getDocument();
         Feed feed = (Feed) introspection.getRoot();
@@ -412,7 +430,7 @@
     public Resource executeQuery(String path, Object[] parameters) throws 
RegistryException {
         Abdera abdera = new Abdera();
         AbderaClient abderaClient = new AbderaClient(abdera);
-        RequestOptions requestOptions = new RequestOptions();
+        RequestOptions requestOptions = getAuthorization();
         requestOptions.addHeader("parameters", 
encodeParametesAsString(parameters));
         ClientResponse resp = abderaClient.get(baseURI + path +
                 URL_SEPARATOR +
@@ -452,7 +470,7 @@
             resourcePath = "/";
         }
         AbderaClient abderaClient = new AbderaClient(abdera);
-        RequestOptions requestOptions = new RequestOptions();
+        RequestOptions requestOptions = getAuthorization();
         requestOptions.addDateHeader("ToDate", to);
         requestOptions.addDateHeader("FromDate", from);
         requestOptions.addHeader("Action", "" + action);
@@ -569,4 +587,16 @@
             }
         }
     }
+
+    /**
+     * This method will create a RequestOptions object adding  Authorization 
headers.
+     *
+     * @return RequestOptions : Created RequestOptions object
+     */
+    private RequestOptions getAuthorization() {
+        RequestOptions requestOptions = new RequestOptions();
+        requestOptions.setAuthorization(authorizationString);
+        return requestOptions;
+    }
+
 }

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
      (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
      Thu Jan  3 20:32:30 2008
@@ -144,6 +144,8 @@
         String authorizationPath = path;
         if (path.indexOf("?") > 0) {
             authorizationPath = path.split("\\?")[0];
+        } else if (path.indexOf(":")>0) {
+            authorizationPath = path.split("\\:")[0];
         }
 
         try {

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
    (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
    Thu Jan  3 20:32:30 2008
@@ -26,7 +26,6 @@
 import org.wso2.registry.RegistryConstants;
 import org.wso2.registry.RegistryException;
 import org.wso2.registry.Resource;
-import org.wso2.registry.app.RemoteRegistry;
 import org.wso2.registry.config.DataBaseConfiguration;
 import org.wso2.registry.config.RegistryConfiguration;
 import org.wso2.registry.i18n.Messages;
@@ -48,8 +47,6 @@
 import javax.sql.DataSource;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.net.URL;
-import java.net.MalformedURLException;
 import java.util.Date;
 
 /** Servlet for providing REST API for the registry. */
@@ -133,6 +130,7 @@
                     .setAttribute(RegistryConstants.REGISTRY_REALM, 
registryRealm);
             System.getProperties().put(RegistryConstants.REGISTRY, 
coreRegistry);
             System.getProperties().put(RegistryConstants.SYSTEM_REGISTRY, 
systemRegistry);
+            System.getProperties().put(RegistryConstants.REGISTRY_REALM, 
registryRealm);
         } catch (RegistryException e) {
             throw new ServletException(e.getMessage());
         }
@@ -194,7 +192,7 @@
         if (controlPart.startsWith(
                 RegistryConstants.PATH_SEPARATOR + 
RegistryConstants.RESOURCES_PATH)) {
 
-            String path = null;
+            String path ;
 
             if (uri.equals("") || 
uri.endsWith(RegistryConstants.RESOURCES_PATH +
                     RegistryConstants.PATH_SEPARATOR)) {
@@ -215,7 +213,7 @@
                 path = path + "?" + qPart;
             }
 
-            Resource resource = null;
+            Resource resource ;
             try {
                 resource = ResourceHandlerUtil.getResource(request, path);
             } catch (RegistryException e) {
@@ -302,7 +300,10 @@
         }
 
         try {
-            Object content = resource.getContent();
+            Object content = null;
+            if (resource != null) {
+                content = resource.getContent();
+            }
             if (content != null) {
 
                 response.setDateHeader("Last-Modified", 
resource.getLastModified().getTime());

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
   Thu Jan  3 20:32:30 2008
@@ -45,7 +45,7 @@
         try {
             if (registry == null) {
                 initJetty();
-                registry = new RemoteRegistry(new 
URL("http://localhost:8081/wso2registry/atom";));
+                registry = new RemoteRegistry(new 
URL("http://localhost:8081/wso2registry/atom";), "admin","admin");
             }
         } catch (Exception e) {
             fail("Failed to initialize the registry.");
@@ -79,6 +79,7 @@
                     //jdbcRegistry = new JDBCRegistry();
                     //jdbcRegistry.init(registryRealm);
                     System.getProperties().put(RegistryConstants.REGISTRY, 
jdbcRegistry);
+                    
System.getProperties().put(RegistryConstants.REGISTRY_REALM, new 
InMemoryRegistryRealm());
                 } catch (RegistryException e) {
                     e.printStackTrace();
                 }

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   Thu Jan  3 20:32:30 2008
@@ -64,7 +64,7 @@
         if (userRegistry != null) {
             request.getSession().setAttribute(UIConstants.USER_ATTR, 
userRegistry.getUserID());
 
-            request.getSession().setAttribute(UIConstants.IS_LOGGED_IN_ATTR, 
new Boolean(true));
+            request.getSession().setAttribute(UIConstants.IS_LOGGED_IN_ATTR, 
Boolean.TRUE);
 
             try {
                 boolean isAdmin = UserUtil.isAdmin(request, 
userRegistry.getUserID());
@@ -77,7 +77,7 @@
 
         } else {
             request.getSession().setAttribute(UIConstants.USER_ATTR, 
RegistryConstants.ANONYMOUS_USER);
-            request.getSession().setAttribute(UIConstants.IS_LOGGED_IN_ATTR, 
new Boolean(false));
+            request.getSession().setAttribute(UIConstants.IS_LOGGED_IN_ATTR, 
Boolean.FALSE);
         }
 
         String uri = request.getRequestURI();
@@ -245,11 +245,11 @@
 
             } else if (command.equals("/setDescription")) {
 
-                String resourcePath = path;
+                //String resourcePath = path;
                 String description = request.getParameter("description");
 
                 SetDescriptionAction setDescriptionAction = new 
SetDescriptionAction();
-                setDescriptionAction.setResourcePath(resourcePath);
+                setDescriptionAction.setResourcePath(path);
                 setDescriptionAction.setDescription(description);
 
                 try {
@@ -264,7 +264,7 @@
 
             } else if (command.equals("/setRating")) {
 
-                int userRating = new 
Integer(request.getParameter("ratingValue")).intValue();
+                int userRating = 
Integer.parseInt(request.getParameter("ratingValue"));
 
                 AjaxRatingAction ajaxRatingAction = new AjaxRatingAction();
                 ajaxRatingAction.setResourcePath(path);
@@ -298,7 +298,7 @@
 
             } else if (command.equals("/addUserToRole")) {
 
-                String userName = (String) request.getParameter("userName");
+                String userName = request.getParameter("userName");
                 AddUserRoleAction addUserRoleAction = new AddUserRoleAction();
                 addUserRoleAction.setUserName(userName);
                 
addUserRoleAction.setRoleName(request.getParameter("roleToAdd"));
@@ -479,7 +479,7 @@
                 path = path + "?" + qPart;
             }
 
-            VersionsBean versionsBean = null;
+            VersionsBean versionsBean ;
             try {
                 versionsBean = ResourcesUtil.getVersions(request, path);
             } catch (RegistryException e) {
@@ -490,8 +490,6 @@
 
             request.getSession().setAttribute(UIConstants.VERSIONS_BEAN, 
versionsBean);
             
request.getRequestDispatcher(UIConstants.VERSIONS_JSP).forward(request, 
response);
-            return;
-
         } else if (controlPart.startsWith(RegistryConstants.PATH_SEPARATOR + 
UIConstants.RESOURCES_PATH)) {
 
             if (uri.equals("") || uri.endsWith(UIConstants.RESOURCES_PATH + 
RegistryConstants.PATH_SEPARATOR)) {
@@ -509,7 +507,7 @@
                 path = path + "?" + qPart;
             }
 
-            Resource resource = null;
+            Resource resource ;
             try {
                 resource = ResourcesUtil.getResource(request, path);
             } catch (RegistryException e) {
@@ -659,7 +657,7 @@
             } else if (command.equals("/getRating")) {
 
                 String rating = request.getParameter("userRating");
-                int iRating = new Integer(rating).intValue();
+                int iRating = Integer.parseInt(rating);
 
                 AjaxRatingAction ajaxRatingAction = new AjaxRatingAction();
                 
ajaxRatingAction.setResourcePath(request.getParameter("resourcePath"));
@@ -703,7 +701,7 @@
 
             } else if (command.equals("/getResourceMediaTypes")) {
 
-                String mediaTypes = null;
+                String mediaTypes ;
                 try {
                     mediaTypes = 
MediaTypesReader.getResourceMediaTypeMappings(request);
                 } catch (RegistryException e) {
@@ -711,9 +709,6 @@
                 }
 
                 response.getWriter().write(mediaTypes);
-
-                return;
-
             } else if (command.equals("/removeDBConfig")) {
 
                 AdminUtil.removeDBConfiguration(request, response);
@@ -757,7 +752,10 @@
         }
 
         try {
-            Object content = resource.getContent();
+            Object content = null;
+            if (resource != null) {
+                content = resource.getContent();
+            }
             if (content != null) {
 
                 if (resource.getMediaType() != null && 
resource.getMediaType().length() > 0) {
@@ -1020,9 +1018,6 @@
     }
 
     private void forwardToUserPage(HttpServletRequest request, 
HttpServletResponse response, String userName) {
-
-        String uri = request.getRequestURI();
-
         UserDetailsAction userDetailsAction = new UserDetailsAction();
         userDetailsAction.setUserName(userName);
 

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceHandler.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceHandler.java
     (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceHandler.java
     Thu Jan  3 20:32:30 2008
@@ -20,7 +20,6 @@
 import org.wso2.registry.RegistryException;
 import org.wso2.registry.Resource;
 import org.wso2.registry.Registry;
-import org.wso2.registry.jdbc.JDBCRegistry;
 import org.wso2.registry.jdbc.realm.RegistryRealm;
 import org.wso2.registry.secure.SecureRegistry;
 import org.wso2.registry.web.ConsoleConstants;

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to