org.blojsom.plugin.registration
Class RegistrationPlugin

java.lang.Object
  extended byorg.blojsom.plugin.admin.BaseAdminPlugin
      extended byorg.blojsom.plugin.registration.RegistrationPlugin
All Implemented Interfaces:
PermissionedPlugin, Plugin

public class RegistrationPlugin
extends BaseAdminPlugin

This plugin allows users to register for an account on the blog. Can be combined with various authorization plugins to force users to login before they can access the blog.

Version:
$Id: RegistrationPlugin.java,v 1.2 2007/01/17 02:35:05 czarneckid Exp $
Author:
Eric Broyles

Field Summary
protected static java.lang.String REGISTRATION_MESSAGES_RESOURCE
           
 
Fields inherited from class org.blojsom.plugin.admin.BaseAdminPlugin
_authorizationProvider, _ignoreParams, _resourceManager, _servletConfig, ACTION_PARAM, ADMIN_ADMINISTRATION_PAGE, ADMIN_AJAX_RESPONSE, ADMIN_LOGIN_PAGE, BLOJSOM_ADMIN_MESSAGES_RESOURCE, BLOJSOM_ADMIN_PLUGIN_AUTHENTICATED_KEY, BLOJSOM_ADMIN_PLUGIN_OPERATION_RESULT, BLOJSOM_ADMIN_PLUGIN_PASSWORD_PARAM, BLOJSOM_ADMIN_PLUGIN_USERNAME, BLOJSOM_ADMIN_PLUGIN_USERNAME_KEY, BLOJSOM_ADMIN_PLUGIN_USERNAME_PARAM, BLOJSOM_PERMISSION_CHECKER, BLOJSOM_USER_AUTHENTICATED, LOGIN_ACTION, LOGIN_ERROR_TEXT_KEY, LOGOUT_ACTION, PAGE_ACTION, PLUGIN_ADMIN_INHERIT_APACHE_CREDENTIALS, SUBACTION_PARAM
 
Constructor Summary
RegistrationPlugin()
           
 
Method Summary
protected  void addUserMetaData(javax.servlet.http.HttpServletRequest httpServletRequest, Blog blog, java.util.Map context, User user, java.lang.String metaDataPropertyKeys, boolean isRequired)
          Add metadata to the user.
 void cleanup()
          Perform any cleanup for the plugin.
protected  Notification constructEmail(Blog blog, User user, java.lang.String flavor)
          Construct an email notification to the user with their registration details.
 void destroy()
          Called when BlojsomServlet is taken out of service
protected  java.lang.String formatRegistrationResource(java.lang.String resourceID, java.lang.String fallbackText, java.util.Locale locale, java.lang.Object[] arguments)
          Retrieve a resource from the registration resource bundle and pass it through the ResourceManager.format(String,Object[]) method
protected  java.lang.String getRegistrationResource(java.lang.String resourceID, java.lang.String fallbackText, java.util.Locale locale)
          Retrieve a resource from the registration resource bundle
 void init()
          Initialize this plugin.
protected  void notifyOfFailedRegistration(java.lang.String username, java.util.Map context, Blog blog, javax.servlet.http.HttpServletRequest httpServletRequest)
          Notify the user that their registration has failed for some reason.
protected  void notifyOfMissingParameter(java.lang.String parameterName, java.util.Map context, Blog blog, javax.servlet.http.HttpServletRequest httpServletRequest)
          Notify the user that a required registration parameter is missing.
 Entry[] process(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Blog blog, java.util.Map context, Entry[] entries)
          Process the blog entries
 void setFetcher(Fetcher fetcher)
          Set the Fetcher.
protected  void setupEmail(Blog blog, User user, org.apache.commons.mail.Email email)
          Setup an email for the given Blog and User.
 
Methods inherited from class org.blojsom.plugin.admin.BaseAdminPlugin
addOperationResultMessage, authenticateUser, checkPermission, formatAdminResource, getAdminResource, getUsernameFromSession, setAuthorizationProvider, setResourceManager, setServletConfig
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REGISTRATION_MESSAGES_RESOURCE

protected static final java.lang.String REGISTRATION_MESSAGES_RESOURCE
See Also:
Constant Field Values
Constructor Detail

RegistrationPlugin

public RegistrationPlugin()
Method Detail

setFetcher

public void setFetcher(Fetcher fetcher)
Set the Fetcher. Usually injected by Spring.

Parameters:
fetcher - Fetcher

init

public void init()
          throws PluginException
Description copied from class: BaseAdminPlugin
Initialize this plugin. This method only called when the plugin is instantiated.

Specified by:
init in interface Plugin
Overrides:
init in class BaseAdminPlugin
Throws:
PluginException - If there is an error initializing the plugin
See Also:
BaseAdminPlugin.init()

setupEmail

protected void setupEmail(Blog blog,
                          User user,
                          org.apache.commons.mail.Email email)
                   throws org.apache.commons.mail.EmailException
Setup an email for the given Blog and User. Sets the from address to the blog owner's email address and the blog's name. Sets the to address to the user's email address and the blog owner's email address.

Parameters:
blog - Blog
user - User
email - E-mail message
Throws:
org.apache.commons.mail.EmailException - If there is an error setting e-mail attributes

process

public Entry[] process(javax.servlet.http.HttpServletRequest httpServletRequest,
                       javax.servlet.http.HttpServletResponse httpServletResponse,
                       Blog blog,
                       java.util.Map context,
                       Entry[] entries)
                throws PluginException
Description copied from class: BaseAdminPlugin
Process the blog entries

Specified by:
process in interface Plugin
Overrides:
process in class BaseAdminPlugin
Parameters:
httpServletRequest - Request
httpServletResponse - Response
blog - Blog instance
context - Context
entries - Blog entries retrieved for the particular request
Returns:
Modified set of blog entries
Throws:
PluginException - If there is an error processing the blog entries
See Also:
BaseAdminPlugin.process(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,org.blojsom.blog.Blog,java.util.Map,org.blojsom.blog.Entry[])

addUserMetaData

protected void addUserMetaData(javax.servlet.http.HttpServletRequest httpServletRequest,
                               Blog blog,
                               java.util.Map context,
                               User user,
                               java.lang.String metaDataPropertyKeys,
                               boolean isRequired)
                        throws MissingParameterException
Add metadata to the user. If the metadata is required and it's not present the user will be notified that required data is missing.

Parameters:
httpServletRequest - the request
blog - the Blog
context - Context
user - the user who's registering
metaDataPropertyKeys - the keys used to access the metadata values from the context
isRequired - If the metadata is required
Throws:
MissingParameterException - when a required parameter is missing

cleanup

public void cleanup()
             throws PluginException
Description copied from class: BaseAdminPlugin
Perform any cleanup for the plugin. Called after BaseAdminPlugin.process(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.blojsom.blog.Blog, java.util.Map, org.blojsom.blog.Entry[]).

Specified by:
cleanup in interface Plugin
Overrides:
cleanup in class BaseAdminPlugin
Throws:
PluginException - If there is an error performing cleanup for this plugin
See Also:
BaseAdminPlugin.cleanup()

destroy

public void destroy()
             throws PluginException
Description copied from class: BaseAdminPlugin
Called when BlojsomServlet is taken out of service

Specified by:
destroy in interface Plugin
Overrides:
destroy in class BaseAdminPlugin
Throws:
PluginException - If there is an error in finalizing this plugin
See Also:
BaseAdminPlugin.destroy()

constructEmail

protected Notification constructEmail(Blog blog,
                                      User user,
                                      java.lang.String flavor)
                               throws org.apache.commons.mail.EmailException,
                                      javax.mail.MessagingException
Construct an email notification to the user with their registration details.

Parameters:
blog - Blog
user - User
flavor - Flavor
Returns:
the Notification
Throws:
org.apache.commons.mail.EmailException - If there is an error setting e-mail attributes
javax.mail.MessagingException - If there is an error sending the e-mail

formatRegistrationResource

protected java.lang.String formatRegistrationResource(java.lang.String resourceID,
                                                      java.lang.String fallbackText,
                                                      java.util.Locale locale,
                                                      java.lang.Object[] arguments)
Retrieve a resource from the registration resource bundle and pass it through the ResourceManager.format(String,Object[]) method

Parameters:
resourceID - ID of resource to retrieve
fallbackText - Text to use as fallback if resource ID is not found
locale - Locale to use when retrieving resource
arguments - Arguments for ResourceManager.format(String,Object[])
Returns:
Text from administration resource bundle given by resourceID formatted appropriately or fallbackText if the resource ID could not be formatted

getRegistrationResource

protected java.lang.String getRegistrationResource(java.lang.String resourceID,
                                                   java.lang.String fallbackText,
                                                   java.util.Locale locale)
Retrieve a resource from the registration resource bundle

Parameters:
resourceID - ID of resource to retrieve
fallbackText - Text to use as fallback if resource ID is not found
locale - Locale to use when retrieving resource
Returns:
Text from administration resource bundle given by resourceID or fallbackText if the resource ID is not found

notifyOfMissingParameter

protected void notifyOfMissingParameter(java.lang.String parameterName,
                                        java.util.Map context,
                                        Blog blog,
                                        javax.servlet.http.HttpServletRequest httpServletRequest)
Notify the user that a required registration parameter is missing.

Parameters:
parameterName - the name of the missing parameter
context - Context
blog - the Blog
httpServletRequest - the request

notifyOfFailedRegistration

protected void notifyOfFailedRegistration(java.lang.String username,
                                          java.util.Map context,
                                          Blog blog,
                                          javax.servlet.http.HttpServletRequest httpServletRequest)
Notify the user that their registration has failed for some reason.

Parameters:
username - the username of the user for which registration failed
context - Context
blog - the Blog
httpServletRequest - the request