XMLVirtualUserTablepublic class XMLVirtualUserTable extends AbstractVirtualUserTable Implements a Virtual User Table to translate virtual users
to real users. This implementation has the same functionality
as JDBCVirtualUserTable , but is configured in the
JAMES configuration and is thus probably most suitable for smaller
and less dynamic mapping requirements.
The configuration is specified in the form:
<mailet match="All" class="XMLVirtualUserTable">
<mapping>virtualuser@xxx=realuser[@yyy][;anotherrealuser[@zzz]]</mapping>
<mapping>virtualuser2@*=realuser2[@yyy][;anotherrealuser2[@zzz]]</mapping>
...
</mailet>
As many <mapping> elements can be added as necessary. As indicated,
wildcards are supported, and multiple recipients can be specified with a
semicolon-separated list. The target domain does not need to be specified if
the real user is local to the server.
Matching is done in the following order:
1. user@domain - explicit mapping for user@domain
2. user@* - catchall mapping for user anywhere
3. *@domain - catchall mapping for anyone at domain
4. null - no valid mapping |
Fields Summary |
---|
private Map | mappingsHolds the configured mappings |
Methods Summary |
---|
public java.lang.String | getMailetInfo()
return "XML Virtual User Table mailet";
| private java.lang.String | getTargetString(java.lang.String user, java.lang.String domain)Returns the real recipient given a virtual username and domain.
StringBuffer buf;
String target;
//Look for exact (user@domain) match
buf = new StringBuffer().append(user).append("@").append(domain);
target = (String)mappings.get(buf.toString());
if (target != null) {
return target;
}
//Look for user@* match
buf = new StringBuffer().append(user).append("@*");
target = (String)mappings.get(buf.toString());
if (target != null) {
return target;
}
//Look for *@domain match
buf = new StringBuffer().append("*@").append(domain);
target = (String)mappings.get(buf.toString());
if (target != null) {
return target;
}
return null;
| public void | init()Initialize the mailet
String mapping = getInitParameter("mapping");
if(mapping != null) {
StringTokenizer tokenizer = new StringTokenizer(mapping, ",");
while(tokenizer.hasMoreTokens()) {
String mappingItem = tokenizer.nextToken();
int index = mappingItem.indexOf('=");
String virtual = mappingItem.substring(0, index).trim().toLowerCase();
String real = mappingItem.substring(index + 1).trim().toLowerCase();
mappings.put(virtual, real);
}
}
| protected void | mapRecipients(java.util.Map recipientsMap)Map any virtual recipients to real recipients using the configured mapping.
Collection recipients = recipientsMap.keySet();
for (Iterator i = recipients.iterator(); i.hasNext(); ) {
MailAddress source = (MailAddress)i.next();
String user = source.getUser().toLowerCase();
String domain = source.getHost().toLowerCase();
String targetString = getTargetString(user, domain);
if (targetString != null) {
recipientsMap.put(source, targetString);
}
}
|
|