/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
*/
/**
* This class provides an implementation of an account status notification
* administrators whenever an account status notification occurs. The e-mail
* messages will be generated from template files, which contain the information
* to use to create the message body. The template files may contain plain
* text, in addition to the following tokens:
* <UL>
* <LI>%%notification-type%% -- Will be replaced with the name of the
* account status notification type for the notification.</LI>
* <LI>%%notification-message%% -- Will be replaced with the message for the
* account status notification.</LI>
* <LI>%%notification-user-dn%% -- Will be replaced with the string
* representation of the DN for the user that is the target of the
* account status notification.</LI>
* <LI>%%notification-user-attr:attrname%% -- Will be replaced with the value
* of the attribute specified by attrname from the user's entry. If the
* specified attribute has multiple values, then the first value
* encountered will be used. If the specified attribute does not have any
* values, then it will be replaced with an emtpy string.</LI>
* <LI>%%notification-property:propname%% -- Will be replaced with the value
* of the specified notification property from the account status
* notification. If the specified property has multiple values, then the
* first value encountered will be used. If the specified property does
* not have any values, then it will be replaced with an emtpy
* string.</LI>
* </UL>
*/
public class SMTPAccountStatusNotificationHandler
extends AccountStatusNotificationHandler
implements ConfigurationChangeListener
{
/**
* The tracer object for the debug logger.
*/
// A mapping between the notification types and the message template.
private HashMap<AccountStatusNotificationType,
// A mapping between the notification types and the message subject.
// The current configuration for this account status notification handler.
/**
* Creates a new, uninitialized instance of this account status notification
* handler.
*/
public SMTPAccountStatusNotificationHandler()
{
super();
}
/**
* {@inheritDoc}
*/
public void initializeStatusNotificationHandler(
{
// Make sure that the Directory Server is configured with information about
// one or more mail servers.
{
}
// Make sure that either an explicit recipient list or a set of email
// address attributes were provided.
{
}
}
/**
* Examines the provided configuration and parses the message subject
* information from it.
*
* @param configuration The configuration to be examined.
*
* @return A mapping between the account status notification type and the
* subject that should be used for messages generated for
* notifications with that type.
*
* @throws ConfigException If a problem occurs while parsing the subject
* configuration.
*/
throws ConfigException
{
{
if (colonPos < 0)
{
}
if (t == null)
{
throw new ConfigException(
}
else if (map.containsKey(t))
{
}
if (debugEnabled())
{
}
}
return map;
}
/**
* Examines the provided configuration and parses the message template
* information from it.
*
* @param configuration The configuration to be examined.
*
* @return A mapping between the account status notification type and the
* template that should be used to generate messages for
* notifications with that type.
*
* @throws ConfigException If a problem occurs while parsing the template
* configuration.
*/
private HashMap<AccountStatusNotificationType,
throws ConfigException
{
{
if (colonPos < 0)
{
}
if (t == null)
{
throw new ConfigException(
}
else if (map.containsKey(t))
{
}
if (! f.isAbsolute() )
{
path);
}
if (! f.exists())
{
}
if (debugEnabled())
{
t.getName());
}
}
return map;
}
/**
* Parses the specified template file into a list of notification message
* template elements.
*
* @param f A reference to the template file to be parsed.
*
* @return A list of notification message template elements parsed from the
* specified file.
*
* @throws ConfigException If error occurs while attempting to parse the
* template file.
*/
throws ConfigException
{
try
{
int lineNumber = 0;
while (true)
{
{
break;
}
if (debugEnabled())
{
}
lineNumber++;
int startPos = 0;
{
if (delimPos < 0)
{
if (debugEnabled())
{
}
break;
}
else
{
{
if (debugEnabled())
{
}
}
if (closeDelimPos < 0)
{
// There was an opening %% but not a closing one.
throw new ConfigException(
delimPos, lineNumber));
}
else
{
{
if (debugEnabled())
{
tokenStr);
}
}
{
if (debugEnabled())
{
tokenStr);
}
}
{
if (debugEnabled())
{
tokenStr);
}
}
{
{
throw new ConfigException(
}
else
{
if (debugEnabled())
{
tokenStr);
}
attrType));
}
}
{
{
throw new ConfigException(
}
else
{
if (debugEnabled())
{
}
property));
}
}
else
{
throw new ConfigException(
}
}
}
}
// We need to put a CRLF at the end of the line, as per the SMTP spec.
}
return elementList;
}
catch (Exception e)
{
if (debugEnabled())
{
}
f.getAbsolutePath(),
getExceptionMessage(e)));
}
finally
{
try
{
{
}
} catch (Exception e) {}
}
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationAcceptable(
{
}
/**
* {@inheritDoc}
*/
{
// First, see if the notification type is one that we handle. If not, then
// return without doing anything.
if (templateElements == null)
{
if (debugEnabled())
{
}
return;
}
// It is a notification that should be handled, so we can start generating
// the e-mail message. First, check to see if there are any mail attributes
// that would cause us to send a message to the end user.
{
for (AttributeType t : addressAttrs)
{
{
{
for (AttributeValue v : a)
{
if (debugEnabled())
{
a.getNameWithOptions());
}
}
}
}
}
if (recipients.isEmpty())
{
{
// There are no recipients at all, so there's no point in generating
// the message. Return without doing anything.
if (debugEnabled())
{
"recipients");
}
return;
}
else
{
if (! config.isSendMessageWithoutEndUserAddress())
{
// We can't send the message to the end user, and the handler is
// configured to not send only to administrators, so we shouln't
// do anything.
if (debugEnabled())
{
"without end user recipients");
}
return;
}
}
}
}
// Next, add any explicitly-defined recipients.
if (recipientAddrs != null)
{
if (debugEnabled())
{
for (String s : recipientAddrs)
{
}
}
}
// Get the message subject to use. If none is defined, then use a generic
// subject.
{
if (debugEnabled())
{
}
}
else if (debugEnabled())
{
}
// Generate the message body.
{
}
// Create and send the e-mail message.
if (debugEnabled())
{
}
try
{
if (debugEnabled())
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
getExceptionMessage(e)));
}
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
boolean configAcceptable = true;
// Make sure that the Directory Server is configured with information about
// one or more mail servers.
{
configAcceptable = false;
}
// Make sure that either an explicit recipient list or a set of email
// address attributes were provided.
{
configAcceptable = false;
}
try
{
}
catch (ConfigException ce)
{
if (debugEnabled())
{
}
configAcceptable = false;
}
try
{
}
catch (ConfigException ce)
{
if (debugEnabled())
{
}
configAcceptable = false;
}
return configAcceptable;
}
/**
* {@inheritDoc}
*/
{
try
{
}
catch (ConfigException ce)
{
if (debugEnabled())
{
}
}
}
}