You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2022/04/16 05:58:29 UTC
[syncope] branch 2_1_X updated: Miscellaneous fixes and cleanups
This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/2_1_X by this push:
new 93f04631df Miscellaneous fixes and cleanups
93f04631df is described below
commit 93f04631dfea8c2af84d33c3b83a2d72e7d52be9
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Sat Apr 16 07:58:21 2022 +0200
Miscellaneous fixes and cleanups
---
.../org/apache/syncope/core/logic/UserLogic.java | 29 +++++++++++++++-------
.../core/persistence/api/dao/EntityCacheDAO.java | 3 +++
.../core/persistence/jpa/dao/JPAJSONUserDAO.java | 1 +
.../persistence/jpa/dao/JPAEntityCacheDAO.java | 7 ++++++
.../core/persistence/jpa/outer/UserTest.java | 1 -
.../core/rest/cxf/service/UserSelfServiceImpl.java | 1 -
pom.xml | 2 +-
7 files changed, 32 insertions(+), 12 deletions(-)
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/UserLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/UserLogic.java
index dd5ec19262..3bfd90995f 100644
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/UserLogic.java
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/UserLogic.java
@@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.ArrayUtils;
@@ -52,6 +53,7 @@ import org.apache.syncope.core.persistence.api.dao.NotFoundException;
import org.apache.syncope.core.persistence.api.dao.UserDAO;
import org.apache.syncope.core.persistence.api.dao.search.OrderByClause;
import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
+import org.apache.syncope.core.persistence.api.entity.AccessToken;
import org.apache.syncope.core.persistence.api.entity.group.Group;
import org.apache.syncope.core.persistence.api.entity.user.User;
import org.apache.syncope.core.provisioning.api.LogicActions;
@@ -204,10 +206,8 @@ public class UserLogic extends AbstractAnyLogic<UserTO, UserPatch> {
// Ensures that, if the self update above moves the user into a status from which no authentication
// is possible, the existing Access Token is clean up to avoid issues with future authentications
if (!confDAO.getValuesAsStrings("authentication.statuses").contains(updated.getEntity().getStatus())) {
- String accessToken = accessTokenDAO.findByOwner(updated.getEntity().getUsername()).getKey();
- if (accessToken != null) {
- accessTokenDAO.delete(accessToken);
- }
+ Optional.ofNullable(accessTokenDAO.findByOwner(updated.getEntity().getUsername())).
+ map(AccessToken::getKey).ifPresent(accessTokenDAO::delete);
}
return updated;
@@ -315,10 +315,21 @@ public class UserLogic extends AbstractAnyLogic<UserTO, UserPatch> {
@PreAuthorize("hasRole('" + StandardEntitlement.MUST_CHANGE_PASSWORD + "')")
public ProvisioningResult<UserTO> mustChangePassword(final String password, final boolean nullPriorityAsync) {
+ UserTO userTO = binder.getAuthenticatedUserTO();
+
UserPatch userPatch = new UserPatch();
- userPatch.setPassword(new PasswordPatch.Builder().value(password).build());
+ userPatch.setPassword(new PasswordPatch.Builder().
+ value(password).
+ onSyncope(true).
+ resources(userDAO.findAllResourceKeys(userTO.getKey())).
+ build());
userPatch.setMustChangePassword(new BooleanReplacePatchItem.Builder().value(false).build());
- return selfUpdate(userPatch, nullPriorityAsync);
+ ProvisioningResult<UserTO> result = selfUpdate(userPatch, nullPriorityAsync);
+
+ Optional.ofNullable(accessTokenDAO.findByOwner(result.getEntity().getUsername())).
+ map(AccessToken::getKey).ifPresent(accessTokenDAO::delete);
+
+ return result;
}
@PreAuthorize("isAnonymous() or hasRole('" + StandardEntitlement.ANONYMOUS + "')")
@@ -334,9 +345,9 @@ public class UserLogic extends AbstractAnyLogic<UserTO, UserPatch> {
}
if (syncopeLogic.isPwdResetRequiringSecurityQuestions()
- && (securityAnswer == null
- || !Encryptor.getInstance().verify(securityAnswer, user.getCipherAlgorithm(),
- user.getSecurityAnswer()))) {
+ && (securityAnswer == null || !Encryptor.getInstance().
+ verify(securityAnswer, user.getCipherAlgorithm(), user.getSecurityAnswer()))) {
+
throw SyncopeClientException.build(ClientExceptionType.InvalidSecurityAnswer);
}
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/EntityCacheDAO.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/EntityCacheDAO.java
index 2736f62a70..d48133171c 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/EntityCacheDAO.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/EntityCacheDAO.java
@@ -19,6 +19,7 @@
package org.apache.syncope.core.persistence.api.dao;
import java.util.Map;
+import org.apache.syncope.core.persistence.api.entity.Entity;
public interface EntityCacheDAO {
@@ -30,5 +31,7 @@ public interface EntityCacheDAO {
void resetStatistics();
+ void evict(Class<? extends Entity> entityClass, String key);
+
void clearCache();
}
diff --git a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONUserDAO.java b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONUserDAO.java
index 345d1efcc1..13de10eb03 100644
--- a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONUserDAO.java
+++ b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONUserDAO.java
@@ -81,6 +81,7 @@ public class JPAJSONUserDAO extends JPAUserDAO {
String clearPwd = user.getClearPassword();
// 2. save
+ entityManager().flush();
User merged = entityManager().merge(user);
// 3. set back the sole clear password value
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAEntityCacheDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAEntityCacheDAO.java
index abeda5719c..32d7302532 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAEntityCacheDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAEntityCacheDAO.java
@@ -129,6 +129,13 @@ public class JPAEntityCacheDAO extends AbstractDAO<Entity> implements EntityCach
queryStatistics().reset();
}
+ @Override
+ public void evict(final Class<? extends Entity> entityClass, final String key) {
+ OpenJPAEntityManagerFactory emf = OpenJPAPersistence.cast(entityManagerFactory());
+
+ emf.getStoreCache().evict(entityClass, key);
+ }
+
@Override
public void clearCache() {
OpenJPAEntityManagerFactory emf = OpenJPAPersistence.cast(entityManagerFactory());
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/UserTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/UserTest.java
index 03e498d63c..7f58bfc300 100644
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/UserTest.java
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/UserTest.java
@@ -197,7 +197,6 @@ public class UserTest extends AbstractTest {
} catch (InvalidEntityException e) {
assertNotNull(e);
}
- entityManager().flush();
}
@Test
diff --git a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserSelfServiceImpl.java b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserSelfServiceImpl.java
index d97ba96690..44a40e16fc 100644
--- a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserSelfServiceImpl.java
+++ b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserSelfServiceImpl.java
@@ -117,5 +117,4 @@ public class UserSelfServiceImpl extends AbstractServiceImpl implements UserSelf
logic.confirmPasswordReset(token, password);
}
-
}
diff --git a/pom.xml b/pom.xml
index eb6c364023..46e2118e46 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,7 +32,7 @@ under the License.
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
- <version>25</version>
+ <version>26</version>
<relativePath />
</parent>