apps/user_ldap/lib/User/User.php
/**
	 * called by a post_login hook to handle password expiry
	 *
	 * @param array $params
	 */
called by a post_login hook to handle password expiry
@param array $params
called by a post_login hook to handle password expiry @param array $params
public function handlePasswordExpiry($params) {
		$ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
		if (empty($ppolicyDN) || (intval($this->connection->turnOnPasswordChange) !== 1)) {
			return;
		}
		$uid = $params['uid'];
		if(isset($uid) && $uid === $this->getUsername()) {
			$result = $this->access->search('objectclass=*', $this->dn, ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']);
			if(array_key_exists('pwdpolicysubentry', $result[0])) {
				$pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
				if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
					$ppolicyDN = $pwdPolicySubentry[0];
				}
			}
			$pwdGraceUseTime = array_key_exists('pwdgraceusetime', $result[0]) ? $result[0]['pwdgraceusetime'] : null;
			$pwdReset = array_key_exists('pwdreset', $result[0]) ? $result[0]['pwdreset'] : null;
			$pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null;
			$cacheKey = 'ppolicyAttributes' . $ppolicyDN;
			$result = $this->connection->getFromCache($cacheKey);
			if(is_null($result)) {
				$result = $this->access->search('objectclass=*', $ppolicyDN, ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
				$this->connection->writeToCache($cacheKey, $result);
			}
			$pwdGraceAuthNLimit = array_key_exists('pwdgraceauthnlimit', $result[0]) ? $result[0]['pwdgraceauthnlimit'] : null;
			$pwdMaxAge = array_key_exists('pwdmaxage', $result[0]) ? $result[0]['pwdmaxage'] : null;
			$pwdExpireWarning = array_key_exists('pwdexpirewarning', $result[0]) ? $result[0]['pwdexpirewarning'] : null;
			$pwdGraceUseTimeCount = count($pwdGraceUseTime);
			if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { 				if($pwdGraceAuthNLimit 
					&& (count($pwdGraceAuthNLimit) > 0)
					&&($pwdGraceUseTimeCount < intval($pwdGraceAuthNLimit[0]))) { 					$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
					header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
					'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
				} else { 
					header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
					'user_ldap.renewPassword.showLoginFormInvalidPassword', array('user' => $uid)));
				}
				exit();
			}
			if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { 
				$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
				header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
				'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
				exit();
			}
			if($pwdChangedTime && (count($pwdChangedTime) > 0)) {
				if($pwdMaxAge && (count($pwdMaxAge) > 0)
					&& $pwdExpireWarning && (count($pwdExpireWarning) > 0)) {
					$pwdMaxAgeInt = intval($pwdMaxAge[0]);
					$pwdExpireWarningInt = intval($pwdExpireWarning[0]);
					if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
						$pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
						$pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
						$currentDateTime = new \DateTime();
						$secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp();
						if($secondsToExpiry <= $pwdExpireWarningInt) {
							$notification = $this->notificationManager->createNotification();
							$notification->setApp('user_ldap')
								->setUser($uid)
								->setObject('pwd_exp_warn', $uid)
							;
							$this->notificationManager->markProcessed($notification);
							$notification = $this->notificationManager->createNotification();
							$notification->setApp('user_ldap')
								->setUser($uid)
								->setDateTime($currentDateTime)
								->setObject('pwd_exp_warn', $uid) 
								->setSubject('pwd_exp_warn_days', [(int) ceil($secondsToExpiry / 60 / 60 / 24)])
							;
							$this->notificationManager->notify($notification);
						}
					}
				}
			}
		}
	}
public function handlePasswordExpiry ( $ params ) { $ ppolicyDN = $ this -> connection -> ldapDefaultPPolicyDN ; if ( empty ( $ ppolicyDN ) || ( intval ( $ this -> connection -> turnOnPasswordChange ) !== 1 ) ) { return ; } $ uid = $ params [ 'uid' ] ; if ( isset ( $ uid ) && $ uid === $ this -> getUsername ( ) ) { $ result = $ this -> access -> search ( 'objectclass=*' , $ this -> dn , [ 'pwdpolicysubentry' , 'pwdgraceusetime' , 'pwdreset' , 'pwdchangedtime' ] ) ; if ( array_key_exists ( 'pwdpolicysubentry' , $ result [ 0 ] ) ) { $ pwdPolicySubentry = $ result [ 0 ] [ 'pwdpolicysubentry' ] ; if ( $ pwdPolicySubentry && ( count ( $ pwdPolicySubentry ) > 0 ) ) { $ ppolicyDN = $ pwdPolicySubentry [ 0 ] ; } } $ pwdGraceUseTime = array_key_exists ( 'pwdgraceusetime' , $ result [ 0 ] ) ? $ result [ 0 ] [ 'pwdgraceusetime' ] : null ; $ pwdReset = array_key_exists ( 'pwdreset' , $ result [ 0 ] ) ? $ result [ 0 ] [ 'pwdreset' ] : null ; $ pwdChangedTime = array_key_exists ( 'pwdchangedtime' , $ result [ 0 ] ) ? $ result [ 0 ] [ 'pwdchangedtime' ] : null ; $ cacheKey = 'ppolicyAttributes' . $ ppolicyDN ; $ result = $ this -> connection -> getFromCache ( $ cacheKey ) ; if ( is_null ( $ result ) ) { $ result = $ this -> access -> search ( 'objectclass=*' , $ ppolicyDN , [ 'pwdgraceauthnlimit' , 'pwdmaxage' , 'pwdexpirewarning' ] ) ; $ this -> connection -> writeToCache ( $ cacheKey , $ result ) ; } $ pwdGraceAuthNLimit = array_key_exists ( 'pwdgraceauthnlimit' , $ result [ 0 ] ) ? $ result [ 0 ] [ 'pwdgraceauthnlimit' ] : null ; $ pwdMaxAge = array_key_exists ( 'pwdmaxage' , $ result [ 0 ] ) ? $ result [ 0 ] [ 'pwdmaxage' ] : null ; $ pwdExpireWarning = array_key_exists ( 'pwdexpirewarning' , $ result [ 0 ] ) ? $ result [ 0 ] [ 'pwdexpirewarning' ] : null ; $ pwdGraceUseTimeCount = count ( $ pwdGraceUseTime ) ; if ( $ pwdGraceUseTime && $ pwdGraceUseTimeCount > 0 ) { if ( $ pwdGraceAuthNLimit && ( count ( $ pwdGraceAuthNLimit ) > 0 ) && ( $ pwdGraceUseTimeCount < intval ( $ pwdGraceAuthNLimit [ 0 ] ) ) ) { $ this -> config -> setUserValue ( $ uid , 'user_ldap' , 'needsPasswordReset' , 'true' ) ; header ( 'Location: ' . \ OC :: $ server -> getURLGenerator ( ) -> linkToRouteAbsolute ( 'user_ldap.renewPassword.showRenewPasswordForm' , array ( 'user' => $ uid ) ) ) ; } else { header ( 'Location: ' . \ OC :: $ server -> getURLGenerator ( ) -> linkToRouteAbsolute ( 'user_ldap.renewPassword.showLoginFormInvalidPassword' , array ( 'user' => $ uid ) ) ) ; } exit ( ) ; } if ( $ pwdReset && ( count ( $ pwdReset ) > 0 ) && $ pwdReset [ 0 ] === 'TRUE' ) { $ this -> config -> setUserValue ( $ uid , 'user_ldap' , 'needsPasswordReset' , 'true' ) ; header ( 'Location: ' . \ OC :: $ server -> getURLGenerator ( ) -> linkToRouteAbsolute ( 'user_ldap.renewPassword.showRenewPasswordForm' , array ( 'user' => $ uid ) ) ) ; exit ( ) ; } if ( $ pwdChangedTime && ( count ( $ pwdChangedTime ) > 0 ) ) { if ( $ pwdMaxAge && ( count ( $ pwdMaxAge ) > 0 ) && $ pwdExpireWarning && ( count ( $ pwdExpireWarning ) > 0 ) ) { $ pwdMaxAgeInt = intval ( $ pwdMaxAge [ 0 ] ) ; $ pwdExpireWarningInt = intval ( $ pwdExpireWarning [ 0 ] ) ; if ( $ pwdMaxAgeInt > 0 && $ pwdExpireWarningInt > 0 ) { $ pwdChangedTimeDt = \ DateTime :: createFromFormat ( 'YmdHisZ' , $ pwdChangedTime [ 0 ] ) ; $ pwdChangedTimeDt -> add ( new \ DateInterval ( 'PT' . $ pwdMaxAgeInt . 'S' ) ) ; $ currentDateTime = new \ DateTime ( ) ; $ secondsToExpiry = $ pwdChangedTimeDt -> getTimestamp ( ) - $ currentDateTime -> getTimestamp ( ) ; if ( $ secondsToExpiry <= $ pwdExpireWarningInt ) { $ notification = $ this -> notificationManager -> createNotification ( ) ; $ notification -> setApp ( 'user_ldap' ) -> setUser ( $ uid ) -> setObject ( 'pwd_exp_warn' , $ uid ) ; $ this -> notificationManager -> markProcessed ( $ notification ) ; $ notification = $ this -> notificationManager -> createNotification ( ) ; $ notification -> setApp ( 'user_ldap' ) -> setUser ( $ uid ) -> setDateTime ( $ currentDateTime ) -> setObject ( 'pwd_exp_warn' , $ uid ) -> setSubject ( 'pwd_exp_warn_days' , [ ( int ) ceil ( $ secondsToExpiry / 60 / 60 / 24 ) ] ) ; $ this -> notificationManager -> notify ( $ notification ) ; } } } } } }
called by a post_login hook to handle password expiry
 @param array $params
called by a post_login hook to handle password expiry @param array $params
//password expiry handling disabled //retrieve relevant user attributes //custom ppolicy DN //retrieve relevant password policy attributes //handle grace login //was this a grace login?
 //at least one more grace login available?
 //no more grace login available //handle pwdReset attribute //user must change his password //handle password expiry warning //remove last password expiry warning if any //create new password expiry warning