From 5a8df644816033c9fc2ba2d5ee9c7e2fa4cbeae9 Mon Sep 17 00:00:00 2001 From: isuraD Date: Mon, 11 Apr 2016 18:30:02 +0530 Subject: [PATCH] Fixing IDENTITY-4498 --- .../mgt/IdentityMgtEventListener.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/IdentityMgtEventListener.java b/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/IdentityMgtEventListener.java index d5bd33152cf8..6cb9835c9ebd 100644 --- a/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/IdentityMgtEventListener.java +++ b/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/IdentityMgtEventListener.java @@ -251,10 +251,19 @@ public boolean doPostAuthenticate(String userName, boolean authenticated, if (!isEnable()) { return true; } - if(!userStoreManager.isReadOnly() && authenticated){ - userStoreManager.setUserClaimValue(userName, IdentityMgtConstants.LAST_LOGIN_TIME, Long.toString(System - .currentTimeMillis()), null); + + if (!userStoreManager.isReadOnly() && authenticated) { + String domainName = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); + String usernameWithDomain = UserCoreUtil.addDomainToName(userName, domainName); + boolean isUserExistInCurrentDomain = userStoreManager.isExistingUser(usernameWithDomain); + if (isUserExistInCurrentDomain) { + Map userClaims = new HashMap<>(); + userClaims.put(IdentityMgtConstants.LAST_LOGIN_TIME, Long.toString(System + .currentTimeMillis())); + userStoreManager.setUserClaimValues(userName, userClaims, null); + } } + // Top level try and finally blocks are used to unset thread local variables try { if (!IdentityUtil.threadLocalProperties.get().containsKey(DO_POST_AUTHENTICATE)) { @@ -703,8 +712,15 @@ public boolean doPostUpdateCredentialByAdmin(String userName, Object credential, return true; } if (!userStoreManager.isReadOnly()) { - userStoreManager.setUserClaimValue(userName, IdentityMgtConstants.LAST_PASSWORD_UPDATE_TIME, Long - .toString(System.currentTimeMillis()), null); + String domainName = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); + String usernameWithDomain = UserCoreUtil.addDomainToName(userName, domainName); + boolean isUserExistInCurrentDomain = userStoreManager.isExistingUser(usernameWithDomain); + if (isUserExistInCurrentDomain) { + Map userClaims = new HashMap<>(); + userClaims.put(IdentityMgtConstants.LAST_PASSWORD_UPDATE_TIME, Long + .toString(System.currentTimeMillis())); + userStoreManager.setUserClaimValues(userName, userClaims, null); + } } return true; @@ -1003,8 +1019,15 @@ public boolean doPostUpdateCredential(String userName, Object credential, UserSt return true; } if (!userStoreManager.isReadOnly()) { - userStoreManager.setUserClaimValue(userName, IdentityMgtConstants.LAST_PASSWORD_UPDATE_TIME, Long - .toString(System.currentTimeMillis()), null); + String domainName = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); + String usernameWithDomain = UserCoreUtil.addDomainToName(userName, domainName); + boolean isUserExistInCurrentDomain = userStoreManager.isExistingUser(usernameWithDomain); + if (isUserExistInCurrentDomain) { + Map userClaims = new HashMap<>(); + userClaims.put(IdentityMgtConstants.LAST_PASSWORD_UPDATE_TIME, Long + .toString(System.currentTimeMillis())); + userStoreManager.setUserClaimValues(userName, userClaims, null); + } } return true;