From b4b0f74a9ee929a5f906d4c90bace936489bcb40 Mon Sep 17 00:00:00 2001
From: "Crystal.Sea"
Date: Sat, 12 Dec 2020 22:02:31 +0800
Subject: [PATCH 1/8] Dynamic Groups
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
动态用户组
---
.../apache/commons/ssl/HostnameVerifier.java | 571 ------------------
.../main/java/org/maxkey/domain/Groups.java | 6 +
.../main/java/org/maxkey/domain/Roles.java | 38 ++
.../org/maxkey/web/InitializeContext.java | 4 +
.../main/java/org/maxkey/web/WebContext.java | 25 +-
.../persistence/mapper/GroupMemberMapper.java | 10 +
.../persistence/mapper/GroupsMapper.java | 3 +
.../persistence/mapper/RoleMemberMapper.java | 7 +
.../persistence/mapper/RolesMapper.java | 2 +
.../service/GroupMemberService.java | 13 +
.../persistence/service/GroupsService.java | 31 +
.../service/RoleMemberService.java | 14 +
.../persistence/service/RolesService.java | 27 +
.../mapper/xml/mysql/GroupMemberMapper.xml | 53 +-
.../mapper/xml/mysql/GroupsMapper.xml | 10 +
.../mapper/xml/mysql/RoleMemberMapper.xml | 57 +-
.../mapper/xml/mysql/RolesMapper.xml | 14 +-
.../main/java/org/maxkey/MaxKeyMgtConfig.java | 58 +-
.../org/maxkey/jobs/DynamicGroupsJob.java | 56 ++
.../java/org/maxkey/jobs/DynamicRolesJob.java | 5 +
.../web/contorller/GroupsController.java | 4 +-
.../web/contorller/RolesController.java | 4 +-
.../src/main/resources/maxkey.properties | 4 +-
.../resources/messages/message.properties | 3 +
.../resources/messages/message_en.properties | 3 +
.../messages/message_zh_CN.properties | 3 +
.../templates/views/groups/groupsList.ftl | 12 +-
.../templates/views/roles/roleAdd.ftl | 176 +++++-
.../templates/views/roles/roleUpdate.ftl | 190 +++++-
.../templates/views/roles/rolesList.ftl | 19 +-
30 files changed, 808 insertions(+), 614 deletions(-)
delete mode 100644 maxkey-core/src/main/java/org/apache/commons/ssl/HostnameVerifier.java
create mode 100644 maxkey-web-manage/src/main/java/org/maxkey/jobs/DynamicGroupsJob.java
create mode 100644 maxkey-web-manage/src/main/java/org/maxkey/jobs/DynamicRolesJob.java
diff --git a/maxkey-core/src/main/java/org/apache/commons/ssl/HostnameVerifier.java b/maxkey-core/src/main/java/org/apache/commons/ssl/HostnameVerifier.java
deleted file mode 100644
index a59a1e819..000000000
--- a/maxkey-core/src/main/java/org/apache/commons/ssl/HostnameVerifier.java
+++ /dev/null
@@ -1,571 +0,0 @@
-package org.apache.commons.ssl;
-
-import javax.naming.InvalidNameException;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.ldap.LdapName;
-import javax.naming.ldap.Rdn;
-/*
- * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/trunk/src/java/org/apache/commons/ssl/HostnameVerifier.java $
- * $Revision: 121 $
- * $Date: 2007-11-14 09:26:57 +0400 (Ср., 14 нояб. 2007) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * .
- *
- */
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLPeerUnverifiedException;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
-import javax.security.auth.x500.X500Principal;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateParsingException;
-import java.security.cert.X509Certificate;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.TreeSet;
-
-/**
- * Interface for checking if a hostname matches the names stored inside the
- * server's X.509 certificate. Correctly implements
- * javax.net.ssl.HostnameVerifier, but that interface is not recommended.
- * Instead we added several check() methods that take SSLSocket,
- * or X509Certificate, or ultimately (they all end up calling this one),
- * String. (It's easier to supply JUnit with Strings instead of mock
- * SSLSession objects!)
- *
Our check() methods throw exceptions if the name is
- * invalid, whereas javax.net.ssl.HostnameVerifier just returns true/false.
- *
- * We provide the HostnameVerifier.DEFAULT, HostnameVerifier.STRICT, and
- * HostnameVerifier.ALLOW_ALL implementations. We also provide the more
- * specialized HostnameVerifier.DEFAULT_AND_LOCALHOST, as well as
- * HostnameVerifier.STRICT_IE6. But feel free to define your own
- * implementations!
- *
- * Inspired by Sebastian Hauer's original StrictSSLProtocolSocketFactory in the
- * HttpClient "contrib" repository.
- *
- * @author Julius Davies
- * @author Sebastian Hauer
- * @since 8-Dec-2006
- */
-public interface HostnameVerifier extends javax.net.ssl.HostnameVerifier {
-
- boolean verify(String host, SSLSession session);
-
- void check(String host, SSLSocket ssl) throws IOException;
-
- void check(String host, X509Certificate cert) throws SSLException;
-
- void check(String host, String[] cns, String[] subjectAlts)
- throws SSLException;
-
- void check(String[] hosts, SSLSocket ssl) throws IOException;
-
- void check(String[] hosts, X509Certificate cert) throws SSLException;
-
-
- /**
- * Checks to see if the supplied hostname matches any of the supplied CNs
- * or "DNS" Subject-Alts. Most implementations only look at the first CN,
- * and ignore any additional CNs. Most implementations do look at all of
- * the "DNS" Subject-Alts. The CNs or Subject-Alts may contain wildcards
- * according to RFC 2818.
- *
- * @param cns CN fields, in order, as extracted from the X.509
- * certificate.
- * @param subjectAlts Subject-Alt fields of type 2 ("DNS"), as extracted
- * from the X.509 certificate.
- * @param hosts The array of hostnames to verify.
- * @throws SSLException If verification failed.
- */
- void check(String[] hosts, String[] cns, String[] subjectAlts)
- throws SSLException;
-
-
- /**
- * The DEFAULT HostnameVerifier works the same way as Curl and Firefox.
- *
- * The hostname must match either the first CN, or any of the subject-alts.
- * A wildcard can occur in the CN, and in any of the subject-alts.
- *
- * The only difference between DEFAULT and STRICT is that a wildcard (such
- * as "*.foo.com") with DEFAULT matches all subdomains, including
- * "a.b.foo.com".
- */
- public final static HostnameVerifier DEFAULT =
- new AbstractVerifier() {
- public final void check(final String[] hosts, final String[] cns,
- final String[] subjectAlts)
- throws SSLException {
- check(hosts, cns, subjectAlts, false, false);
- }
-
- public final String toString() { return "DEFAULT"; }
- };
-
-
- /**
- * The DEFAULT_AND_LOCALHOST HostnameVerifier works like the DEFAULT
- * one with one additional relaxation: a host of "localhost",
- * "localhost.localdomain", "127.0.0.1", "::1" will always pass, no matter
- * what is in the server's certificate.
- */
- public final static HostnameVerifier DEFAULT_AND_LOCALHOST =
- new AbstractVerifier() {
- public final void check(final String[] hosts, final String[] cns,
- final String[] subjectAlts)
- throws SSLException {
- if (isLocalhost(hosts[0])) {
- return;
- }
- check(hosts, cns, subjectAlts, false, false);
- }
-
- public final String toString() { return "DEFAULT_AND_LOCALHOST"; }
- };
-
- /**
- * The STRICT HostnameVerifier works the same way as java.net.URL in Sun
- * Java 1.4, Sun Java 5, Sun Java 6. It's also pretty close to IE6.
- * This implementation appears to be compliant with RFC 2818 for dealing
- * with wildcards.
- *
- * The hostname must match either the first CN, or any of the subject-alts.
- * A wildcard can occur in the CN, and in any of the subject-alts. The
- * one divergence from IE6 is how we only check the first CN. IE6 allows
- * a match against any of the CNs present. We decided to follow in
- * Sun Java 1.4's footsteps and only check the first CN.
- *
- * A wildcard such as "*.foo.com" matches only subdomains in the same
- * level, for example "a.foo.com". It does not match deeper subdomains
- * such as "a.b.foo.com".
- */
- public final static HostnameVerifier STRICT =
- new AbstractVerifier() {
- public final void check(final String[] host, final String[] cns,
- final String[] subjectAlts)
- throws SSLException {
- check(host, cns, subjectAlts, false, true);
- }
-
- public final String toString() { return "STRICT"; }
- };
-
- /**
- * The STRICT_IE6 HostnameVerifier works just like the STRICT one with one
- * minor variation: the hostname can match against any of the CN's in the
- * server's certificate, not just the first one. This behaviour is
- * identical to IE6's behaviour.
- */
- public final static HostnameVerifier STRICT_IE6 =
- new AbstractVerifier() {
- public final void check(final String[] host, final String[] cns,
- final String[] subjectAlts)
- throws SSLException {
- check(host, cns, subjectAlts, true, true);
- }
-
- public final String toString() { return "STRICT_IE6"; }
- };
-
- /**
- * The ALLOW_ALL HostnameVerifier essentially turns hostname verification
- * off. This implementation is a no-op, and never throws the SSLException.
- */
- public final static HostnameVerifier ALLOW_ALL =
- new AbstractVerifier() {
- public final void check(final String[] host, final String[] cns,
- final String[] subjectAlts) {
- // Allow everything - so never blowup.
- }
-
- public final String toString() { return "ALLOW_ALL"; }
- };
-
- abstract class AbstractVerifier implements HostnameVerifier {
-
- /**
- * This contains a list of 2nd-level domains that aren't allowed to
- * have wildcards when combined with country-codes.
- * For example: [*.co.uk].
- *
- * The [*.co.uk] problem is an interesting one. Should we just hope
- * that CA's would never foolishly allow such a certificate to happen?
- * Looks like we're the only implementation guarding against this.
- * Firefox, Curl, Sun Java 1.4, 5, 6 don't bother with this check.
- */
- private final static String[] BAD_COUNTRY_2LDS =
- {"ac", "co", "com", "ed", "edu", "go", "gouv", "gov", "info",
- "lg", "ne", "net", "or", "org"};
-
- private final static String[] LOCALHOSTS = {"::1", "127.0.0.1",
- "localhost",
- "localhost.localdomain"};
-
-
- static {
- // Just in case developer forgot to manually sort the array. :-)
- Arrays.sort(BAD_COUNTRY_2LDS);
- Arrays.sort(LOCALHOSTS);
- }
-
- protected AbstractVerifier() {}
-
- /**
- * The javax.net.ssl.HostnameVerifier contract.
- *
- * @param host 'hostname' we used to create our socket
- * @param session SSLSession with the remote server
- * @return true if the host matched the one in the certificate.
- */
- public boolean verify(String host, SSLSession session) {
- try {
- Certificate[] certs = session.getPeerCertificates();
- X509Certificate x509 = (X509Certificate) certs[0];
- check(new String[]{host}, x509);
- return true;
- }
- catch (SSLException e) {
- return false;
- }
- }
-
- public void check(String host, SSLSocket ssl) throws IOException {
- check(new String[]{host}, ssl);
- }
-
- public void check(String host, X509Certificate cert)
- throws SSLException {
- check(new String[]{host}, cert);
- }
-
- public void check(String host, String[] cns, String[] subjectAlts)
- throws SSLException {
- check(new String[]{host}, cns, subjectAlts);
- }
-
- public void check(String host[], SSLSocket ssl)
- throws IOException {
- if (host == null) {
- throw new NullPointerException("host to verify is null");
- }
-
- SSLSession session = ssl.getSession();
- if (session == null) {
- // In our experience this only happens under IBM 1.4.x when
- // spurious (unrelated) certificates show up in the server'
- // chain. Hopefully this will unearth the real problem:
- InputStream in = ssl.getInputStream();
- in.available();
- /*
- If you're looking at the 2 lines of code above because
- you're running into a problem, you probably have two
- options:
- #1. Clean up the certificate chain that your server
- is presenting (e.g. edit "/etc/apache2/server.crt"
- or wherever it is your server's certificate chain
- is defined).
- OR
- #2. Upgrade to an IBM 1.5.x or greater JVM, or switch
- to a non-IBM JVM.
- */
-
- // If ssl.getInputStream().available() didn't cause an
- // exception, maybe at least now the session is available?
- session = ssl.getSession();
- if (session == null) {
- // If it's still null, probably a startHandshake() will
- // unearth the real problem.
- ssl.startHandshake();
-
- // Okay, if we still haven't managed to cause an exception,
- // might as well go for the NPE. Or maybe we're okay now?
- session = ssl.getSession();
- }
- }
- Certificate[] certs;
- try {
- certs = session.getPeerCertificates();
- } catch (SSLPeerUnverifiedException spue) {
- InputStream in = ssl.getInputStream();
- in.available();
- // Didn't trigger anything interesting? Okay, just throw
- // original.
- throw spue;
- }
- X509Certificate x509 = (X509Certificate) certs[0];
- check(host, x509);
- }
-
- public void check(String[] host, X509Certificate cert)
- throws SSLException {
- String[] cns = getCNs(cert);
- String[] subjectAlts = getDNSSubjectAlts(cert);
- check(host, cns, subjectAlts);
- }
-
-
- public void check(final String[] hosts, final String[] cns,
- final String[] subjectAlts, final boolean ie6,
- final boolean strictWithSubDomains)
- throws SSLException {
- // Build up lists of allowed hosts For logging/debugging purposes.
- StringBuffer buf = new StringBuffer(32);
- buf.append('<');
- for (int i = 0; i < hosts.length; i++) {
- String h = hosts[i];
- h = h != null ? h.trim().toLowerCase() : "";
- hosts[i] = h;
- if (i > 0) {
- buf.append('/');
- }
- buf.append(h);
- }
- buf.append('>');
- String hostnames = buf.toString();
- // Build the list of names we're going to check. Our DEFAULT and
- // STRICT implementations of the HostnameVerifier only use the
- // first CN provided. All other CNs are ignored.
- // (Firefox, wget, curl, Sun Java 1.4, 5, 6 all work this way).
- TreeSet names = new TreeSet();
- if (cns != null && cns.length > 0 && cns[0] != null) {
- names.add(cns[0]);
- if (ie6) {
- for (int i = 1; i < cns.length; i++) {
- names.add(cns[i]);
- }
- }
- }
- if (subjectAlts != null) {
- for (int i = 0; i < subjectAlts.length; i++) {
- if (subjectAlts[i] != null) {
- names.add(subjectAlts[i]);
- }
- }
- }
- if (names.isEmpty()) {
- String msg = "Certificate for " + hosts[0] + " doesn't contain CN or DNS subjectAlt";
- throw new SSLException(msg);
- }
-
- // StringBuffer for building the error message.
- buf = new StringBuffer();
-
- boolean match = false;
- out:
- for (Iterator it = names.iterator(); it.hasNext();) {
- // Don't trim the CN, though!
- String cn = (String) it.next();
- cn = cn.toLowerCase();
- // Store CN in StringBuffer in case we need to report an error.
- buf.append(" <");
- buf.append(cn);
- buf.append('>');
- if (it.hasNext()) {
- buf.append(" OR");
- }
-
- // The CN better have at least two dots if it wants wildcard
- // action. It also can't be [*.co.uk] or [*.co.jp] or
- // [*.org.uk], etc...
- boolean doWildcard = cn.startsWith("*.") &&
- cn.lastIndexOf('.') >= 0 &&
- !isIP4Address(cn) &&
- acceptableCountryWildcard(cn);
-
- for (int i = 0; i < hosts.length; i++) {
- final String hostName = hosts[i].trim().toLowerCase();
- if (doWildcard) {
- match = hostName.endsWith(cn.substring(1));
- if (match && strictWithSubDomains) {
- // If we're in strict mode, then [*.foo.com] is not
- // allowed to match [a.b.foo.com]
- match = countDots(hostName) == countDots(cn);
- }
- } else {
- match = hostName.equals(cn);
- }
- if (match) {
- break out;
- }
- }
- }
- if (!match) {
- throw new SSLException("hostname in certificate didn't match: " + hostnames + " !=" + buf);
- }
- }
-
- public static boolean isIP4Address(final String cn) {
- boolean isIP4 = true;
- String tld = cn;
- int x = cn.lastIndexOf('.');
- // We only bother analyzing the characters after the final dot
- // in the name.
- if (x >= 0 && x + 1 < cn.length()) {
- tld = cn.substring(x + 1);
- }
- for (int i = 0; i < tld.length(); i++) {
- if (!Character.isDigit(tld.charAt(0))) {
- isIP4 = false;
- break;
- }
- }
- return isIP4;
- }
-
- public static boolean acceptableCountryWildcard(final String cn) {
- int cnLen = cn.length();
- if (cnLen >= 7 && cnLen <= 9) {
- // Look for the '.' in the 3rd-last position:
- if (cn.charAt(cnLen - 3) == '.') {
- // Trim off the [*.] and the [.XX].
- String s = cn.substring(2, cnLen - 3);
- // And test against the sorted array of bad 2lds:
- int x = Arrays.binarySearch(BAD_COUNTRY_2LDS, s);
- return x < 0;
- }
- }
- return true;
- }
-
- public static boolean isLocalhost(String host) {
- host = host != null ? host.trim().toLowerCase() : "";
- if (host.startsWith("::1")) {
- int x = host.lastIndexOf('%');
- if (x >= 0) {
- host = host.substring(0, x);
- }
- }
- int x = Arrays.binarySearch(LOCALHOSTS, host);
- return x >= 0;
- }
-
- /**
- * Counts the number of dots "." in a string.
- *
- * @param s string to count dots from
- * @return number of dots
- */
- public static int countDots(final String s) {
- int count = 0;
- for (int i = 0; i < s.length(); i++) {
- if (s.charAt(i) == '.') {
- count++;
- }
- }
- return count;
- }
- }
-
- //from Certificate
- public static String getCN(X509Certificate cert) {
- String[] cns = getCNs(cert);
- boolean foundSomeCNs = cns != null && cns.length >= 1;
- return foundSomeCNs ? cns[0] : null;
- }
-
- public static String[] getCNs(X509Certificate cert) {
- try {
- final String subjectPrincipal = cert.getSubjectX500Principal().getName(X500Principal.RFC2253);
- final LinkedList cnList = new LinkedList();
- final LdapName subjectDN = new LdapName(subjectPrincipal);
- for (final Rdn rds : subjectDN.getRdns()) {
- final Attributes attributes = rds.toAttributes();
- final Attribute cn = attributes.get("cn");
- if (cn != null) {
- try {
- final Object value = cn.get();
- if (value != null) {
- cnList.add(value.toString());
- }
- } catch (NoSuchElementException ignore) {
- } catch (NamingException ignore) {
- }
- }
- }
- if (!cnList.isEmpty()) {
- return cnList.toArray(new String[cnList.size()]);
- }
- } catch (InvalidNameException ignore) {
- }
- return null;
- }
-
- /**
- * Extracts the array of SubjectAlt DNS names from an X509Certificate.
- * Returns null if there aren't any.
- *
- * Note: Java doesn't appear able to extract international characters
- * from the SubjectAlts. It can only extract international characters
- * from the CN field.
- *
- * (Or maybe the version of OpenSSL I'm using to test isn't storing the
- * international characters correctly in the SubjectAlts?).
- *
- * @param cert X509Certificate
- * @return Array of SubjectALT DNS names stored in the certificate.
- */
- public static String[] getDNSSubjectAlts(X509Certificate cert) {
- LinkedList subjectAltList = new LinkedList();
- Collection c = null;
- try {
- c = cert.getSubjectAlternativeNames();
- }
- catch (CertificateParsingException cpe) {
- // Should probably log.debug() this?
- cpe.printStackTrace();
- }
- if (c != null) {
- Iterator it = c.iterator();
- while (it.hasNext()) {
- List list = (List) it.next();
- int type = ((Integer) list.get(0)).intValue();
- // If type is 2, then we've got a dNSName
- if (type == 2) {
- String s = (String) list.get(1);
- subjectAltList.add(s);
- }
- }
- }
- if (!subjectAltList.isEmpty()) {
- String[] subjectAlts = new String[subjectAltList.size()];
- subjectAltList.toArray(subjectAlts);
- return subjectAlts;
- } else {
- return null;
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/maxkey-core/src/main/java/org/maxkey/domain/Groups.java b/maxkey-core/src/main/java/org/maxkey/domain/Groups.java
index 3520f9787..3b8fa9524 100644
--- a/maxkey-core/src/main/java/org/maxkey/domain/Groups.java
+++ b/maxkey-core/src/main/java/org/maxkey/domain/Groups.java
@@ -188,6 +188,12 @@ public class Groups extends JpaBaseDomain implements Serializable {
builder.append(id);
builder.append(", name=");
builder.append(name);
+ builder.append(", dynamic=");
+ builder.append(dynamic);
+ builder.append(", filters=");
+ builder.append(filters);
+ builder.append(", orgIdsList=");
+ builder.append(orgIdsList);
builder.append(", isdefault=");
builder.append(isdefault);
builder.append(", description=");
diff --git a/maxkey-core/src/main/java/org/maxkey/domain/Roles.java b/maxkey-core/src/main/java/org/maxkey/domain/Roles.java
index 76efc21da..d21a438af 100644
--- a/maxkey-core/src/main/java/org/maxkey/domain/Roles.java
+++ b/maxkey-core/src/main/java/org/maxkey/domain/Roles.java
@@ -38,6 +38,14 @@ public class Roles extends JpaBaseDomain implements Serializable {
@Column
private String name;
@Column
+ String dynamic;
+
+ @Column
+ String filters ;
+
+ @Column
+ String orgIdsList;
+ @Column
String status;
@Column
String description;
@@ -119,6 +127,30 @@ public class Roles extends JpaBaseDomain implements Serializable {
this.modifiedDate = modifiedDate;
}
+ public String getDynamic() {
+ return dynamic;
+ }
+
+ public void setDynamic(String dynamic) {
+ this.dynamic = dynamic;
+ }
+
+ public String getFilters() {
+ return filters;
+ }
+
+ public void setFilters(String filters) {
+ this.filters = filters;
+ }
+
+ public String getOrgIdsList() {
+ return orgIdsList;
+ }
+
+ public void setOrgIdsList(String orgIdsList) {
+ this.orgIdsList = orgIdsList;
+ }
+
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@@ -126,6 +158,12 @@ public class Roles extends JpaBaseDomain implements Serializable {
builder.append(id);
builder.append(", name=");
builder.append(name);
+ builder.append(", dynamic=");
+ builder.append(dynamic);
+ builder.append(", filters=");
+ builder.append(filters);
+ builder.append(", orgIdsList=");
+ builder.append(orgIdsList);
builder.append(", status=");
builder.append(status);
builder.append(", description=");
diff --git a/maxkey-core/src/main/java/org/maxkey/web/InitializeContext.java b/maxkey-core/src/main/java/org/maxkey/web/InitializeContext.java
index 7b6bd45a4..1e23d7f0e 100644
--- a/maxkey-core/src/main/java/org/maxkey/web/InitializeContext.java
+++ b/maxkey-core/src/main/java/org/maxkey/web/InitializeContext.java
@@ -62,6 +62,10 @@ public class InitializeContext extends HttpServlet {
_logger.info("SecurityContextHolder StrategyName " + SessionSecurityContextHolderStrategy.class.getCanonicalName());
SecurityContextHolder.setStrategyName(SessionSecurityContextHolderStrategy.class.getCanonicalName());
+ WebContext.applicationContext = applicationContext;
+
+ org.apache.mybatis.jpa.util.WebContext.applicationContext = applicationContext;
+
// List Environment Variables
listEnvVars();
diff --git a/maxkey-core/src/main/java/org/maxkey/web/WebContext.java b/maxkey-core/src/main/java/org/maxkey/web/WebContext.java
index f28569a23..ef6ecbed3 100644
--- a/maxkey-core/src/main/java/org/maxkey/web/WebContext.java
+++ b/maxkey-core/src/main/java/org/maxkey/web/WebContext.java
@@ -57,6 +57,8 @@ public final class WebContext {
public static Properties properties;
+ public static ApplicationContext applicationContext;
+
public static ArrayList sessionAttributeNameList = new ArrayList();
static {
@@ -137,23 +139,24 @@ public final class WebContext {
}
/**
- * get ApplicationContext from web ServletContext configuration.
- *
+ * get ApplicationContext from web ServletContext configuration
* @return ApplicationContext
*/
- public static ApplicationContext getApplicationContext() {
- return WebApplicationContextUtils.getWebApplicationContext(
- getSession().getServletContext());
+ public static ApplicationContext getApplicationContext(){
+ return WebApplicationContextUtils.getWebApplicationContext(getSession().getServletContext());
}
-
+
/**
- * get bean from spring configuration by bean id.
- *
- * @param id String
+ * get bean from spring configuration by bean id
+ * @param id
* @return Object
*/
- public static Object getBean(String id) {
- return getApplicationContext().getBean(id);
+ public static Object getBean(String id){
+ if(applicationContext==null) {
+ return getApplicationContext().getBean(id);
+ }else {
+ return applicationContext.getBean(id);
+ }
}
// below method is common HttpServlet method
diff --git a/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/GroupMemberMapper.java b/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/GroupMemberMapper.java
index 1f4408091..4f4519f7d 100644
--- a/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/GroupMemberMapper.java
+++ b/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/GroupMemberMapper.java
@@ -24,6 +24,7 @@ import java.util.List;
import org.apache.mybatis.jpa.persistence.IJpaBaseMapper;
import org.maxkey.domain.GroupMember;
+import org.maxkey.domain.Groups;
/**
* @author Crystal.sea
@@ -36,4 +37,13 @@ public interface GroupMemberMapper extends IJpaBaseMapper {
public List memberInGroup(GroupMember entity);
public List memberNotInGroup(GroupMember entity);
public List groupMemberInGroup(GroupMember entity);
+
+ public int addDynamicGroupMember(Groups dynamicGroup);
+
+ public int deleteDynamicGroupMember(Groups dynamicGroup);
+
+ public int deleteByGroupId(String groupId);
+
+
+
}
diff --git a/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/GroupsMapper.java b/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/GroupsMapper.java
index c9908ebcc..16b6e009a 100644
--- a/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/GroupsMapper.java
+++ b/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/GroupsMapper.java
@@ -20,6 +20,8 @@
*/
package org.maxkey.persistence.mapper;
+import java.util.List;
+
import org.apache.mybatis.jpa.persistence.IJpaBaseMapper;
import org.maxkey.domain.Groups;
@@ -30,4 +32,5 @@ import org.maxkey.domain.Groups;
public interface GroupsMapper extends IJpaBaseMapper {
+ public List queryDynamicGroups(Groups groups);
}
diff --git a/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/RoleMemberMapper.java b/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/RoleMemberMapper.java
index fc425e44a..7336fbc52 100644
--- a/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/RoleMemberMapper.java
+++ b/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/RoleMemberMapper.java
@@ -24,6 +24,7 @@ import java.util.List;
import org.apache.mybatis.jpa.persistence.IJpaBaseMapper;
import org.maxkey.domain.RoleMember;
+import org.maxkey.domain.Roles;
/**
* @author Crystal.sea
@@ -36,4 +37,10 @@ public interface RoleMemberMapper extends IJpaBaseMapper {
public List memberInRole(RoleMember entity);
public List memberNotInRole(RoleMember entity);
public List roleMemberInRole(RoleMember entity);
+
+ public int addDynamicRoleMember(Roles dynamicRole);
+
+ public int deleteDynamicRoleMember(Roles dynamicRole);
+
+ public int deleteByRoleId(String roleId);
}
diff --git a/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/RolesMapper.java b/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/RolesMapper.java
index 2c2169fca..72e1cf19c 100644
--- a/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/RolesMapper.java
+++ b/maxkey-persistence/src/main/java/org/maxkey/persistence/mapper/RolesMapper.java
@@ -38,4 +38,6 @@ public interface RolesMapper extends IJpaBaseMapper {
public int logisticDeleteRolePermissions(List rolePermissionsList);
public List queryRolePermissions(RolePermissions rolePermissions);
+
+ public List queryDynamicRoles(Roles role);
}
diff --git a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/GroupMemberService.java b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/GroupMemberService.java
index 36f68980e..2cf52b72b 100644
--- a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/GroupMemberService.java
+++ b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/GroupMemberService.java
@@ -19,6 +19,7 @@ package org.maxkey.persistence.service;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.domain.GroupMember;
+import org.maxkey.domain.Groups;
import org.maxkey.persistence.mapper.GroupMemberMapper;
import org.springframework.stereotype.Service;
@@ -37,4 +38,16 @@ public class GroupMemberService extends JpaBaseService{
// TODO Auto-generated method stub
return (GroupMemberMapper)super.getMapper();
}
+
+ public int addDynamicGroupMember(Groups dynamicGroup) {
+ return getMapper().addDynamicGroupMember(dynamicGroup);
+ }
+
+ public int deleteDynamicGroupMember(Groups dynamicGroup) {
+ return getMapper().deleteDynamicGroupMember(dynamicGroup);
+ }
+ public int deleteByGroupId(String groupId) {
+ return getMapper().deleteByGroupId(groupId);
+ }
+
}
diff --git a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/GroupsService.java b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/GroupsService.java
index a17ad4ffe..f35ef818f 100644
--- a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/GroupsService.java
+++ b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/GroupsService.java
@@ -17,14 +17,22 @@
package org.maxkey.persistence.service;
+import java.util.List;
+
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.domain.Groups;
import org.maxkey.persistence.mapper.GroupsMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@Service
public class GroupsService extends JpaBaseService{
+ @Autowired
+ @Qualifier("groupMemberService")
+ GroupMemberService groupMemberService;
+
public GroupsService() {
super(GroupsMapper.class);
}
@@ -37,4 +45,27 @@ public class GroupsService extends JpaBaseService{
// TODO Auto-generated method stub
return (GroupsMapper)super.getMapper();
}
+
+
+ public List queryDynamicGroups(Groups groups){
+ return this.getMapper().queryDynamicGroups(groups);
+ }
+
+ public boolean deleteById(String groupId) {
+ this.remove(groupId);
+ groupMemberService.deleteByGroupId(groupId);
+ return true;
+ }
+
+ public void refreshDynamicGroups(Groups dynamicGroup){
+ if(dynamicGroup.getDynamic().equals("1")) {
+ if(dynamicGroup.getOrgIdsList()!=null && !dynamicGroup.getOrgIdsList().equals("")) {
+ dynamicGroup.setOrgIdsList("'"+dynamicGroup.getOrgIdsList().replace(",", "','")+"'");
+ }
+
+ groupMemberService.deleteDynamicGroupMember(dynamicGroup);
+ groupMemberService.addDynamicGroupMember(dynamicGroup);
+ }
+ }
+
}
diff --git a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/RoleMemberService.java b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/RoleMemberService.java
index 6c1f3b4c4..5ca174d63 100644
--- a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/RoleMemberService.java
+++ b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/RoleMemberService.java
@@ -19,6 +19,7 @@ package org.maxkey.persistence.service;
import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.domain.RoleMember;
+import org.maxkey.domain.Roles;
import org.maxkey.persistence.mapper.RoleMemberMapper;
import org.springframework.stereotype.Service;
@@ -37,4 +38,17 @@ public class RoleMemberService extends JpaBaseService{
// TODO Auto-generated method stub
return (RoleMemberMapper)super.getMapper();
}
+
+
+ public int addDynamicRoleMember(Roles dynamicRole) {
+ return getMapper().addDynamicRoleMember(dynamicRole);
+ }
+
+ public int deleteDynamicRoleMember(Roles dynamicRole) {
+ return getMapper().deleteDynamicRoleMember(dynamicRole);
+ }
+
+ public int deleteByRoleId(String roleId) {
+ return getMapper().deleteByRoleId(roleId);
+ }
}
diff --git a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/RolesService.java b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/RolesService.java
index 98358a314..631a5caee 100644
--- a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/RolesService.java
+++ b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/RolesService.java
@@ -23,11 +23,17 @@ import org.apache.mybatis.jpa.persistence.JpaBaseService;
import org.maxkey.domain.RolePermissions;
import org.maxkey.domain.Roles;
import org.maxkey.persistence.mapper.RolesMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@Service
public class RolesService extends JpaBaseService{
+ @Autowired
+ @Qualifier("roleMemberService")
+ RoleMemberService roleMemberService;
+
public RolesService() {
super(RolesMapper.class);
}
@@ -51,4 +57,25 @@ public class RolesService extends JpaBaseService{
public List queryRolePermissions(RolePermissions rolePermissions){
return getMapper().queryRolePermissions(rolePermissions);
}
+
+ public List queryDynamicRoles(Roles dynamicRole){
+ return this.getMapper().queryDynamicRoles(dynamicRole);
+ }
+
+ public boolean deleteById(String roleId) {
+ this.remove(roleId);
+ roleMemberService.deleteByRoleId(roleId);
+ return true;
+ }
+
+ public void refreshDynamicRoles(Roles dynamicRole){
+ if(dynamicRole.getDynamic().equals("1")) {
+ if(dynamicRole.getOrgIdsList()!=null && !dynamicRole.getOrgIdsList().equals("")) {
+ dynamicRole.setOrgIdsList("'"+dynamicRole.getOrgIdsList().replace(",", "','")+"'");
+ }
+
+ roleMemberService.deleteDynamicRoleMember(dynamicRole);
+ roleMemberService.addDynamicRoleMember(dynamicRole);
+ }
+ }
}
diff --git a/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/GroupMemberMapper.xml b/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/GroupMemberMapper.xml
index ba2c290ea..5b9c5bfed 100644
--- a/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/GroupMemberMapper.xml
+++ b/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/GroupMemberMapper.xml
@@ -108,7 +108,7 @@
AND G.NAME = #{groupName}
- AND GM.TYPE = 'USER'
+ AND GM.TYPE IN( 'USER','USER-DYNAMIC')
AND GM.GROUPID = G.ID
AND GM.MEMBERID = U.ID
@@ -167,7 +167,7 @@
AND G.NAME = #{groupName}
- AND GM.TYPE = 'USER'
+ AND GM.TYPE IN( 'USER','USER-DYNAMIC')
AND GM.GROUPID = G.ID
)
@@ -195,5 +195,54 @@
+
+ INSERT INTO MXK_GROUP_MEMBER(
+ ID,
+ GROUPID,
+ MEMBERID,
+ TYPE
+ )
+ SELECT
+ CONCAT_WS('-','UD','${id}',U.ID) ID,
+ '${id}' GROUPID,
+ U.ID MEMBERID,
+ 'USER-DYNAMIC' TYPE
+ FROM MXK_USERINFO U
+ WHERE NOT EXISTS(
+ SELECT 1 FROM MXK_GROUP_MEMBER GM
+ WHERE GM.GROUPID=#{id}
+ AND GM.MEMBERID=U.ID
+ AND GM.TYPE='USER-DYNAMIC'
+ )
+
+ ${filters}
+
+
+ AND U.DEPARTMENTID IN( ${orgIdsList})
+
+
+
+
+ DELETE FROM MXK_GROUP_MEMBER GM
+ WHERE TYPE = 'USER-DYNAMIC'
+ AND GM.GROUPID=#{id}
+ AND NOT EXISTS(
+ SELECT 1
+ FROM MXK_USERINFO U
+ WHERE 1 = 1
+ AND U.ID=GM.MEMBERID
+
+ ${filters}
+
+
+ AND U.DEPARTMENTID IN( ${orgIdsList})
+
+ )
+
+
+
+ DELETE FROM MXK_GROUP_MEMBER GM
+ WHERE GM.GROUPID=#{value}
+
\ No newline at end of file
diff --git a/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/GroupsMapper.xml b/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/GroupsMapper.xml
index 520822186..4b99abf6c 100644
--- a/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/GroupsMapper.xml
+++ b/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/GroupsMapper.xml
@@ -23,6 +23,16 @@
+
+
UPDATE `MXK_GROUPS` SET
diff --git a/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/RoleMemberMapper.xml b/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/RoleMemberMapper.xml
index 82c2ec087..97b37d252 100644
--- a/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/RoleMemberMapper.xml
+++ b/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/RoleMemberMapper.xml
@@ -108,7 +108,7 @@
AND R.NAME = #{roleName}
- AND RM.TYPE = 'USER'
+ AND RM.TYPE IN( 'USER','USER-DYNAMIC')
AND RM.ROLEID = R.ID
AND RM.MEMBERID = U.ID
@@ -167,14 +167,14 @@
AND R.NAME = #{roleName}
- AND RM.TYPE = 'USER'
+ AND RM.TYPE IN( 'USER','USER-DYNAMIC')
AND RM.ROLEID = R.ID
)
-