org.wso2.registry.secure
Class SecureRegistry

java.lang.Object
  extended by org.wso2.registry.secure.SecureRegistry
All Implemented Interfaces:
CoreRegistry, Registry

public class SecureRegistry
extends java.lang.Object
implements Registry

Registry implementation to perform authentication and authorization. Each user should use a separate instance of the SecureRegistry initialized with the user name and a back-end Registry. All SecureRegistry instances should be initialized using the same back-end registry implementation. SecureRegistry verifies whether the user has necessary permissions to perform the requested action and delegates the request to the back-end registry if the authorization succeeds. It also sets user name as a thread local variable before delegating the request, so that the back-end registry can use that user name to associate user information with performed operation (e.g. who commented on the resource /projects/abcbank/orders.doc).

Resource path is used as the unique ID of the resource to associate permissions. So when an operation is request on a certain path, we can first check the permissions for that path, without even touching the actual resource. This has a side effect that if a user has requested an operation on a non-existing resource, he gets an unauthorized operation message rather than a resource does not exist message. This is good as we don't want unauthorized users to check if a resource exist in a particular path.


Constructor Summary
SecureRegistry(java.lang.String userID, Registry registry, org.wso2.usermanager.Realm defaultRealm)
          Non-authenticating constructor.
SecureRegistry(java.lang.String userID, java.lang.String password, Registry registry, org.wso2.usermanager.Realm defaultRealm)
           
 
Method Summary
 java.lang.String addComment(java.lang.String resourcePath, Comment comment)
          Adds a comment to a resource.
 void applyTag(java.lang.String resourcePath, java.lang.String tag)
          Applies the given tag to the resource in the given path.
 void delete(java.lang.String path)
          Deletes the resource at the given path.
 void editComment(java.lang.String commentPath, java.lang.String text)
          Change the text of an existing comment.
 Resource executeQuery(java.lang.String path, java.util.Map parameters)
          Executes a custom query which lives at the given path in the Registry.
 Resource get(java.lang.String path)
          Returns the resource at the given path.
 float getAverageRating(java.lang.String resourcePath)
          Returns the average rating for the given resource.
 Comment[] getComments(java.lang.String resourcePath)
          Get all comments for the given resource.
 LogEntry[] getLogs(java.lang.String resourcePath, int action, java.lang.String userName, java.util.Date from, java.util.Date to, boolean recentFirst)
          Returns the logs of the activities occured in the registy.
 int getRating(java.lang.String resourcePath, java.lang.String userName)
          Returns the rating given to the specified resource by the given user
 TaggedResourcePath[] getResourcePathsWithTag(java.lang.String tag)
          Returns the paths of all Resources that are tagged with the given tag.
 Tag[] getTags(java.lang.String resourcePath)
          Returns all tags used for tagging the given resource.
 java.lang.String getUserID()
           
 org.wso2.usermanager.Realm getUserRealm()
           
 java.lang.String[] getVersions(java.lang.String resourcePath)
          Get a list of all versions of the resource located at the given path.
 java.lang.String importResource(java.lang.String suggestedPath, java.lang.String sourceURL, Resource metadata)
          Creates a resource by fetching the resource content from the given URL.
 java.lang.String put(java.lang.String suggestedPath, Resource resource)
          Checks if the user has "PUT" permissions to the existing ascendent path of the given path.
 void rateResource(java.lang.String resourcePath, int rating)
          Rate the given resource.
 void removeTag(java.lang.String resourcePath, java.lang.String tag)
          Removes a tag on a resource.
 java.lang.String rename(java.lang.String currentPath, java.lang.String newPath)
          Move or rename a resource in the registry.
 boolean resourceExists(java.lang.String resourcePath)
          Check whether a resource exists at the given path
 void restoreVersion(java.lang.String versionPath)
          Reverts a resource to a given version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SecureRegistry

public SecureRegistry(java.lang.String userID,
                      java.lang.String password,
                      Registry registry,
                      org.wso2.usermanager.Realm defaultRealm)
               throws RegistryException
Throws:
RegistryException

SecureRegistry

public SecureRegistry(java.lang.String userID,
                      Registry registry,
                      org.wso2.usermanager.Realm defaultRealm)
               throws RegistryException
Non-authenticating constructor. Use this constructor if the user is already authenticated outside the secure registry.

Parameters:
userID - user name of the user of the secure registry.
registry - core registry to use by the secure registry.
defaultRealm - default (non-authorizing) realm.
Throws:
RegistryException
Method Detail

getUserID

public java.lang.String getUserID()

getUserRealm

public org.wso2.usermanager.Realm getUserRealm()

get

public Resource get(java.lang.String path)
             throws RegistryException
Description copied from interface: CoreRegistry
Returns the resource at the given path.

Specified by:
get in interface CoreRegistry
Parameters:
path - Path of the resource. e.g. /project1/server/deployment.xml
Returns:
Resource instance
Throws:
RegistryException - is thrown if the resource is not in the registry

resourceExists

public boolean resourceExists(java.lang.String resourcePath)
                       throws RegistryException
Description copied from interface: CoreRegistry
Check whether a resource exists at the given path

Specified by:
resourceExists in interface CoreRegistry
Parameters:
resourcePath - Path of the resource to be checked
Returns:
true if a resource exists at the given path, false otherwise.
Throws:
RegistryException - if an error occurs

put

public java.lang.String put(java.lang.String suggestedPath,
                            Resource resource)
                     throws RegistryException
Checks if the user has "PUT" permissions to the existing ascendent path of the given path. e.g. if a user wants to put a resource in to the path "/d1/d2/d3/r1" and only "/d1/d2" currently exist in the registry, that user should have PUT permission to "/d1/d2".

If the user has PUT permission, delegates the request to the underlying jdbc registry.

Then sets the default permissions for newly created paths. i.e. in the above sample, default permissions are set for "/d1/d2/d3" and "/d1/d2/d3/r1".

Specified by:
put in interface CoreRegistry
Parameters:
suggestedPath - the path which we'd like to use for the new resource.
resource - New resource @throws RegistryException
Returns:
the actual path that the server chose to use for our Resource
Throws:
RegistryException

importResource

public java.lang.String importResource(java.lang.String suggestedPath,
                                       java.lang.String sourceURL,
                                       Resource metadata)
                                throws RegistryException
Description copied from interface: Registry
Creates a resource by fetching the resource content from the given URL.

Specified by:
importResource in interface Registry
Parameters:
suggestedPath - path where we'd like to add the new resource. Although this path is specified by the caller of the method, resource may not be actually added at this path.
sourceURL - where to fetch the resource content
metadata - a template Resource
Returns:
actual path to the new resource
Throws:
RegistryException - if we couldn't get or store the new resource

delete

public void delete(java.lang.String path)
            throws RegistryException
Description copied from interface: CoreRegistry
Deletes the resource at the given path. If the path refers to a directory, all child resources of the directory will also be deleted.

Specified by:
delete in interface CoreRegistry
Parameters:
path - Path of the resource to be deleted.
Throws:
RegistryException - is thrown depending on the implementation.

rename

public java.lang.String rename(java.lang.String currentPath,
                               java.lang.String newPath)
                        throws RegistryException
Description copied from interface: Registry
Move or rename a resource in the registry. This is equivalent to 1) delete the resource, then 2) add the resource to the new location. The operation is atomic, so if it fails the old resource will still be there.

Specified by:
rename in interface Registry
Parameters:
currentPath - current path of the resource
newPath - where we'd like to move the reosurce
Returns:
the actual path for the new resource
Throws:
RegistryException - if something went wrong

getVersions

public java.lang.String[] getVersions(java.lang.String resourcePath)
                               throws RegistryException
Description copied from interface: Registry
Get a list of all versions of the resource located at the given path. Version paths are returned in the form /projects/myresource?v=12

Specified by:
getVersions in interface Registry
Parameters:
resourcePath - path of a current version of a resource
Returns:
a String array containing the individual paths of versions
Throws:
RegistryException - if there is an error

restoreVersion

public void restoreVersion(java.lang.String versionPath)
                    throws RegistryException
Description copied from interface: Registry
Reverts a resource to a given version.

Specified by:
restoreVersion in interface Registry
Parameters:
versionPath - path of the version to be reverted. It is not necessary to provide the path of the resource as it can be derived from the version path.
Throws:
RegistryException - if there is an error

applyTag

public void applyTag(java.lang.String resourcePath,
                     java.lang.String tag)
              throws RegistryException
Description copied from interface: Registry
Applies the given tag to the resource in the given path. If the given tag is not defined in the registry, it will be defined.

Specified by:
applyTag in interface Registry
Parameters:
resourcePath - Path of the resource to be tagged.
tag - Tag. Any string can be used for the tag.
Throws:
RegistryException - is thrown if a resource does not exist in the given path.

getResourcePathsWithTag

public TaggedResourcePath[] getResourcePathsWithTag(java.lang.String tag)
                                             throws RegistryException
Description copied from interface: Registry
Returns the paths of all Resources that are tagged with the given tag.

Specified by:
getResourcePathsWithTag in interface Registry
Parameters:
tag - the tag to search for
Returns:
an array of TaggedResourcePaths
Throws:
RegistryException - if an error occurs

getTags

public Tag[] getTags(java.lang.String resourcePath)
              throws RegistryException
Description copied from interface: Registry
Returns all tags used for tagging the given resource.

Specified by:
getTags in interface Registry
Parameters:
resourcePath - Path of the resource
Returns:
Tags tag names
Throws:
RegistryException - is thrown if a resource does not exist in the given path.

removeTag

public void removeTag(java.lang.String resourcePath,
                      java.lang.String tag)
               throws RegistryException
Description copied from interface: Registry
Removes a tag on a resource. If the resource at the path is owned by the current user, all taggings done using the given tag will be removed. If the resource is not owned by the current user, only the tagging done by the current user will be removed.

Specified by:
removeTag in interface Registry
Parameters:
resourcePath - Resource path tagged with the given tag.
tag - Name of the tag to be removed.
Throws:
RegistryException - if there's a problem

addComment

public java.lang.String addComment(java.lang.String resourcePath,
                                   Comment comment)
                            throws RegistryException
Description copied from interface: Registry
Adds a comment to a resource.

Specified by:
addComment in interface Registry
Parameters:
resourcePath - Path of the resource to add the comment.
comment - Comment instance for the new comment.
Returns:
the path of the new comment.
Throws:
RegistryException - is thrown if a resource does not exist in the given path.

editComment

public void editComment(java.lang.String commentPath,
                        java.lang.String text)
                 throws RegistryException
Description copied from interface: Registry
Change the text of an existing comment.

Specified by:
editComment in interface Registry
Parameters:
commentPath - path to comment resource ("..foo/r1;comment:1")
text - new text for the comment.
Throws:
RegistryException - Registry implementations may handle exceptions and throw RegistryException if the exception has to be propagated to the client.

getComments

public Comment[] getComments(java.lang.String resourcePath)
                      throws RegistryException
Description copied from interface: Registry
Get all comments for the given resource.

Specified by:
getComments in interface Registry
Parameters:
resourcePath - path of the resource.
Returns:
an array of Comment objects.
Throws:
RegistryException - Registry implementations may handle exceptions and throw RegistryException if the exception has to be propagated to the client.

rateResource

public void rateResource(java.lang.String resourcePath,
                         int rating)
                  throws RegistryException
Description copied from interface: Registry
Rate the given resource.

Specified by:
rateResource in interface Registry
Parameters:
resourcePath - Path of the resource.
rating - Rating value between 1 and 5.
Throws:
RegistryException - Registry implementations may handle exceptions and throw RegistryException if the exception has to be propagated to the client.

getAverageRating

public float getAverageRating(java.lang.String resourcePath)
                       throws RegistryException
Description copied from interface: Registry
Returns the average rating for the given resource. This is the average of all ratings done by all users for the given resource.

Specified by:
getAverageRating in interface Registry
Parameters:
resourcePath - Path of the resource.
Returns:
Average rating between 1 and 5.
Throws:
RegistryException - if an error occurs

getRating

public int getRating(java.lang.String resourcePath,
                     java.lang.String userName)
              throws RegistryException
Description copied from interface: Registry
Returns the rating given to the specified resource by the given user

Specified by:
getRating in interface Registry
Parameters:
resourcePath - Path of the resource
userName - username of the user
Returns:
rating given by the given user
Throws:
RegistryException - if there is a problem

executeQuery

public Resource executeQuery(java.lang.String path,
                             java.util.Map parameters)
                      throws RegistryException
Description copied from interface: Registry
Executes a custom query which lives at the given path in the Registry.

Specified by:
executeQuery in interface Registry
Parameters:
path - Path of the query to execute.
parameters - a Map of query parameters (name -> value)
Returns:
RowSet containing the fields specified in the query.
Throws:
RegistryException - depends on the implementation.

getLogs

public LogEntry[] getLogs(java.lang.String resourcePath,
                          int action,
                          java.lang.String userName,
                          java.util.Date from,
                          java.util.Date to,
                          boolean recentFirst)
                   throws RegistryException
Description copied from interface: Registry
Returns the logs of the activities occured in the registy.

Specified by:
getLogs in interface Registry
Parameters:
resourcePath - If given, only the logs related to the resource path will be returned. If null, logs for all resources will be returned.
action - Only the logs pertaining to this action will be returned.
userName - If given, only the logs for activities done by the given user will be returned. If null, logs for all users will be returned.
from - If given, logs for activities occured after the given date will be returned. If null, there will not be a bound for the starting date.
to - If given, logs for activities occured before the given date will be returned. If null, there will not be a bound for the ending date.
recentFirst - If true, returned activities will be most-recent first. If false, returned activities will be oldest first.
Returns:
Array of LogEntry objects representing the logs
Throws:
RegistryException - if there is a problem


Copyright © 2007 Apache Web Services Project. All Rights Reserved.