Spaces/Authorization Support
Spaces has a convenience implementation of authorization support that space providers can use if there are no special needs.
The implementation is found in the project "org.eclipse.spaces.core", and there is a test in "org.eclipse.spaces.test" (class "SpaceAuthroizationTest").
Storing Authorization Information
Here is an example of how to store authorization information for a space.
// A space URI URI address = URI.create("spaces:local://user@localhost/MySpace1"); // Lookup the space ISpace space = Spaces.getSpace(address); // Create a space resource for the entire space SpaceResource r = new SpaceResource(space); // Add the authorization information SpaceAuthorization.add(r, new BasicCredentials("fred", "secret"));
This adds information that user "fred" with password "secret" is authorization information for anything in the space (and below).
Getting Authorization Information
Here is an example how to obtain the authorization information:
// A space URI URI address = URI.create("spaces:local://user@localhost/MySpace1"); // Lookup the space ISpace space = Spaces.getSpace(address); // Create a space resource for the entire space SpaceResource r = new SpaceResource(space); BasicCredentials c = SpaceAuthorization.get(r, BasicCredentials.class); String login = c.getLogin(); Stirng password = c.getPassword();
The SpaceResource
The SpaceResource specifies the root of a resource tree. Here is the hierarchy
Area | Authorization for | Example |
---|---|---|
provider | provider, server, user, space, and all three areas flat, structured, and source | new SpaceResource(space, SpaceResource.Type.PROVIDER)
|
server | server, user, space, and all three areas flat, structured, and source | new SpaceResource(space, SpaceResource.Type.SERVER)
|
user | user, space, and all three areas flat, structured, and source | new SpaceResource(space, SpaceResource.Type.USER)
|
space | space, and all three areas flat, structured, and source | new SpaceResource(space) which is shorthand for: new SpaceResource(space, SpaceResource.Type.SPACE)
|
flat | the flat area of a space | new SpaceResource(space, SpaceResource.Type.FLAT)
|
structure | the structured area of a space | new SpaceResource(space, SpaceResource.Type.STRUCTURE)
|
source | the source area of a space | new SpaceResource(space, SpaceResource.Type.SOURCE)
|
When a request is made to get authroization information for a space resource, the information added for the exact match, or the closest enclosing area's information is returned.
This makes it possible to just add authroization information for the space, and still request information for flat, structure, and source individually. If no specific information has been defined for these areas, the information stored for the space will be returned.
The levels above space are useful when a user has one login/password for a larger group of spaces.