* @param profile the supplied UserProfile
*/
public final void validateProfile( WikiContext context, UserProfile profile )
{
boolean isNew = profile.isNew();
WikiSession session = context.getWikiSession();
InputValidator validator = new InputValidator( SESSION_MESSAGES, context );
ResourceBundle rb = Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE );
//
// Query the SpamFilter first
//
FilterManager fm = m_engine.getFilterManager();
List<PageFilter> ls = fm.getFilterList();
for( PageFilter pf : ls )
{
if( pf instanceof SpamFilter )
{
if( ((SpamFilter)pf).isValidUserProfile( context, profile ) == false )
{
session.addMessage( SESSION_MESSAGES, "Invalid userprofile" );
return;
}
break;
}
}
// If container-managed auth and user not logged in, throw an error
if ( m_engine.getAuthenticationManager().isContainerAuthenticated()
&& !context.getWikiSession().isAuthenticated() )
{
session.addMessage( SESSION_MESSAGES, rb.getString("security.error.createprofilebeforelogin") );
}
validator.validateNotNull( profile.getLoginName(), rb.getString("security.user.loginname") );
validator.validateNotNull( profile.getFullname(), rb.getString("security.user.fullname") );
validator.validate( profile.getEmail(), rb.getString("security.user.email"), InputValidator.EMAIL );
// If new profile, passwords must match and can't be null
if ( !m_engine.getAuthenticationManager().isContainerAuthenticated() )
{
String password = profile.getPassword();
if ( password == null )
{
if ( isNew )
{
session.addMessage( SESSION_MESSAGES, rb.getString("security.error.blankpassword") );
}
}
else
{
HttpServletRequest request = context.getHttpRequest();
String password2 = ( request == null ) ? null : request.getParameter( "password2" );
if ( !password.equals( password2 ) )
{
session.addMessage( SESSION_MESSAGES, rb.getString("security.error.passwordnomatch") );
}
}
}
UserProfile otherProfile;
String fullName = profile.getFullname();
String loginName = profile.getLoginName();
// It's illegal to use as a full name someone else's login name
try
{
otherProfile = getUserDatabase().find( fullName );
if ( otherProfile != null && !profile.equals( otherProfile ) && !fullName.equals( otherProfile.getFullname() ) )
{
Object[] args = { fullName };
session.addMessage( SESSION_MESSAGES, MessageFormat.format( rb.getString("security.error.illegalfullname"),
args ) );
}
}
catch ( NoSuchPrincipalException e)
{ /* It's clean */ }
// It's illegal to use as a login name someone else's full name
try
{
otherProfile = getUserDatabase().find( loginName );
if ( otherProfile != null && !profile.equals( otherProfile ) && !loginName.equals( otherProfile.getLoginName() ) )
{
Object[] args = { loginName };
session.addMessage( SESSION_MESSAGES, MessageFormat.format( rb.getString("security.error.illegalloginname"),
args ) );
}
}
catch ( NoSuchPrincipalException e)
{ /* It's clean */ }