org.apache.felix.useradmin.impl
Class UserAdminServiceImpl

java.lang.Object
  extended by org.apache.felix.useradmin.impl.UserAdminServiceImpl
All Implemented Interfaces:
ServiceFactory, UserAdmin

public class UserAdminServiceImpl
extends Object
implements UserAdmin, ServiceFactory

This UserAdminServiceImpl class implementing a contract UserAdmin. It represents UserAdmin service is exposed as a OSGi service in the ServiceRegistry.

Its used to manage a database of named Role objects, which can be used for authentication and authorization purposes. This version of the User Admin service defines two types of Role objects: User and Group. Each type of role is represented by an int constant and an interface. The range of positive integers is reserved for new types of roles that may be added in the future. When defining proprietary role types, negative constant values must be used. Every role has a name and a type. A User object can be configured with credentials (e.g., a password) and properties (e.g., a street address, phone number, etc.). A Group object represents an aggregation of User and Group objects. In other words, the members of a Group object are roles themselves. Every User Admin service manages and maintains its own namespace of Role objects, in which each Role object has a unique name.

Version:
$Rev$ $Date$
See Also:
UserAdmin, ServiceFactory, UserAdminRepositoryManager, UserAdminEventDispatcher

Constructor Summary
UserAdminServiceImpl(BundleContext bc, UserAdminRepositoryManager repositoryManager, Logger logger, UserAdminEventDispatcher dispatcher)
          This constructor is creating new UserAdmin service.
 
Method Summary
 void checkPermission(UserAdminPermission permission)
          Checking permission with security manager.
 Role createRole(String name, int type)
          Creates a Role object with the given name and of the given type.
 void destroy()
           This method is closing UserAdmin resources.
 CredentialAuthenticator getAuthenticator()
          This method returns CredentialAuthenticator instance.
 Authorization getAuthorization(User user)
          Creates an Authorization object that encapsulates the specified User object and the Role objects it possesses.
 UserAdminEventDispatcher getEventAdminDispatcher()
          This method returns UserAdminEvent dispatcher.
 UserAdminRepositoryManager getRepositoryManager()
          This method returns repository manager instance.
 Role getRole(String name)
          Gets the Role object with the given name from this User Admin service.
 Role[] getRoles(String filter)
          Gets the Role objects managed by this User Admin service that have properties matching the specified LDAP filter criteria.
 Object getService(Bundle bundle, ServiceRegistration reg)
          Creates a new service object.
 ServiceReference getServiceRef()
          This method returns ServiceReference for this service needed for UserAdminEvent.
 User getUser(String key, String value)
          Gets the user with the given property key-value pair from the User Admin service database.
 UserAdminPermission getUserAdminPermission()
          This method returns UserAdminPermission with name admin.
 boolean isAlive()
          Checks if UserAdmin service is alive.
 boolean removeRole(String name)
          Removes the Role object with the given name from this User Admin service and all groups it is a member of.
 void setServiceRef(ServiceReference serviceRef)
          This method is used for setting ServiceReference of this service.
 void ungetService(Bundle bundle, ServiceRegistration reg, Object obj)
          Releases a service object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserAdminServiceImpl

public UserAdminServiceImpl(BundleContext bc,
                            UserAdminRepositoryManager repositoryManager,
                            Logger logger,
                            UserAdminEventDispatcher dispatcher)
This constructor is creating new UserAdmin service.

Parameters:
bc - BundleContext of a bundle which creating this service instance.
repositoryManager - repository manager.
logger - Logger instance.
dispatcher - UserAdmin event dispatcher instance.
Method Detail

createRole

public Role createRole(String name,
                       int type)
Description copied from interface: UserAdmin
Creates a Role object with the given name and of the given type.

If a Role object was created, a UserAdminEvent object of type UserAdminEvent.ROLE_CREATED is broadcast to any UserAdminListener object.

Specified by:
createRole in interface UserAdmin
Parameters:
name - The name of the Role object to create.
type - The type of the Role object to create. Must be either a Role.USER type or Role.GROUP type.
Returns:
The newly created Role object, or null if a role with the given name already exists.
See Also:
UserAdmin.createRole(String, int)

checkPermission

public void checkPermission(UserAdminPermission permission)
Checking permission with security manager. If the caller thread doesn't have permission it throwing SecurityException.

Parameters:
permission - UserAdminPermission for which check will e performed.
See Also:
SecurityManager.checkPermission(java.security.Permission)

getAuthorization

public Authorization getAuthorization(User user)
Description copied from interface: UserAdmin
Creates an Authorization object that encapsulates the specified User object and the Role objects it possesses. The null user is interpreted as the anonymous user. The anonymous user represents a user that has not been authenticated. An Authorization object for an anonymous user will be unnamed, and will only imply groups that user.anyone implies.

Specified by:
getAuthorization in interface UserAdmin
Parameters:
user - The User object to create an Authorization object for, or null for the anonymous user.
Returns:
the Authorization object for the specified User object.
See Also:
UserAdmin.getAuthorization(User)

getRole

public Role getRole(String name)
Description copied from interface: UserAdmin
Gets the Role object with the given name from this User Admin service.

Specified by:
getRole in interface UserAdmin
Parameters:
name - The name of the Role object to get.
Returns:
The requested Role object, or null if this User Admin service does not have a Role object with the given name.
See Also:
UserAdmin.getRole(String)

getRoles

public Role[] getRoles(String filter)
                throws InvalidSyntaxException
Description copied from interface: UserAdmin
Gets the Role objects managed by this User Admin service that have properties matching the specified LDAP filter criteria. See org.osgi.framework.Filter for a description of the filter syntax. If a null filter is specified, all Role objects managed by this User Admin service are returned.

Specified by:
getRoles in interface UserAdmin
Parameters:
filter - The filter criteria to match.
Returns:
The Role objects managed by this User Admin service whose properties match the specified filter criteria, or all Role objects if a null filter is specified. If no roles match the filter, null will be returned.
Throws:
InvalidSyntaxException - If the filter is not well formed.
See Also:
UserAdmin.getRoles(String), Filter

getUser

public User getUser(String key,
                    String value)
Description copied from interface: UserAdmin
Gets the user with the given property key-value pair from the User Admin service database. This is a convenience method for retrieving a User object based on a property for which every User object is supposed to have a unique value (within the scope of this User Admin service), such as for example a X.500 distinguished name.

Specified by:
getUser in interface UserAdmin
Parameters:
key - The property key to look for.
value - The property value to compare with.
Returns:
A matching user, if exactly one is found. If zero or more than one matching users are found, null is returned.
See Also:
UserAdmin.getUser(String, String)

removeRole

public boolean removeRole(String name)
Description copied from interface: UserAdmin
Removes the Role object with the given name from this User Admin service and all groups it is a member of.

If the Role object was removed, a UserAdminEvent object of type UserAdminEvent.ROLE_REMOVED is broadcast to any UserAdminListener object.

Specified by:
removeRole in interface UserAdmin
Parameters:
name - The name of the Role object to remove.
Returns:
true If a Role object with the given name is present in this User Admin service and could be removed, otherwise false.
See Also:
UserAdmin.removeRole(String)

getService

public Object getService(Bundle bundle,
                         ServiceRegistration reg)
Description copied from interface: ServiceFactory
Creates a new service object.

The Framework invokes this method the first time the specified bundle requests a service object using the BundleContext.getService(ServiceReference) method. The service factory can then return a specific service object for each bundle.

The Framework caches the value returned (unless it is null), and will return the same service object on any future call to BundleContext.getService for the same bundle. This means the Framework must not allow this method to be concurrently called for the same bundle.

The Framework will check if the returned service object is an instance of all the classes named when the service was registered. If not, then null is returned to the bundle.

Specified by:
getService in interface ServiceFactory
Parameters:
bundle - The bundle using the service.
reg - The ServiceRegistration object for the service.
Returns:
A service object that must be an instance of all the classes named when the service was registered.
See Also:
ServiceFactory.ungetService(Bundle, ServiceRegistration, Object)

ungetService

public void ungetService(Bundle bundle,
                         ServiceRegistration reg,
                         Object obj)
Description copied from interface: ServiceFactory
Releases a service object.

The Framework invokes this method when a service has been released by a bundle. The service object may then be destroyed.

Specified by:
ungetService in interface ServiceFactory
Parameters:
bundle - The bundle releasing the service.
reg - The ServiceRegistration object for the service.
obj - The service object returned by a previous call to the ServiceFactory.getService method.
See Also:
ServiceFactory.ungetService(Bundle, ServiceRegistration, Object)

destroy

public void destroy()

This method is closing UserAdmin resources. Should be used when UserAdmin service is unregistred. Alive flag is set to true, eventDispacther is closed and ServiceReference is set to null.


isAlive

public boolean isAlive()
Checks if UserAdmin service is alive.

Returns:
true if service is alive or false if not.

setServiceRef

public void setServiceRef(ServiceReference serviceRef)
This method is used for setting ServiceReference of this service.

Parameters:
serviceRef - ServiceReference of this service.

getServiceRef

public ServiceReference getServiceRef()
This method returns ServiceReference for this service needed for UserAdminEvent.

Returns:
ServiceReference for this service.

getUserAdminPermission

public UserAdminPermission getUserAdminPermission()
This method returns UserAdminPermission with name admin.

Returns:
UserAdmingPermission with name admin.

getEventAdminDispatcher

public UserAdminEventDispatcher getEventAdminDispatcher()
This method returns UserAdminEvent dispatcher.

Returns:
UserAdminEventDispatcher
See Also:
UserAdminEventDispatcher

getRepositoryManager

public UserAdminRepositoryManager getRepositoryManager()
This method returns repository manager instance.

Returns:
repository manager instance.

getAuthenticator

public CredentialAuthenticator getAuthenticator()
This method returns CredentialAuthenticator instance.

Returns:
CredentialAuthenticator instance.


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.