Name Generator
Introduction
The Activate Name Generator component allows you to generate and check for unique names using an easy, but sophisticated formatting mechanism. The name generator has the following major features:-
· Remove invalid characters from the name depending upon the rules for the type of name being generated.
· Check for uniqueness of the name and generate a unique name
· Format parts of the name into lower, upper and proper case
· Limit parts of the name and or the overall length of the name
Details
The name generator has a special format the is used to generate the next name of the sequence and this is then used to check for uniqueness depending upon the type of name. The name generator supports the following name types:-
· Login Names
· Email Addresses
· Common Names (CN)
Each of these name types has different rules on what is considered unique and what characters are valid. These are detailed below.
Multiple formats can be separated by a ";" to provide a fallback incase the first method does not generate a unique name.
Login Names
A login name is used for 'samAccountName' within Active Directory. It can be used for any object type in Active Directory that has a samAccountName. For example, Users, Groups and Contacts.
The following characters are considered invalid in login names are automatically stripped.
" \\/[]:;|=,+*?<>@\"'"
For example, "My+Name" would become "MyName".
Login names are unique within a forest and therefore must be unique across the entire first.
The system checks this by querying the Global Catalogue ("GC:").
Email Addresses
Email addresses are used to generate valid email addresses for Exchange. And can be used for any object that supports the proxyAddresses or mail attributes.
The format of email addresses is formally defined in RFC 5322 (mostly section 3.4.1) and by RFC 5321.
The local-part of the email address may use any of these ASCII characters:
· Uppercase and lowercase English letters (a–z, A–Z)
· Digits 0 to 9
· Characters ! # $ % & ' * + - / = ? ^ _ ` { | } ~
· Character . (dot, period, full stop) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively (e.g. [email protected]).
Any invalid characters are stripped. For example, ".wendy(fred)@activatelive.com" would become "[email protected]"
Email addresses must be unique within the forest and this is checked by checking the 'proxyAddresses' attribute in the global catalogue.
Common Names (CN)
A common name or CN is the name of an object in Active Directory. This function can be used for any object type that is valid in Active Directory.
Active Directory allows all characters in common names. However, some characters are reserved and must be escaped. For example, ',' is a reserved character and must be escaped when being used within LDAP. It is recommended that these characters not be used in common names, however this is not enforced.
A CN must be unique within its container within Active Directory. This generally means the organizationalUnit (OU) that the object is going to be created in. The name generate enforces this if an OU is specified.
Valid Characters
By default any character that is valid for the specified name type is allowed. This means that for example that ' is a valid character for email addresses. There are times you wish to restrict these further.
A type modifier can be used to further restrict these. These type modifiers can be combined to allow multiple classes of characters.
The valid modifiers are
'A' - Alpha characters only
'N' - Numeric characters only
'W' - Whitespace
For example:-
data/lastName:A - would allow Alpha characters only in the Last Name for the user.
data/lastName:ANW - would allow Alpha, Digits and Whitespaces characters only in the Last Name for the user.
Examples
The following are examples of generating different types of names. The following examples assumes the following data in the current arguments and job.
Description | Examples | Format |
|---|---|---|
First + Surname + # | WendyEvans WendyEvans2 | data/firstName|data/lastName|{#} |
First + "." + Surname + # | WendyEvans Wendy.Evens2 | data/firstName|"."|data/lastName|{#} |
First letter for firstName + Surname + # | WEvans WEvans2 | data/firstName:1|data/lastName|{#} |
First + Surname + Digit (always have a number starting at 1) | WendyEvans1 WendyEvans2 | data/firstName:1|data/lastName|{#:-1} |
First+ Surname to max of 6 characters + # | WendyE WendyE2 | {data/firstname|data/lastName}:6|{#} |
surname + First name (enough chars of first name) + # (This will always have the first letter of the first name) | EvansW EvansWe EvansWen | data/lastName|data/firstName:1+|{#}
|
FirstName (+ Surname if required) + # | Wendy WendyE WendyEv | data/firstName|data/lastName:0+|{#} |
Enough of first name + surname Add Initial is still not unique Add Numbers | WEvans WeEvans ... WendyEvans WendyHEvans WendyHEvans2 | data/firstName:1+|data/lastName; data/firstName|data/initial|data/lastName{#} |
Firstname + last Name with max of 8 characters (including number) | WendyEva WendyEv2 ... WendyE10 | {data/firstName|data/lastName|{#}}:8 |
Same as last on expect upper case | WENDYEVA WENDYEV2 ... WENDYE10 | {data/firstName|data/lastName|{#}}:u,8 |
First name upper case and last name proper case | WENDYEvans WENDYEvans2 | data/firstName:u|data/lastName:p|{#} |
Note: The '#' in the description means that a number should be added if there is a duplicate.
The following test script can be used to test and display the first 20 matches.
using System;
using Innovation.Activate;
using Innovation.Activate.Utilities;
class Script : ScriptBase
{
public void main()
{
string format = "data/firstName|data/lastName|{#}";
NameGenerator g = new NameGenerator(format, NameGenerator.ValidCharacters.LoginName);
Job j = new Job();
j.Task = Evaluator.GetObject("=//Tasks/User/Create User") as Task;
j.Arguments.SetValue("data/firstName", "wendy");
j.Arguments.SetValue("data/lastName", "evans");
j.Arguments.SetValue("data/initial", "H");
j.Arguments.SetValue("data/prefix", "ven");
for (int i = 0; i < 20; i++)
Trace.WriteLine(g.GetNextUserName(j, j.Arguments.Root));
}
}
Appendix 1: Formal Grammar Specification
The following section outlines the formal grammar and specification for the name generator.
NamePartExpr:-
NamePart
|
NamePart ; [NamePart] NamePart:-
" string " -- static
|
{ expr } Format
|
bindPath
|
{ # [:startNumber] [+] }
|
{ # [:-startNumber] [+] } -- always force a number
Format:-
""
|
: [Type], [MaxLength]
Type:-
L l -- lower case
|
U u -- upper case
|
P p -- upper case first char
|
A a -- allow Alpha characters only
|
N n -- Allow digits only
|
W w -- Allow Whitespace
MaxLength:-
integer