diff --git a/clearing-parent/pom.xml b/clearing-parent/pom.xml
index 06fb06d46..f90ee465d 100644
--- a/clearing-parent/pom.xml
+++ b/clearing-parent/pom.xml
@@ -20,6 +20,7 @@
classes
backend-api
imdg
+ security-util
db-scripts
dbf-importer
dbf-exporter
diff --git a/clearing-parent/security-util/pom.xml b/clearing-parent/security-util/pom.xml
new file mode 100644
index 000000000..2c0a2dbf5
--- /dev/null
+++ b/clearing-parent/security-util/pom.xml
@@ -0,0 +1,142 @@
+
+
+ 4.0.0
+
+ security-util
+ Clearing misc util for verify user roles
+ jar
+ SPCEX-1.0.0.0
+
+
+ clearing-parent
+ ru.spcex.clearing
+ SPCEX-1.0.0.0
+
+
+
+ 17
+ 17
+
+
+
+
+ org.springframework
+ spring-core
+ provided
+
+
+ org.springframework
+ spring-context
+ provided
+
+
+ ru.spcex.clearing
+ classes
+ SPCEX-1.0.0.0
+ compile
+
+
+ ru.spcex.clearing
+ dictionary
+ SPCEX-1.0.0.0
+ compile
+
+
+ ru.spcex.platform
+ platform-enum
+
+
+
+
+ ru.spcex.platform
+ platform-imdg-api
+
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.33
+
+
+
+
+ org.springframework
+ spring-test
+ test
+
+
+ org.skyscreamer
+ jsonassert
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter
+ test
+
+
+ org.assertj
+ assertj-core
+ test
+
+
+
+
+
+ src/main/resources
+
+ application.properties
+
+ false
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ ru.spcex.clearing.imdg.IMDGApplication
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+ true
+ ${project.artifactId}
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.21.0
+
+
+ org.junit.platform
+ junit-platform-surefire-provider
+ 1.2.0-M1
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.2.0-M1
+
+
+
+
+
+
\ No newline at end of file
diff --git a/clearing-parent/security-util/src/main/java/ru/spcex/clearing/util/security/UserRoleVerification.java b/clearing-parent/security-util/src/main/java/ru/spcex/clearing/util/security/UserRoleVerification.java
new file mode 100644
index 000000000..89b2c10d0
--- /dev/null
+++ b/clearing-parent/security-util/src/main/java/ru/spcex/clearing/util/security/UserRoleVerification.java
@@ -0,0 +1,86 @@
+package ru.spcex.clearing.util.security;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import ru.clearing.classes.objects.BusinessObject;
+import ru.clearing.classes.statics.data.company.CompanyRoleSet;
+import ru.clearing.classes.statics.data.user.User;
+import ru.clearing.classes.statics.data.user.UserRoleSession;
+import ru.spcex.clearing.imdg.IMDGDistributedNames;
+import ru.spcex.platform.enumeration.Status;
+import ru.spcex.platform.imdg.api.Imdg;
+import ru.spcex.platform.imdg.api.ImdgProvider;
+import ru.spcex.platform.utils.enumeration.IEnumKey;
+
+import java.util.Collection;
+
+/**
+ * Проверка дополнительных прав пользователя.
+ *
+ * Основная проверка прав осуществляется на frontend-api, и использовать этот компонент дополнительно не требуется.
+ */
+@Service
+public class UserRoleVerification {
+ protected Logger log = LoggerFactory.getLogger(getClass());
+
+ protected Imdg users;
+ protected Imdg userRoleSessions;
+ protected Imdg companyRoleSet;
+
+ @Autowired
+ public UserRoleVerification(ImdgProvider imdg) {
+ userRoleSessions = imdg.getImdg(IMDGDistributedNames.Map_UserRoleSession, UserRoleSession.class);
+ companyRoleSet = imdg.getImdg(IMDGDistributedNames.Map_CompanyRoleSet, CompanyRoleSet.class);
+ }
+
+ public boolean userHasRole(Long userId, String userRole) {
+ String query = String.format("userId=%s and userRole=%s and status=%s",
+ userId, userRole, Status.Active.getKey());
+ Collection roles = userRoleSessions.getCollectionIdsBySQL(query);
+ log.trace("userHasRole: found {} roles by query: {}", roles.size(), query);
+ if (roles.isEmpty())
+ return false;
+ //todo impl, use userRoleSessions
+ return true;
+ }
+
+ public boolean userHasRole(Long userId, Long companyId, String userRole) {
+ String query = String.format("userId=%s and companyId=%s and userRole=%s and status=%s",
+ userId, companyId, userRole, Status.Active.getKey());
+ Collection roles = userRoleSessions.getCollectionIdsBySQL(query);
+ log.trace("userHasRole: found {} roles by query: {}", roles.size(), query);
+ if (roles.isEmpty())
+ return false;
+ //todo impl, use userRoleSessions
+ return true;
+ }
+
+
+ boolean userHasRole(Long userId, IEnumKey role) {
+ return userHasRole(userId, role == null ? null : role.getKey());
+ }
+
+ boolean userHasRole(Long userId, Long companyId, IEnumKey role) {
+ return userHasRole(userId, companyId, role == null ? null : role.getKey());
+ }
+
+ boolean userHasRoleOnObject(Long userId, BusinessObject /*todo WithUserId / WithCompany */ bObject) {
+ //todo impl
+ return true;
+ }
+
+
+ public boolean companyHasRole(Long companyId, String companyRole) {
+ String query = String.format("companyId=%s and companyRole=%s and workflowStatus=%s",
+ companyId, companyRole, Status.Active.getKey());
+ Collection roles = companyRoleSet.getCollectionIdsBySQL(query);
+ log.trace("companyHasRole: found {} roles by query: {}", roles.size(), query);
+// if (roles.isEmpty()) return false;
+ //todo impl
+ return true;
+ }
+
+ // userIsEnabled & exist - frontendapi validation
+}