org.cometd.bayeux.server
Interface Authorizer


public interface Authorizer

Authorizers authorize operations on channels.

Authorizers can be added to and ConfigurableServerChannel.removeAuthorizer(Authorizer) removed from} channels, even wildcard channels.

Authorizers work together with the SecurityPolicy to determine if a channel creation, a channel subscribe or a publish operation may succeed.

For an operation on a channel, the authorizers on the wildcard channels that match the channel and the authorizers on the channel itself (together known at the authorizers set for that channel) will be consulted to check if the the operation is granted, denied or ignored.
The list of wildcard channels that match the channel is obtained from ChannelId.getWilds().

The following is the authorization algorithm:

The order in which the authorizers are checked is not important.

Typically, authorizers are setup during the configuration of a channel:

 BayeuxServer bayeuxServer = ...;
 bayeuxServer.createIfAbsent("/television/cnn", new ConfigurableServerChannel.Initializer()
 {
     public void configureChannel(ConfigurableServerChannel channel)
     {
         // Grant subscribe to all
         channel.addAuthorizer(GrantAuthorizer.GRANT_SUBSCRIBE);

         // Grant publishes only to CNN employees
         channel.addAuthorizer(new Authorizer()
         {
             public Result authorize(Operation operation, ChannelId channel,
                                     ServerSession session, ServerMessage message)
             {
                 if (operation == Operation.PUBLISH &&
                         session.getAttribute("isCNNEmployee") == Boolean.TRUE)
                     return Result.grant();
                 else
                     return Result.ignore();
             }
         });
     }
 });
 

A typical usage of authorizers is as follows:

See Also:
SecurityPolicy, org.cometd.server.authorizer.GrantAuthorizer

Nested Class Summary
static class Authorizer.Operation
          Operations that are to be authorized on a channel
static class Authorizer.Result
          The result of an authentication request.
 
Method Summary
 Authorizer.Result authorize(Authorizer.Operation operation, ChannelId channel, ServerSession session, ServerMessage message)
          Callback invoked to authorize the given operation on the given channel.
 

Method Detail

authorize

Authorizer.Result authorize(Authorizer.Operation operation,
                            ChannelId channel,
                            ServerSession session,
                            ServerMessage message)

Callback invoked to authorize the given operation on the given channel.

Additional parameters are passed to this method as context parameters, so that it is possible to implement complex logic based on the ServerSession and ServerMessage that are requesting the authorization.

Note that the message channel is not the same as the channelId parameter. For example, for subscription requests, the message channel is Channel.META_SUBSCRIBE, while the channelId parameter is the channel for which the subscription is requested.

Note that for create operation, the channel instance does not yet exist: it will be created only after the authorization is granted.

Parameters:
operation - the operation to authorize
channel - the channel for which the authorization has been requested
session - the session that is requesting the authorization
message - the message that triggered the authorization request
Returns:
the result of the authorization


Copyright © 2008-2010 Dojo Foundation. All Rights Reserved.