1 package org.apache.archiva.redback.rest.services;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import net.sf.ehcache.CacheManager;
23 import org.apache.archiva.redback.authentication.AuthenticationException;
24 import org.apache.archiva.redback.authentication.TokenBasedAuthenticationDataSource;
25 import org.apache.archiva.redback.components.cache.Cache;
26 import org.apache.archiva.redback.configuration.UserConfiguration;
27 import org.apache.archiva.redback.configuration.UserConfigurationKeys;
28 import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
29 import org.apache.archiva.redback.integration.mail.Mailer;
30 import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
31 import org.apache.archiva.redback.keys.AuthenticationKey;
32 import org.apache.archiva.redback.keys.KeyManager;
33 import org.apache.archiva.redback.keys.KeyManagerException;
34 import org.apache.archiva.redback.keys.KeyNotFoundException;
35 import org.apache.archiva.redback.policy.AccountLockedException;
36 import org.apache.archiva.redback.policy.MustChangePasswordException;
37 import org.apache.archiva.redback.policy.PasswordEncoder;
38 import org.apache.archiva.redback.policy.UserSecurityPolicy;
39 import org.apache.archiva.redback.rbac.RBACManager;
40 import org.apache.archiva.redback.rbac.RbacManagerException;
41 import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
42 import org.apache.archiva.redback.rbac.UserAssignment;
43 import org.apache.archiva.redback.rest.api.model.ErrorMessage;
44 import org.apache.archiva.redback.rest.api.model.Operation;
45 import org.apache.archiva.redback.rest.api.model.Permission;
46 import org.apache.archiva.redback.rest.api.model.RegistrationKey;
47 import org.apache.archiva.redback.rest.api.model.ResetPasswordRequest;
48 import org.apache.archiva.redback.rest.api.model.Resource;
49 import org.apache.archiva.redback.rest.api.model.User;
50 import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
51 import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
52 import org.apache.archiva.redback.rest.api.services.UserService;
53 import org.apache.archiva.redback.rest.services.utils.PasswordValidator;
54 import org.apache.archiva.redback.role.RoleManager;
55 import org.apache.archiva.redback.role.RoleManagerException;
56 import org.apache.archiva.redback.system.SecuritySystem;
57 import org.apache.archiva.redback.users.UserManager;
58 import org.apache.archiva.redback.users.UserManagerException;
59 import org.apache.archiva.redback.users.UserNotFoundException;
60 import org.apache.commons.lang.StringUtils;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
63 import org.springframework.stereotype.Service;
65 import javax.inject.Inject;
66 import javax.inject.Named;
67 import javax.mail.internet.AddressException;
68 import javax.mail.internet.InternetAddress;
69 import javax.servlet.http.HttpServletRequest;
70 import javax.ws.rs.core.Context;
71 import javax.ws.rs.core.Response;
72 import java.util.ArrayList;
73 import java.util.Arrays;
74 import java.util.Collection;
75 import java.util.List;
78 @Service( "userService#rest" )
79 public class DefaultUserService
80 implements UserService
83 private Logger log = LoggerFactory.getLogger( getClass() );
85 private static final String VALID_USERNAME_CHARS = "[a-zA-Z_0-9\\-.@]*";
87 private UserManager userManager;
89 private SecuritySystem securitySystem;
92 @Named( value = "userConfiguration#default" )
93 private UserConfiguration config;
96 private RoleManager roleManager;
99 * cache used for user assignments
102 @Named( value = "cache#userAssignments" )
103 private Cache userAssignmentsCache;
106 * cache used for user permissions
109 @Named( value = "cache#userPermissions" )
110 private Cache userPermissionsCache;
113 * Cache used for users
116 @Named( value = "cache#users" )
117 private Cache usersCache;
120 private Mailer mailer;
123 @Named( value = "rbacManager#default" )
124 private RBACManager rbacManager;
126 private HttpAuthenticator httpAuthenticator;
129 private PasswordValidator passwordValidator;
132 private HttpServletRequest httpServletRequest;
135 public DefaultUserService( @Named( value = "userManager#cached" ) UserManager userManager,
136 SecuritySystem securitySystem,
137 @Named( "httpAuthenticator#basic" ) HttpAuthenticator httpAuthenticator )
139 this.userManager = userManager;
140 this.securitySystem = securitySystem;
141 this.httpAuthenticator = httpAuthenticator;
145 public Boolean createUser( User user )
146 throws RedbackServiceException
151 org.apache.archiva.redback.users.User u = userManager.findUser( user.getUsername() );
154 throw new RedbackServiceException(
155 new ErrorMessage( "user " + user.getUsername() + " already exists" ) );
158 catch ( UserNotFoundException e )
160 //ignore we just want to prevent non human readable error message from backend :-)
161 log.debug( "user {} not exists", user.getUsername() );
163 catch ( UserManagerException e )
165 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
169 if ( StringUtils.isEmpty( user.getUsername() ) )
171 throw new RedbackServiceException( new ErrorMessage( "username cannot be empty" ) );
174 if ( StringUtils.isEmpty( user.getFullName() ) )
176 throw new RedbackServiceException( new ErrorMessage( "fullName cannot be empty" ) );
179 if ( StringUtils.isEmpty( user.getEmail() ) )
181 throw new RedbackServiceException( new ErrorMessage( "email cannot be empty" ) );
187 org.apache.archiva.redback.users.User u =
188 userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
189 u.setPassword( user.getPassword() );
190 u.setLocked( user.isLocked() );
191 u.setPasswordChangeRequired( user.isPasswordChangeRequired() );
192 u.setPermanent( user.isPermanent() );
193 u.setValidated( user.isValidated() );
194 u = userManager.addUser( u );
195 if ( !user.isPasswordChangeRequired() )
197 u.setPasswordChangeRequired( false );
200 u = userManager.updateUser( u );
201 log.debug( "user {} created", u.getUsername() );
203 catch ( UserNotFoundException e )
205 throw new RedbackServiceException( e.getMessage() );
209 roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
211 catch ( RoleManagerException rpe )
213 log.error( "RoleProfile Error: " + rpe.getMessage(), rpe );
214 throw new RedbackServiceException( new ErrorMessage( "assign.role.failure", null ) );
216 catch ( UserManagerException e )
218 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
223 public Boolean deleteUser( String username )
224 throws RedbackServiceException
230 if ( rbacManager.userAssignmentExists( username ) )
232 UserAssignment assignment = rbacManager.getUserAssignment( username );
233 rbacManager.removeUserAssignment( assignment );
237 catch ( RbacManagerException e )
239 log.error( e.getMessage(), e );
240 throw new RedbackServiceException( e.getMessage() );
244 userManager.deleteUser( username );
247 catch ( UserNotFoundException e )
249 log.error( e.getMessage(), e );
250 throw new RedbackServiceException( e.getMessage() );
252 catch ( UserManagerException e )
254 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
258 removeFromCache( username );
263 public User getUser( String username )
264 throws RedbackServiceException
268 org.apache.archiva.redback.users.User user = userManager.findUser( username );
269 return getSimpleUser( user );
271 catch ( UserNotFoundException e )
275 catch ( UserManagerException e )
277 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
281 public List<User> getUsers()
282 throws RedbackServiceException
286 List<org.apache.archiva.redback.users.User> users = userManager.getUsers();
287 List<User> simpleUsers = new ArrayList<User>( users.size() );
289 for ( org.apache.archiva.redback.users.User user : users )
291 simpleUsers.add( getSimpleUser( user ) );
296 catch ( UserManagerException e )
298 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
302 public Boolean updateMe( User user )
303 throws RedbackServiceException
305 // check username == one in the session
306 RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
307 if ( redbackRequestInformation == null || redbackRequestInformation.getUser() == null )
309 throw new RedbackServiceException( new ErrorMessage( "you must be logged to update your profile" ),
310 Response.Status.FORBIDDEN.getStatusCode() );
314 throw new RedbackServiceException( new ErrorMessage( "user parameter is mandatory" ),
315 Response.Status.BAD_REQUEST.getStatusCode() );
317 if ( !StringUtils.equals( redbackRequestInformation.getUser().getUsername(), user.getUsername() ) )
319 throw new RedbackServiceException( new ErrorMessage( "you can update only your profile" ),
320 Response.Status.FORBIDDEN.getStatusCode() );
323 if ( StringUtils.isEmpty( user.getPreviousPassword() ) )
325 throw new RedbackServiceException( new ErrorMessage( "previous password is empty" ),
326 Response.Status.BAD_REQUEST.getStatusCode() );
329 User realUser = getUser( user.getUsername() );
332 String previousEncodedPassword =
333 securitySystem.getUserManager().findUser( user.getUsername() ).getEncodedPassword();
335 // check oldPassword with the current one
337 PasswordEncoder encoder = securitySystem.getPolicy().getPasswordEncoder();
339 if ( !encoder.isPasswordValid( previousEncodedPassword, user.getPreviousPassword() ) )
342 throw new RedbackServiceException( new ErrorMessage( "password.provided.does.not.match.existing" ),
343 Response.Status.BAD_REQUEST.getStatusCode() );
346 catch ( UserNotFoundException e )
348 throw new RedbackServiceException( new ErrorMessage( "user not found" ),
349 Response.Status.BAD_REQUEST.getStatusCode() );
351 catch ( UserManagerException e )
353 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
355 // only 3 fields to update
356 realUser.setFullName( user.getFullName() );
357 realUser.setEmail( user.getEmail() );
358 // ui can limit to not update password
359 if ( StringUtils.isNotBlank( user.getPassword() ) )
361 passwordValidator.validatePassword( user.getPassword(), user.getUsername() );
363 realUser.setPassword( user.getPassword() );
366 updateUser( realUser );
371 public Boolean updateUser( User user )
372 throws RedbackServiceException
376 org.apache.archiva.redback.users.User rawUser = userManager.findUser( user.getUsername() );
377 rawUser.setFullName( user.getFullName() );
378 rawUser.setEmail( user.getEmail() );
379 rawUser.setValidated( user.isValidated() );
380 rawUser.setLocked( user.isLocked() );
381 rawUser.setPassword( user.getPassword() );
382 rawUser.setPasswordChangeRequired( user.isPasswordChangeRequired() );
383 rawUser.setPermanent( user.isPermanent() );
385 userManager.updateUser( rawUser );
388 catch ( UserNotFoundException e )
390 throw new RedbackServiceException( e.getMessage() );
392 catch ( UserManagerException e )
394 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
398 public int removeFromCache( String userName )
399 throws RedbackServiceException
401 if ( userAssignmentsCache != null )
403 userAssignmentsCache.remove( userName );
405 if ( userPermissionsCache != null )
407 userPermissionsCache.remove( userName );
409 if ( usersCache != null )
411 usersCache.remove( userName );
414 CacheManager cacheManager = CacheManager.getInstance();
415 String[] caches = cacheManager.getCacheNames();
416 for ( String cacheName : caches )
418 if ( StringUtils.startsWith( cacheName, "org.apache.archiva.redback.rbac.jdo" ) )
420 cacheManager.getCache( cacheName ).removeAll();
427 public User getGuestUser()
428 throws RedbackServiceException
432 org.apache.archiva.redback.users.User user = userManager.getGuestUser();
433 return getSimpleUser( user );
435 catch ( Exception e )
441 public User createGuestUser()
442 throws RedbackServiceException
444 User u = getGuestUser();
449 // temporary disable policy during guest creation as no password !
452 securitySystem.getPolicy().setEnabled( false );
453 org.apache.archiva.redback.users.User user = userManager.createGuestUser();
454 user.setPasswordChangeRequired( false );
455 user = userManager.updateUser( user, false );
456 roleManager.assignRole( config.getString( UserConfigurationKeys.DEFAULT_GUEST ), user.getUsername() );
457 return getSimpleUser( user );
459 catch ( RoleManagerException e )
461 log.error( e.getMessage(), e );
462 throw new RedbackServiceException( e.getMessage() );
464 catch ( UserNotFoundException e )
466 // olamy I wonder how this can happen :-)
467 log.error( e.getMessage(), e );
468 throw new RedbackServiceException( e.getMessage() );
470 catch ( UserManagerException e )
472 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
477 if ( !securitySystem.getPolicy().isEnabled() )
479 securitySystem.getPolicy().setEnabled( true );
484 public Boolean ping()
485 throws RedbackServiceException
490 private User getSimpleUser( org.apache.archiva.redback.users.User user )
496 return new User( user );
499 public Boolean createAdminUser( User adminUser )
500 throws RedbackServiceException
502 if ( isAdminUserExists() )
504 return Boolean.FALSE;
509 org.apache.archiva.redback.users.User user =
510 userManager.createUser( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME, adminUser.getFullName(),
511 adminUser.getEmail() );
512 user.setPassword( adminUser.getPassword() );
514 user.setLocked( false );
515 user.setPasswordChangeRequired( false );
516 user.setPermanent( true );
517 user.setValidated( true );
519 userManager.addUser( user );
520 roleManager.assignRole( "system-administrator", user.getUsername() );
522 catch ( RoleManagerException e )
524 throw new RedbackServiceException( e.getMessage() );
526 catch ( UserManagerException e )
528 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
533 public Boolean isAdminUserExists()
534 throws RedbackServiceException
538 userManager.findUser( config.getString( UserConfigurationKeys.DEFAULT_ADMIN ) );
541 catch ( UserNotFoundException e )
545 catch ( UserManagerException e )
547 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
549 return Boolean.FALSE;
552 public Boolean resetPassword( ResetPasswordRequest resetPasswordRequest )
553 throws RedbackServiceException
555 String username = resetPasswordRequest.getUsername();
556 if ( StringUtils.isEmpty( username ) )
558 throw new RedbackServiceException( new ErrorMessage( "username.cannot.be.empty" ) );
561 UserManager userManager = securitySystem.getUserManager();
562 KeyManager keyManager = securitySystem.getKeyManager();
563 UserSecurityPolicy policy = securitySystem.getPolicy();
567 org.apache.archiva.redback.users.User user = userManager.findUser( username );
569 AuthenticationKey authkey = keyManager.createKey( username, "Password Reset Request",
570 policy.getUserValidationSettings().getEmailValidationTimeout() );
572 String applicationUrl = resetPasswordRequest.getApplicationUrl();
573 if ( StringUtils.isBlank( applicationUrl ) )
575 applicationUrl = getBaseUrl();
578 mailer.sendPasswordResetEmail( Arrays.asList( user.getEmail() ), authkey, applicationUrl );
579 log.info( "password reset request for username {}", username );
581 catch ( UserNotFoundException e )
583 log.info( "Password Reset on non-existant user [{}].", username );
584 throw new RedbackServiceException( new ErrorMessage( "password.reset.failure" ) );
586 catch ( KeyManagerException e )
588 log.info( "Unable to issue password reset.", e );
589 throw new RedbackServiceException( new ErrorMessage( "password.reset.email.generation.failure" ) );
591 catch ( UserManagerException e )
593 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
599 public RegistrationKey registerUser( UserRegistrationRequest userRegistrationRequest )
600 throws RedbackServiceException
602 User user = userRegistrationRequest.getUser();
605 throw new RedbackServiceException( new ErrorMessage( "invalid.user.credentials", null ) );
609 UserSecurityPolicy securityPolicy = securitySystem.getPolicy();
611 boolean emailValidationRequired = securityPolicy.getUserValidationSettings().isEmailValidationRequired();
613 if ( emailValidationRequired )
615 validateCredentialsLoose( user );
619 validateCredentialsStrict( user );
622 org.apache.archiva.redback.users.User u = null;
627 // NOTE: Do not perform Password Rules Validation Here.
629 if ( userManager.userExists( user.getUsername() ) )
631 throw new RedbackServiceException(
632 new ErrorMessage( "user.already.exists", new String[]{ user.getUsername() } ) );
635 u = userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
636 u.setPassword( user.getPassword() );
637 u.setValidated( false );
638 u.setLocked( false );
640 roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
642 catch ( RoleManagerException rpe )
644 log.error( "RoleProfile Error: " + rpe.getMessage(), rpe );
645 throw new RedbackServiceException( new ErrorMessage( "assign.role.failure", null ) );
647 catch ( UserManagerException e )
649 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
652 if ( emailValidationRequired )
658 AuthenticationKey authkey =
659 securitySystem.getKeyManager().createKey( u.getUsername(), "New User Email Validation",
660 securityPolicy.getUserValidationSettings().getEmailValidationTimeout() );
662 String baseUrl = userRegistrationRequest.getApplicationUrl();
663 if ( StringUtils.isBlank( baseUrl ) )
665 baseUrl = getBaseUrl();
668 log.debug( "register user {} with email {} and app url {}", u.getUsername(), u.getEmail(), baseUrl );
670 mailer.sendAccountValidationEmail( Arrays.asList( u.getEmail() ), authkey, baseUrl );
672 securityPolicy.setEnabled( false );
673 userManager.addUser( u );
674 return new RegistrationKey( authkey.getKey() );
677 catch ( KeyManagerException e )
679 log.error( "Unable to register a new user.", e );
680 throw new RedbackServiceException( new ErrorMessage( "cannot.register.user", null ) );
682 catch ( UserManagerException e )
684 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
688 securityPolicy.setEnabled( true );
695 userManager.addUser( u );
696 return new RegistrationKey( "-1" );
698 catch ( UserManagerException e )
700 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
704 // FIXME log this event
706 AuditEvent event = new AuditEvent( getText( "log.account.create" ) );
707 event.setAffectedUser( username );
713 public Boolean validateUserFromKey( String key )
714 throws RedbackServiceException
716 String principal = null;
719 AuthenticationKey authkey = securitySystem.getKeyManager().findKey( key );
721 org.apache.archiva.redback.users.User user =
722 securitySystem.getUserManager().findUser( authkey.getForPrincipal() );
724 user.setValidated( true );
725 user.setLocked( false );
726 user.setPasswordChangeRequired( true );
727 user.setEncodedPassword( "" );
729 principal = user.getUsername();
731 TokenBasedAuthenticationDataSource authsource = new TokenBasedAuthenticationDataSource();
732 authsource.setPrincipal( principal );
733 authsource.setToken( authkey.getKey() );
734 authsource.setEnforcePasswordChange( false );
736 securitySystem.getUserManager().updateUser( user );
738 httpAuthenticator.authenticate( authsource, httpServletRequest.getSession( true ) );
740 log.info( "account validated for user {}", user.getUsername() );
744 catch ( MustChangePasswordException e )
746 throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() );
748 catch ( KeyNotFoundException e )
750 log.info( "Invalid key requested: {}", key );
751 throw new RedbackServiceException( new ErrorMessage( "cannot.find.key" ) );
753 catch ( KeyManagerException e )
755 throw new RedbackServiceException( new ErrorMessage( "cannot.find.key.at.the.momment" ) );
758 catch ( UserNotFoundException e )
760 throw new RedbackServiceException( new ErrorMessage( "cannot.find.user", new String[]{ principal } ) );
763 catch ( AccountLockedException e )
765 throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() );
767 catch ( AuthenticationException e )
769 throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() );
771 catch ( UserManagerException e )
773 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
777 public Collection<Permission> getCurrentUserPermissions()
778 throws RedbackServiceException
780 RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
781 String userName = UserManager.GUEST_USERNAME;
782 if ( redbackRequestInformation != null && redbackRequestInformation.getUser() != null )
784 userName = redbackRequestInformation.getUser().getUsername();
787 return getUserPermissions( userName );
790 public Collection<Operation> getCurrentUserOperations()
791 throws RedbackServiceException
793 RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
794 String userName = UserManager.GUEST_USERNAME;
795 if ( redbackRequestInformation != null && redbackRequestInformation.getUser() != null )
797 userName = redbackRequestInformation.getUser().getUsername();
800 return getUserOperations( userName );
803 public Collection<Operation> getUserOperations( String userName )
804 throws RedbackServiceException
806 Collection<Permission> permissions = getUserPermissions( userName );
807 List<Operation> operations = new ArrayList<Operation>( permissions.size() );
808 for ( Permission permission : permissions )
810 if ( permission.getOperation() != null )
812 Operation operation = new Operation();
813 operation.setName( permission.getOperation().getName() );
814 operations.add( operation );
820 public Collection<Permission> getUserPermissions( String userName )
821 throws RedbackServiceException
825 Set<org.apache.archiva.redback.rbac.Permission> permissions =
826 rbacManager.getAssignedPermissions( userName );
827 // FIXME return guest permissions !!
828 List<Permission> userPermissions = new ArrayList<Permission>( permissions.size() );
829 for ( org.apache.archiva.redback.rbac.Permission p : permissions )
831 Permission permission = new Permission();
832 permission.setName( p.getName() );
834 if ( p.getOperation() != null )
836 Operation operation = new Operation();
837 operation.setName( p.getOperation().getName() );
838 permission.setOperation( operation );
841 if ( p.getResource() != null )
843 Resource resource = new Resource();
844 resource.setIdentifier( p.getResource().getIdentifier() );
845 resource.setPattern( p.getResource().isPattern() );
846 permission.setResource( resource );
849 userPermissions.add( permission );
851 return userPermissions;
853 catch ( RbacObjectNotFoundException e )
855 log.error( e.getMessage(), e );
856 throw new RedbackServiceException( e.getMessage() );
858 catch ( RbacManagerException e )
860 log.error( e.getMessage(), e );
861 throw new RedbackServiceException( e.getMessage() );
865 public void validateCredentialsLoose( User user )
866 throws RedbackServiceException
868 RedbackServiceException redbackServiceException =
869 new RedbackServiceException( "issues during validating user" );
870 if ( StringUtils.isEmpty( user.getUsername() ) )
872 redbackServiceException.addErrorMessage( new ErrorMessage( "username.required", null ) );
876 if ( !user.getUsername().matches( VALID_USERNAME_CHARS ) )
878 redbackServiceException.addErrorMessage( new ErrorMessage( "username.invalid.characters", null ) );
882 if ( StringUtils.isEmpty( user.getFullName() ) )
884 redbackServiceException.addErrorMessage( new ErrorMessage( "fullName.required", null ) );
887 if ( StringUtils.isEmpty( user.getEmail() ) )
889 redbackServiceException.addErrorMessage( new ErrorMessage( "email.required", null ) );
892 if ( !StringUtils.equals( user.getPassword(), user.getConfirmPassword() ) )
894 redbackServiceException.addErrorMessage( new ErrorMessage( "passwords.does.not.match", null ) );
899 if ( !org.codehaus.plexus.util.StringUtils.isEmpty( user.getEmail() ) )
901 new InternetAddress( user.getEmail(), true );
904 catch ( AddressException e )
906 redbackServiceException.addErrorMessage( new ErrorMessage( "email.invalid", null ) );
908 if ( !redbackServiceException.getErrorMessages().isEmpty() )
910 throw redbackServiceException;
914 public void validateCredentialsStrict( User user )
915 throws RedbackServiceException
917 validateCredentialsLoose( user );
920 org.apache.archiva.redback.users.User tmpuser =
921 userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
923 user.setPassword( user.getPassword() );
925 securitySystem.getPolicy().validatePassword( tmpuser );
927 if ( ( org.codehaus.plexus.util.StringUtils.isEmpty( user.getPassword() ) ) )
929 throw new RedbackServiceException( new ErrorMessage( "password.required", null ) );
932 catch ( UserManagerException e )
934 throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
938 private String getBaseUrl()
940 if ( httpServletRequest != null )
942 if ( httpServletRequest != null )
944 return httpServletRequest.getScheme() + "://" + httpServletRequest.getServerName() + (
945 httpServletRequest.getServerPort() == 80
947 : ":" + httpServletRequest.getServerPort() ) + httpServletRequest.getContextPath();
953 public Boolean unlockUser( String username )
954 throws RedbackServiceException
956 User user = getUser( username );
959 user.setLocked( false );
963 return Boolean.FALSE;
966 public Boolean lockUser( String username )
967 throws RedbackServiceException
969 User user = getUser( username );
972 user.setLocked( true );
976 return Boolean.FALSE;
979 public Boolean passwordChangeRequired( String username )
980 throws RedbackServiceException
982 User user = getUser( username );
985 user.setPasswordChangeRequired( true );
989 return Boolean.FALSE;
992 public Boolean passwordChangeNotRequired( String username )
993 throws RedbackServiceException
995 User user = getUser( username );
998 user.setPasswordChangeRequired( false );
1000 return Boolean.TRUE;
1002 return Boolean.FALSE;