@@ -1510,12 +1510,24 @@ private List<APIChecker> getEnabledApiCheckers() {
15101510 @ Override
15111511 @ ActionEvent (eventType = EventTypes .EVENT_USER_CREATE , eventDescription = "creating User" )
15121512 public UserVO createUser (String userName , String password , String firstName , String lastName , String email , String timeZone , String accountName , Long domainId , String userUUID ,
1513- User .Source source ) {
1513+ User .Source source ) {
1514+ return createUser (userName , password , firstName , lastName , email , timeZone , accountName , domainId , userUUID , source , false );
1515+ }
1516+
1517+
1518+ @ ActionEvent (eventType = EventTypes .EVENT_USER_CREATE , eventDescription = "creating User" )
1519+ public UserVO createUser (String userName , String password , String firstName , String lastName , String email , String timeZone , String accountName , Long domainId , String userUUID ,
1520+ User .Source source , boolean isPasswordChangeRequired ) {
15141521 // default domain to ROOT if not specified
15151522 if (domainId == null ) {
15161523 domainId = Domain .ROOT_DOMAIN ;
15171524 }
15181525
1526+ if (isPasswordChangeRequired && (source == User .Source .SAML2 || source == User .Source .SAML2DISABLED || source == User .Source .LDAP )) {
1527+ logger .warn ("Enforcing password change is not permitted for source [{}]." , source );
1528+ throw new InvalidParameterValueException ("CloudStack does not support enforcing password change for SAML or LDAP users." );
1529+ }
1530+
15191531 Domain domain = _domainMgr .getDomain (domainId );
15201532 if (domain == null ) {
15211533 throw new CloudRuntimeException ("The domain " + domainId + " does not exist; unable to create user" );
@@ -1546,14 +1558,21 @@ public UserVO createUser(String userName, String password, String firstName, Str
15461558 verifyCallerPrivilegeForUserOrAccountOperations (account );
15471559 UserVO user ;
15481560 user = createUser (account .getId (), userName , password , firstName , lastName , email , timeZone , userUUID , source );
1561+ if (isPasswordChangeRequired ) {
1562+ long callerAccountId = CallContext .current ().getCallingAccountId ();
1563+ if ((isRootAdmin (callerAccountId ) || isDomainAdmin (callerAccountId ))) {
1564+ _userDetailsDao .addDetail (user .getId (), PasswordChangeRequired , "true" , false );
1565+ }
1566+ }
15491567 return user ;
15501568 }
15511569
15521570 @ Override
15531571 @ ActionEvent (eventType = EventTypes .EVENT_USER_CREATE , eventDescription = "creating User" )
1554- public UserVO createUser (String userName , String password , String firstName , String lastName , String email , String timeZone , String accountName , Long domainId , String userUUID ) {
1572+ public UserVO createUser (String userName , String password , String firstName , String lastName , String email ,
1573+ String timeZone , String accountName , Long domainId , String userUUID , boolean isPasswordChangeRequired ) {
15551574
1556- return createUser (userName , password , firstName , lastName , email , timeZone , accountName , domainId , userUUID , User .Source .UNKNOWN );
1575+ return createUser (userName , password , firstName , lastName , email , timeZone , accountName , domainId , userUUID , User .Source .UNKNOWN , isPasswordChangeRequired );
15571576 }
15581577
15591578 @ Override
@@ -1587,22 +1606,29 @@ public UserAccount updateUser(UpdateUserCmd updateUserCmd) {
15871606 if (mandate2FA != null && mandate2FA ) {
15881607 user .setUser2faEnabled (true );
15891608 }
1590- _userDao .update (user .getId (), user );
15911609 updatePasswordChangeRequired (caller , updateUserCmd , user );
1610+ _userDao .update (user .getId (), user );
15921611 return _userAccountDao .findById (user .getId ());
15931612 }
15941613
15951614 private void updatePasswordChangeRequired (User caller , UpdateUserCmd updateUserCmd , UserVO user ) {
1596- if (StringUtils .isNotBlank (updateUserCmd .getPassword ())) {
1597- boolean isCallerSameAsUser = user .getId () == caller .getId ();
1598- boolean isPasswordResetRequired = updateUserCmd .isPasswordChangeRequired () && !isCallerSameAsUser ;
1599- // Admins only can enforce passwordChangeRequired for user
1600- if (isRootAdmin (caller .getAccountId ()) || isDomainAdmin (caller .getAccountId ())) {
1601- if (isPasswordResetRequired ) {
1602- _userDetailsDao .addDetail (user .getId (), PasswordChangeRequired , "true" , false );
1603- }
1615+ User .Source userSource = user .getSource ();
1616+ if ((userSource == User .Source .SAML2 || userSource == User .Source .SAML2DISABLED || userSource == User .Source .LDAP )
1617+ && updateUserCmd .isPasswordChangeRequired ()) {
1618+ logger .warn ("Enforcing password change is not permitted for source [{}]." , user .getSource ());
1619+ throw new InvalidParameterValueException ("CloudStack does not support enforcing password change for SAML or LDAP users." );
1620+ }
1621+
1622+ boolean isCallerSameAsUser = user .getId () == caller .getId ();
1623+ boolean isPasswordResetRequired = updateUserCmd .isPasswordChangeRequired () && !isCallerSameAsUser ;
1624+ // Admins only can enforce passwordChangeRequired for user
1625+ if (isRootAdmin (caller .getAccountId ()) || isDomainAdmin (caller .getAccountId ())) {
1626+ if (isPasswordResetRequired ) {
1627+ _userDetailsDao .addDetail (user .getId (), PasswordChangeRequired , "true" , false );
16041628 }
1629+ }
16051630
1631+ if (StringUtils .isNotBlank (updateUserCmd .getPassword ())) {
16061632 // Remove passwordChangeRequired if user updating own pwd or admin has not enforced it
16071633 if (isCallerSameAsUser || !isPasswordResetRequired ) {
16081634 _userDetailsDao .removeDetail (user .getId (), PasswordChangeRequired );
0 commit comments