roles;
15 | }
16 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/DownloadCallback.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs;
10 |
11 | /**
12 | * Download file callback interface
13 | *
14 | * @author Happy Fish / YuQing
15 | * @version Version 1.4
16 | */
17 | public interface DownloadCallback {
18 | /**
19 | * recv file content callback function, may be called more than once when the file downloaded
20 | *
21 | * @param file_size file size
22 | * @param data data buff
23 | * @param bytes data bytes
24 | * @return 0 success, return none zero(errno) if fail
25 | */
26 | public int recv(long file_size, byte[] data, int bytes);
27 | }
28 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/DownloadStream.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common.fastdfs;
2 |
3 | import java.io.IOException;
4 | import java.io.OutputStream;
5 |
6 | /**
7 | * Download file by stream (download callback class)
8 | *
9 | * @author zhouzezhong & Happy Fish / YuQing
10 | * @version Version 1.11
11 | */
12 | public class DownloadStream implements DownloadCallback {
13 | private OutputStream out;
14 | private long currentBytes = 0;
15 |
16 | public DownloadStream(OutputStream out) {
17 | super();
18 | this.out = out;
19 | }
20 |
21 | /**
22 | * recv file content callback function, may be called more than once when the file downloaded
23 | *
24 | * @param fileSize file size
25 | * @param data data buff
26 | * @param bytes data bytes
27 | * @return 0 success, return none zero(errno) if fail
28 | */
29 | public int recv(long fileSize, byte[] data, int bytes) {
30 | try {
31 | out.write(data, 0, bytes);
32 | } catch (IOException ex) {
33 | ex.printStackTrace();
34 | return -1;
35 | }
36 |
37 | currentBytes += bytes;
38 | if (this.currentBytes == fileSize) {
39 | this.currentBytes = 0;
40 | }
41 |
42 | return 0;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/FileInfo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs;
10 |
11 | import java.text.SimpleDateFormat;
12 | import java.util.Date;
13 |
14 | /**
15 | * Server Info
16 | *
17 | * @author Happy Fish / YuQing
18 | * @version Version 1.23
19 | */
20 | public class FileInfo {
21 | protected String source_ip_addr;
22 | protected long file_size;
23 | protected Date create_timestamp;
24 | protected int crc32;
25 |
26 | /**
27 | * Constructor
28 | *
29 | * @param file_size the file size
30 | * @param create_timestamp create timestamp in seconds
31 | * @param crc32 the crc32 signature
32 | * @param source_ip_addr the source storage ip address
33 | */
34 | public FileInfo(long file_size, int create_timestamp, int crc32, String source_ip_addr) {
35 | this.file_size = file_size;
36 | this.create_timestamp = new Date(create_timestamp * 1000L);
37 | this.crc32 = crc32;
38 | this.source_ip_addr = source_ip_addr;
39 | }
40 |
41 | /**
42 | * get the source ip address of the file uploaded to
43 | *
44 | * @return the source ip address of the file uploaded to
45 | */
46 | public String getSourceIpAddr() {
47 | return this.source_ip_addr;
48 | }
49 |
50 | /**
51 | * set the source ip address of the file uploaded to
52 | *
53 | * @param source_ip_addr the source ip address
54 | */
55 | public void setSourceIpAddr(String source_ip_addr) {
56 | this.source_ip_addr = source_ip_addr;
57 | }
58 |
59 | /**
60 | * get the file size
61 | *
62 | * @return the file size
63 | */
64 | public long getFileSize() {
65 | return this.file_size;
66 | }
67 |
68 | /**
69 | * set the file size
70 | *
71 | * @param file_size the file size
72 | */
73 | public void setFileSize(long file_size) {
74 | this.file_size = file_size;
75 | }
76 |
77 | /**
78 | * get the create timestamp of the file
79 | *
80 | * @return the create timestamp of the file
81 | */
82 | public Date getCreateTimestamp() {
83 | return this.create_timestamp;
84 | }
85 |
86 | /**
87 | * set the create timestamp of the file
88 | *
89 | * @param create_timestamp create timestamp in seconds
90 | */
91 | public void setCreateTimestamp(int create_timestamp) {
92 | this.create_timestamp = new Date(create_timestamp * 1000L);
93 | }
94 |
95 | /**
96 | * get the file CRC32 signature
97 | *
98 | * @return the file CRC32 signature
99 | */
100 | public long getCrc32() {
101 | return this.crc32;
102 | }
103 |
104 | /**
105 | * set the create timestamp of the file
106 | *
107 | * @param crc32 the crc32 signature
108 | */
109 | public void setCrc32(int crc32) {
110 | this.crc32 = crc32;
111 | }
112 |
113 | /**
114 | * to string
115 | *
116 | * @return string
117 | */
118 | public String toString() {
119 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
120 | return "source_ip_addr = " + this.source_ip_addr + ", " +
121 | "file_size = " + this.file_size + ", " +
122 | "create_timestamp = " + df.format(this.create_timestamp) + ", " +
123 | "crc32 = " + this.crc32;
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/ProtoStructDecoder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs;
10 |
11 | import java.io.IOException;
12 | import java.lang.reflect.Array;
13 |
14 | /**
15 | * C struct body decoder
16 | *
17 | * @author Happy Fish / YuQing
18 | * @version Version 1.17
19 | */
20 | public class ProtoStructDecoder {
21 | /**
22 | * Constructor
23 | */
24 | public ProtoStructDecoder() {
25 | }
26 |
27 | /**
28 | * decode byte buffer
29 | */
30 | public T[] decode(byte[] bs, Class clazz, int fieldsTotalSize) throws Exception {
31 | if (bs.length % fieldsTotalSize != 0) {
32 | throw new IOException("byte array length: " + bs.length + " is invalid!");
33 | }
34 |
35 | int count = bs.length / fieldsTotalSize;
36 | int offset;
37 | T[] results = (T[]) Array.newInstance(clazz, count);
38 |
39 | offset = 0;
40 | for (int i = 0; i < results.length; i++) {
41 | results[i] = clazz.newInstance();
42 | results[i].setFields(bs, offset);
43 | offset += fieldsTotalSize;
44 | }
45 |
46 | return results;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/ServerInfo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs;
10 |
11 | import java.io.IOException;
12 | import java.net.InetSocketAddress;
13 | import java.net.Socket;
14 |
15 | /**
16 | * Server Info
17 | *
18 | * @author Happy Fish / YuQing
19 | * @version Version 1.7
20 | */
21 | public class ServerInfo {
22 | protected String ip_addr;
23 | protected int port;
24 |
25 | /**
26 | * Constructor
27 | *
28 | * @param ip_addr address of the server
29 | * @param port the port of the server
30 | */
31 | public ServerInfo(String ip_addr, int port) {
32 | this.ip_addr = ip_addr;
33 | this.port = port;
34 | }
35 |
36 | /**
37 | * return the ip address
38 | *
39 | * @return the ip address
40 | */
41 | public String getIpAddr() {
42 | return this.ip_addr;
43 | }
44 |
45 | /**
46 | * return the port of the server
47 | *
48 | * @return the port of the server
49 | */
50 | public int getPort() {
51 | return this.port;
52 | }
53 |
54 | /**
55 | * connect to server
56 | *
57 | * @return connected Socket object
58 | */
59 | public Socket connect() throws IOException {
60 | Socket sock = new Socket();
61 | sock.setReuseAddress(true);
62 | sock.setSoTimeout(ClientGlobal.g_network_timeout);
63 | sock.connect(new InetSocketAddress(this.ip_addr, this.port), ClientGlobal.g_connect_timeout);
64 | return sock;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/StorageServer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs;
10 |
11 | import java.io.IOException;
12 | import java.net.InetSocketAddress;
13 |
14 | /**
15 | * Storage Server Info
16 | *
17 | * @author Happy Fish / YuQing
18 | * @version Version 1.11
19 | */
20 | public class StorageServer extends TrackerServer {
21 | protected int store_path_index = 0;
22 |
23 | /**
24 | * Constructor
25 | *
26 | * @param ip_addr the ip address of storage server
27 | * @param port the port of storage server
28 | * @param store_path the store path index on the storage server
29 | */
30 | public StorageServer(String ip_addr, int port, int store_path) throws IOException {
31 | super(ClientGlobal.getSocket(ip_addr, port), new InetSocketAddress(ip_addr, port));
32 | this.store_path_index = store_path;
33 | }
34 |
35 | /**
36 | * Constructor
37 | *
38 | * @param ip_addr the ip address of storage server
39 | * @param port the port of storage server
40 | * @param store_path the store path index on the storage server
41 | */
42 | public StorageServer(String ip_addr, int port, byte store_path) throws IOException {
43 | super(ClientGlobal.getSocket(ip_addr, port), new InetSocketAddress(ip_addr, port));
44 | if (store_path < 0) {
45 | this.store_path_index = 256 + store_path;
46 | } else {
47 | this.store_path_index = store_path;
48 | }
49 | }
50 |
51 | /**
52 | * @return the store path index on the storage server
53 | */
54 | public int getStorePathIndex() {
55 | return this.store_path_index;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/StructBase.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs;
10 |
11 | import java.io.UnsupportedEncodingException;
12 | import java.util.Date;
13 |
14 | /**
15 | * C struct body decoder
16 | *
17 | * @author Happy Fish / YuQing
18 | * @version Version 1.17
19 | */
20 | public abstract class StructBase {
21 | /**
22 | * set fields
23 | *
24 | * @param bs byte array
25 | * @param offset start offset
26 | */
27 | public abstract void setFields(byte[] bs, int offset);
28 |
29 | protected String stringValue(byte[] bs, int offset, FieldInfo filedInfo) {
30 | try {
31 | return (new String(bs, offset + filedInfo.offset, filedInfo.size, ClientGlobal.g_charset)).trim();
32 | } catch (UnsupportedEncodingException ex) {
33 | ex.printStackTrace();
34 | return null;
35 | }
36 | }
37 |
38 | protected long longValue(byte[] bs, int offset, FieldInfo filedInfo) {
39 | return ProtoCommon.buff2long(bs, offset + filedInfo.offset);
40 | }
41 |
42 | protected int intValue(byte[] bs, int offset, FieldInfo filedInfo) {
43 | return (int) ProtoCommon.buff2long(bs, offset + filedInfo.offset);
44 | }
45 |
46 | protected int int32Value(byte[] bs, int offset, FieldInfo filedInfo) {
47 | return ProtoCommon.buff2int(bs, offset + filedInfo.offset);
48 | }
49 |
50 | protected byte byteValue(byte[] bs, int offset, FieldInfo filedInfo) {
51 | return bs[offset + filedInfo.offset];
52 | }
53 |
54 | protected boolean booleanValue(byte[] bs, int offset, FieldInfo filedInfo) {
55 | return bs[offset + filedInfo.offset] != 0;
56 | }
57 |
58 | protected Date dateValue(byte[] bs, int offset, FieldInfo filedInfo) {
59 | return new Date(ProtoCommon.buff2long(bs, offset + filedInfo.offset) * 1000);
60 | }
61 |
62 | protected static class FieldInfo {
63 | protected String name;
64 | protected int offset;
65 | protected int size;
66 |
67 | public FieldInfo(String name, int offset, int size) {
68 | this.name = name;
69 | this.offset = offset;
70 | this.size = size;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/TrackerGroup.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs;
10 |
11 | import java.io.IOException;
12 | import java.net.InetSocketAddress;
13 | import java.net.Socket;
14 |
15 | /**
16 | * Tracker server group
17 | *
18 | * @author Happy Fish / YuQing
19 | * @version Version 1.17
20 | */
21 | public class TrackerGroup {
22 | public int tracker_server_index;
23 | public InetSocketAddress[] tracker_servers;
24 | protected Integer lock;
25 |
26 | /**
27 | * Constructor
28 | *
29 | * @param tracker_servers tracker servers
30 | */
31 | public TrackerGroup(InetSocketAddress[] tracker_servers) {
32 | this.tracker_servers = tracker_servers;
33 | this.lock = new Integer(0);
34 | this.tracker_server_index = 0;
35 | }
36 |
37 | /**
38 | * return connected tracker server
39 | *
40 | * @return connected tracker server, null for fail
41 | */
42 | public TrackerServer getConnection(int serverIndex) throws IOException {
43 | Socket sock = new Socket();
44 | sock.setReuseAddress(true);
45 | sock.setSoTimeout(ClientGlobal.g_network_timeout);
46 | sock.connect(this.tracker_servers[serverIndex], ClientGlobal.g_connect_timeout);
47 | return new TrackerServer(sock, this.tracker_servers[serverIndex]);
48 | }
49 |
50 | /**
51 | * return connected tracker server
52 | *
53 | * @return connected tracker server, null for fail
54 | */
55 | public TrackerServer getConnection() throws IOException {
56 | int current_index;
57 |
58 | synchronized (this.lock) {
59 | this.tracker_server_index++;
60 | if (this.tracker_server_index >= this.tracker_servers.length) {
61 | this.tracker_server_index = 0;
62 | }
63 |
64 | current_index = this.tracker_server_index;
65 | }
66 |
67 | try {
68 | return this.getConnection(current_index);
69 | } catch (IOException ex) {
70 | System.err.println("connect to server " + this.tracker_servers[current_index].getAddress().getHostAddress() + ":" + this.tracker_servers[current_index].getPort() + " fail");
71 | ex.printStackTrace(System.err);
72 | }
73 |
74 | for (int i = 0; i < this.tracker_servers.length; i++) {
75 | if (i == current_index) {
76 | continue;
77 | }
78 |
79 | try {
80 | TrackerServer trackerServer = this.getConnection(i);
81 |
82 | synchronized (this.lock) {
83 | if (this.tracker_server_index == current_index) {
84 | this.tracker_server_index = i;
85 | }
86 | }
87 |
88 | return trackerServer;
89 | } catch (IOException ex) {
90 | System.err.println("connect to server " + this.tracker_servers[i].getAddress().getHostAddress() + ":" + this.tracker_servers[i].getPort() + " fail");
91 | ex.printStackTrace(System.err);
92 | }
93 | }
94 |
95 | return null;
96 | }
97 |
98 | public Object clone() {
99 | InetSocketAddress[] trackerServers = new InetSocketAddress[this.tracker_servers.length];
100 | for (int i = 0; i < trackerServers.length; i++) {
101 | trackerServers[i] = new InetSocketAddress(this.tracker_servers[i].getAddress().getHostAddress(), this.tracker_servers[i].getPort());
102 | }
103 |
104 | return new TrackerGroup(trackerServers);
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/TrackerServer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs;
10 |
11 | import java.io.IOException;
12 | import java.io.InputStream;
13 | import java.io.OutputStream;
14 | import java.net.InetSocketAddress;
15 | import java.net.Socket;
16 |
17 | /**
18 | * Tracker Server Info
19 | *
20 | * @author Happy Fish / YuQing
21 | * @version Version 1.11
22 | */
23 | public class TrackerServer {
24 | protected Socket sock;
25 | protected InetSocketAddress inetSockAddr;
26 |
27 | /**
28 | * Constructor
29 | *
30 | * @param sock Socket of server
31 | * @param inetSockAddr the server info
32 | */
33 | public TrackerServer(Socket sock, InetSocketAddress inetSockAddr) {
34 | this.sock = sock;
35 | this.inetSockAddr = inetSockAddr;
36 | }
37 |
38 | /**
39 | * get the connected socket
40 | *
41 | * @return the socket
42 | */
43 | public Socket getSocket() throws IOException {
44 | if (this.sock == null) {
45 | this.sock = ClientGlobal.getSocket(this.inetSockAddr);
46 | }
47 |
48 | return this.sock;
49 | }
50 |
51 | /**
52 | * get the server info
53 | *
54 | * @return the server info
55 | */
56 | public InetSocketAddress getInetSocketAddress() {
57 | return this.inetSockAddr;
58 | }
59 |
60 | public OutputStream getOutputStream() throws IOException {
61 | return this.sock.getOutputStream();
62 | }
63 |
64 | public InputStream getInputStream() throws IOException {
65 | return this.sock.getInputStream();
66 | }
67 |
68 | public void close() throws IOException {
69 | if (this.sock != null) {
70 | try {
71 | ProtoCommon.closeSocket(this.sock);
72 | } finally {
73 | this.sock = null;
74 | }
75 | }
76 | }
77 |
78 | protected void finalize() throws Throwable {
79 | this.close();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/UploadCallback.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs;
10 |
11 | import java.io.IOException;
12 | import java.io.OutputStream;
13 |
14 | /**
15 | * upload file callback interface
16 | *
17 | * @author Happy Fish / YuQing
18 | * @version Version 1.0
19 | */
20 | public interface UploadCallback {
21 | /**
22 | * send file content callback function, be called only once when the file uploaded
23 | *
24 | * @param out output stream for writing file content
25 | * @return 0 success, return none zero(errno) if fail
26 | */
27 | public int send(OutputStream out) throws IOException;
28 | }
29 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/UploadStream.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common.fastdfs;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 |
7 | /**
8 | * Upload file by stream
9 | *
10 | * @author zhouzezhong & Happy Fish / YuQing
11 | * @version Version 1.11
12 | */
13 | public class UploadStream implements UploadCallback {
14 | private InputStream inputStream; //input stream for reading
15 | private long fileSize = 0; //size of the uploaded file
16 |
17 | /**
18 | * constructor
19 | *
20 | * @param inputStream input stream for uploading
21 | * @param fileSize size of uploaded file
22 | */
23 | public UploadStream(InputStream inputStream, long fileSize) {
24 | super();
25 | this.inputStream = inputStream;
26 | this.fileSize = fileSize;
27 | }
28 |
29 | /**
30 | * send file content callback function, be called only once when the file uploaded
31 | *
32 | * @param out output stream for writing file content
33 | * @return 0 success, return none zero(errno) if fail
34 | */
35 | public int send(OutputStream out) throws IOException {
36 | long remainBytes = fileSize;
37 | byte[] buff = new byte[256 * 1024];
38 | int bytes;
39 | while (remainBytes > 0) {
40 | try {
41 | if ((bytes = inputStream.read(buff, 0, remainBytes > buff.length ? buff.length : (int) remainBytes)) < 0) {
42 | return -1;
43 | }
44 | } catch (IOException ex) {
45 | ex.printStackTrace();
46 | return -1;
47 | }
48 |
49 | out.write(buff, 0, bytes);
50 | remainBytes -= bytes;
51 | }
52 |
53 | return 0;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/common/MyException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs.common;
10 |
11 | /**
12 | * My Exception
13 | *
14 | * @author Happy Fish / YuQing
15 | * @version Version 1.0
16 | */
17 | public class MyException extends Exception {
18 | public MyException() {
19 | }
20 |
21 | public MyException(String message) {
22 | super(message);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/common/fastdfs/common/NameValuePair.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Happy Fish / YuQing
3 | *
4 | * FastDFS Java Client may be copied only under the terms of the GNU Lesser
5 | * General Public License (LGPL).
6 | * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
7 | */
8 |
9 | package org.zeus.common.fastdfs.common;
10 |
11 | /**
12 | * name(key) and value pair model
13 | *
14 | * @author Happy Fish / YuQing
15 | * @version Version 1.0
16 | */
17 | public class NameValuePair {
18 | protected String name;
19 | protected String value;
20 |
21 | public NameValuePair() {
22 | }
23 |
24 | public NameValuePair(String name) {
25 | this.name = name;
26 | }
27 |
28 | public NameValuePair(String name, String value) {
29 | this.name = name;
30 | this.value = value;
31 | }
32 |
33 | public String getName() {
34 | return this.name;
35 | }
36 |
37 | public void setName(String name) {
38 | this.name = name;
39 | }
40 |
41 | public String getValue() {
42 | return this.value;
43 | }
44 |
45 | public void setValue(String value) {
46 | this.value = value;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/dto/MenuUpdateForm.java:
--------------------------------------------------------------------------------
1 | package org.zeus.dto;
2 |
3 |
4 |
5 | import lombok.Data;
6 | import lombok.Setter;
7 |
8 |
9 | /**
10 | * Created by lizhizhong on 2018/11/26.
11 | */
12 | @Data
13 | @Setter
14 | public class MenuUpdateForm{
15 | private Long id;
16 | private String path;
17 | private String component;
18 | private String name;
19 | private String iconCls;
20 | private Long parentId;
21 |
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/dto/PassWordResetResource.java:
--------------------------------------------------------------------------------
1 | package org.zeus.dto;
2 |
3 | import lombok.Data;
4 | import org.apache.commons.lang3.StringUtils;
5 |
6 | import javax.validation.constraints.AssertTrue;
7 | import javax.validation.constraints.Size;
8 | @Data
9 | public class PassWordResetResource {
10 | public interface PasswordChk {
11 |
12 | }
13 | @Size(min=3,groups = PasswordChk.class)
14 | private String password;
15 |
16 | @Size(min=3,groups = PasswordChk.class)
17 | private String password2;
18 |
19 | @AssertTrue(message = "密码输入不一致,请重新输入",groups = PasswordChk.class)
20 | private boolean isValid(){
21 | return StringUtils.equals(password,password2);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/dto/SysLogSearchForm.java:
--------------------------------------------------------------------------------
1 | package org.zeus.dto;
2 |
3 | import io.swagger.annotations.ApiModelProperty;
4 | import lombok.Data;
5 |
6 | import java.util.Date;
7 |
8 | @Data
9 | public class SysLogSearchForm {
10 |
11 | @ApiModelProperty("日志类型")
12 | private String logType;
13 |
14 | @ApiModelProperty("操作人")
15 | private String operator;
16 |
17 | @ApiModelProperty("操作人角色")
18 | private String operatorRole;
19 |
20 | @ApiModelProperty("开始操作时间")
21 | private Date startTime;
22 |
23 | @ApiModelProperty("结束操作时间")
24 | private Date endTime;
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/dto/UserInfoUpdateForm.java:
--------------------------------------------------------------------------------
1 | package org.zeus.dto;
2 | import io.swagger.annotations.ApiModelProperty;
3 | import lombok.Data;
4 | import org.apache.commons.lang3.StringUtils;
5 | import springfox.documentation.annotations.ApiIgnore;
6 |
7 | @Data
8 | public class UserInfoUpdateForm {
9 |
10 | private Integer schoolNum;
11 | private Long id;
12 |
13 | @ApiModelProperty("本人姓名")
14 | private String teacherName;
15 |
16 | @ApiModelProperty("本人学位")
17 | private String academicDegree;
18 |
19 | @ApiModelProperty("毕业学校")
20 | private String graduatedUniversity;
21 |
22 | @ApiModelProperty("职称")
23 | private String title;
24 |
25 | public boolean isEmpty(){
26 | if(StringUtils.isEmpty(this.getTeacherName())
27 | &&StringUtils.isEmpty(this.getGraduatedUniversity())
28 | &&StringUtils.isEmpty(this.getAcademicDegree())
29 | && StringUtils.isEmpty(this.getTitle())){
30 | return true;
31 | }else{
32 | return false;
33 | }
34 | }
35 |
36 |
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/dto/UserRegister.java:
--------------------------------------------------------------------------------
1 | package org.zeus.dto;
2 |
3 | import io.swagger.annotations.ApiModelProperty;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author: lizhizhong
8 | * CreatedDate: 2018/12/31.
9 | */
10 | @Data
11 | public class UserRegister {
12 |
13 |
14 | @ApiModelProperty(value="登录名",required=true)
15 | private String username;
16 |
17 | @ApiModelProperty(value="密码",required=true)
18 | private String password;
19 |
20 | @ApiModelProperty(value="用户姓名",required=true)
21 | private String teacherName;
22 |
23 | // @ApiModelProperty(value="角色id",required=true)
24 | // private Integer roleId;
25 | }
26 |
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/entity/Menu.java:
--------------------------------------------------------------------------------
1 | package org.zeus.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Menu implements Serializable {
6 | private Integer id;
7 |
8 | private String url;
9 |
10 | private String path;
11 |
12 | private String component;
13 |
14 | private String name;
15 |
16 | private String iconcls;
17 |
18 | private Boolean keepalive;
19 |
20 | private Boolean requireauth;
21 |
22 | private Integer parentid;
23 |
24 | private Boolean enabled;
25 |
26 | private static final long serialVersionUID = 1L;
27 |
28 | public Integer getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Integer id) {
33 | this.id = id;
34 | }
35 |
36 | public String getUrl() {
37 | return url;
38 | }
39 |
40 | public void setUrl(String url) {
41 | this.url = url == null ? null : url.trim();
42 | }
43 |
44 | public String getPath() {
45 | return path;
46 | }
47 |
48 | public void setPath(String path) {
49 | this.path = path == null ? null : path.trim();
50 | }
51 |
52 | public String getComponent() {
53 | return component;
54 | }
55 |
56 | public void setComponent(String component) {
57 | this.component = component == null ? null : component.trim();
58 | }
59 |
60 | public String getName() {
61 | return name;
62 | }
63 |
64 | public void setName(String name) {
65 | this.name = name == null ? null : name.trim();
66 | }
67 |
68 | public String getIconcls() {
69 | return iconcls;
70 | }
71 |
72 | public void setIconcls(String iconcls) {
73 | this.iconcls = iconcls == null ? null : iconcls.trim();
74 | }
75 |
76 | public Boolean getKeepalive() {
77 | return keepalive;
78 | }
79 |
80 | public void setKeepalive(Boolean keepalive) {
81 | this.keepalive = keepalive;
82 | }
83 |
84 | public Boolean getRequireauth() {
85 | return requireauth;
86 | }
87 |
88 | public void setRequireauth(Boolean requireauth) {
89 | this.requireauth = requireauth;
90 | }
91 |
92 | public Integer getParentid() {
93 | return parentid;
94 | }
95 |
96 | public void setParentid(Integer parentid) {
97 | this.parentid = parentid;
98 | }
99 |
100 | public Boolean getEnabled() {
101 | return enabled;
102 | }
103 |
104 | public void setEnabled(Boolean enabled) {
105 | this.enabled = enabled;
106 | }
107 | }
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/entity/MenuRole.java:
--------------------------------------------------------------------------------
1 | package org.zeus.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | public class MenuRole implements Serializable {
6 | private Integer id;
7 |
8 | private Integer mid;
9 |
10 | private Integer rid;
11 |
12 | private String usertype;
13 |
14 | private static final long serialVersionUID = 1L;
15 |
16 | public Integer getId() {
17 | return id;
18 | }
19 |
20 | public void setId(Integer id) {
21 | this.id = id;
22 | }
23 |
24 | public Integer getMid() {
25 | return mid;
26 | }
27 |
28 | public void setMid(Integer mid) {
29 | this.mid = mid;
30 | }
31 |
32 | public Integer getRid() {
33 | return rid;
34 | }
35 |
36 | public void setRid(Integer rid) {
37 | this.rid = rid;
38 | }
39 |
40 | public String getUsertype() {
41 | return usertype;
42 | }
43 |
44 | public void setUsertype(String usertype) {
45 | this.usertype = usertype == null ? null : usertype.trim();
46 | }
47 | }
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/entity/Role.java:
--------------------------------------------------------------------------------
1 | package org.zeus.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Role implements Serializable {
6 | private Integer id;
7 |
8 | private String name;
9 |
10 | private String namezh;
11 |
12 | private static final long serialVersionUID = 1L;
13 |
14 | public Integer getId() {
15 | return id;
16 | }
17 |
18 | public void setId(Integer id) {
19 | this.id = id;
20 | }
21 |
22 | public String getName() {
23 | return name;
24 | }
25 |
26 | public void setName(String name) {
27 | this.name = name == null ? null : name.trim();
28 | }
29 |
30 | public String getNamezh() {
31 | return namezh;
32 | }
33 |
34 | public void setNamezh(String namezh) {
35 | this.namezh = namezh == null ? null : namezh.trim();
36 | }
37 | }
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/entity/SysLog.java:
--------------------------------------------------------------------------------
1 | package org.zeus.entity;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 | import java.util.Date;
7 |
8 | @Data
9 | public class SysLog implements Serializable {
10 | private Integer logId;
11 |
12 | private String logType;
13 |
14 | private String logContent;
15 |
16 | private Date operationTime;
17 |
18 | private String operator;
19 |
20 | private String sysType;
21 |
22 | private String operatorRole;
23 |
24 | private String ipAddress;
25 |
26 | private static final long serialVersionUID = 1L;
27 |
28 | }
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/entity/SysSchool.java:
--------------------------------------------------------------------------------
1 | package org.zeus.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | public class SysSchool implements Serializable {
6 | private Integer id;
7 |
8 | private Integer schoolId;
9 |
10 | private String schoolName;
11 |
12 | private static final long serialVersionUID = 1L;
13 |
14 | public Integer getId() {
15 | return id;
16 | }
17 |
18 | public void setId(Integer id) {
19 | this.id = id;
20 | }
21 |
22 | public Integer getSchoolId() {
23 | return schoolId;
24 | }
25 |
26 | public void setSchoolId(Integer schoolId) {
27 | this.schoolId = schoolId;
28 | }
29 |
30 | public String getSchoolName() {
31 | return schoolName;
32 | }
33 |
34 | public void setSchoolName(String schoolName) {
35 | this.schoolName = schoolName == null ? null : schoolName.trim();
36 | }
37 | }
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/entity/SysSystem.java:
--------------------------------------------------------------------------------
1 | package org.zeus.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | public class SysSystem implements Serializable {
6 | private Integer id;
7 |
8 | private Integer systemId;
9 |
10 | private String systemName;
11 |
12 | private static final long serialVersionUID = 1L;
13 |
14 | public Integer getId() {
15 | return id;
16 | }
17 |
18 | public void setId(Integer id) {
19 | this.id = id;
20 | }
21 |
22 | public Integer getSystemId() {
23 | return systemId;
24 | }
25 |
26 | public void setSystemId(Integer systemId) {
27 | this.systemId = systemId;
28 | }
29 |
30 | public String getSystemName() {
31 | return systemName;
32 | }
33 |
34 | public void setSystemName(String systemName) {
35 | this.systemName = systemName == null ? null : systemName.trim();
36 | }
37 | }
--------------------------------------------------------------------------------
/zeus-common/src/main/java/org/zeus/entity/UserRole.java:
--------------------------------------------------------------------------------
1 | package org.zeus.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | public class UserRole implements Serializable {
6 | private Integer id;
7 |
8 | private Integer userid;
9 |
10 | private Integer rid;
11 |
12 | private static final long serialVersionUID = 1L;
13 |
14 | public Integer getId() {
15 | return id;
16 | }
17 |
18 | public void setId(Integer id) {
19 | this.id = id;
20 | }
21 |
22 | public Integer getUserid() {
23 | return userid;
24 | }
25 |
26 | public void setUserid(Integer userid) {
27 | this.userid = userid;
28 | }
29 |
30 | public Integer getRid() {
31 | return rid;
32 | }
33 |
34 | public void setRid(Integer rid) {
35 | this.rid = rid;
36 | }
37 | }
--------------------------------------------------------------------------------
/zeus-common/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AichaelLee/zeusSpring/251777bef6ed018010fe3981ff270d15b8741862/zeus-common/src/main/resources/application.properties
--------------------------------------------------------------------------------
/zeus-common/src/test/java/org/zeus/DemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package org.zeus;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class DemoApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/zeus-web/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/ValidateCodeBeanConfig.java:
--------------------------------------------------------------------------------
1 | package org.zeus;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
5 | import org.springframework.context.annotation.Bean;
6 | import org.zeus.common.validator.*;
7 |
8 | /**
9 | * @author: lizhizhong
10 | * CreatedDate: 2019/1/14.
11 | */
12 | //@Configuration
13 | public class ValidateCodeBeanConfig {
14 |
15 | @Autowired
16 | private SecurityProperties securityProperties;
17 |
18 | /**
19 | * 图片验证码图片生成器
20 | * @return
21 | */
22 | @Bean
23 | @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
24 | public ValidateCodeGenerator imageValidateCodeGenerator() {
25 | ImageCodeGenerator codeGenerator = new ImageCodeGenerator();
26 | codeGenerator.setSecurityProperties(securityProperties);
27 | return codeGenerator;
28 | }
29 |
30 | /**
31 | * 短信验证码发送器
32 | * @return
33 | */
34 | @Bean
35 | @ConditionalOnMissingBean(SmsCodeSender.class)
36 | public SmsCodeSender smsCodeSender() {
37 | return new DefaultSmsCodeSender();
38 | }
39 |
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/ZeusDmsApplication.java:
--------------------------------------------------------------------------------
1 | package org.zeus;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cache.annotation.EnableCaching;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.ComponentScan;
9 | import org.springframework.session.data.redis.config.ConfigureRedisAction;
10 | import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
11 |
12 | /**
13 | * 2.0的start中默认也有一个spring-boot-autoconfigure-2.0..RELEASE.jar,
14 | * 如果还引用了activiti的activiti-spring-boot-starter-rest-api.jar包,
15 | * 需要将两个包中的 SecurityAutoConfiguration.class 都排除,
16 | */
17 | @SpringBootApplication
18 | @MapperScan({"org.zeus.dmsMapper"})
19 | @ComponentScan({"org.zeus.controller","org.zeus.common","org.zeus.config","org.zeus.service"})
20 | //@EnableCaching
21 | //@EnableRedisHttpSession
22 | public class ZeusDmsApplication {
23 |
24 | public static void main(String[] args) {
25 | SpringApplication.run(ZeusDmsApplication.class, args);
26 | }
27 |
28 | /**
29 | * 这段配置是当程序运行在云端的redis的时候,为了安全,云厂商会关闭config
30 | * 命令,所以在这设置一下,如果是本地部署redis的话,这段配置可以去掉
31 | * @return
32 | */
33 | @Bean
34 | public ConfigureRedisAction configureRedisAction() {
35 | return ConfigureRedisAction.NO_OP;
36 | }
37 |
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/CustomAuthenticationFailureHandler.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.security.authentication.*;
6 | import org.springframework.security.core.AuthenticationException;
7 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
8 | import org.springframework.security.web.authentication.AuthenticationFailureHandler;
9 | import org.springframework.stereotype.Component;
10 | import org.zeus.bean.RespBean;
11 | import org.zeus.common.fw.LogType;
12 | import org.zeus.dmsMapper.SysLogMapper;
13 | import org.zeus.entity.SysLog;
14 |
15 | import javax.servlet.http.HttpServletRequest;
16 | import javax.servlet.http.HttpServletResponse;
17 | import java.io.IOException;
18 | import java.io.PrintWriter;
19 | import java.util.Date;
20 |
21 | /**
22 | * @author: lizhizhong
23 | * CreatedDate: 2019/1/14.
24 | */
25 | @Component
26 | public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler {
27 |
28 | @Autowired
29 | SysLogMapper sysLogMapper;
30 | @Override
31 | public void onAuthenticationFailure(HttpServletRequest req,
32 | HttpServletResponse resp,
33 | AuthenticationException e) throws IOException {
34 | resp.setContentType("application/json;charset=utf-8");
35 | RespBean respBean = null;
36 | String reson = null;
37 | if (e instanceof BadCredentialsException ||
38 | e instanceof UsernameNotFoundException) {
39 | reson="账户名或者密码输入错误!";
40 | respBean = RespBean.error(reson);
41 | } else if (e instanceof LockedException) {
42 | reson="账户被锁定,请联系管理员!";
43 | respBean = RespBean.error("账户被锁定,请联系管理员!");
44 | } else if (e instanceof CredentialsExpiredException) {
45 | reson="密码过期,请联系管理员!";
46 | respBean = RespBean.error("密码过期,请联系管理员!");
47 | } else if (e instanceof AccountExpiredException) {
48 | reson="账户过期,请联系管理员!";
49 | respBean = RespBean.error("账户过期,请联系管理员!");
50 | } else if (e instanceof DisabledException) {
51 | reson="账户被禁用,请联系管理员!";
52 | respBean = RespBean.error("账户被禁用,请联系管理员!");
53 | } else {
54 | reson="其他原因!";
55 | respBean = RespBean.error("其他原因!");
56 | }
57 | // 数据库中插入操作记录
58 | SysLog sysLog = new SysLog();
59 | sysLog.setOperatorRole("未知");
60 | sysLog.setLogType(LogType.LOGIN.getDesc());
61 | sysLog.setOperator((String)req.getSession().getAttribute("SPRING_SECURITY_LAST_USERNAME"));
62 | sysLog.setLogContent(String.format("用户登录失败,失败原因%s",reson));
63 | sysLog.setOperationTime(new Date());
64 | sysLogMapper.insert(sysLog);
65 | resp.setStatus(401);
66 | ObjectMapper om = new ObjectMapper();
67 | PrintWriter out = resp.getWriter();
68 | out.write(om.writeValueAsString(respBean));
69 | out.flush();
70 | out.close();
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/CustomUserTypeAuthenticationFilter.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import org.springframework.security.authentication.AuthenticationServiceException;
4 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
5 | import org.springframework.security.core.Authentication;
6 | import org.springframework.security.core.AuthenticationException;
7 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 |
12 | /**
13 | * 添加自定义的登录时额外字段的验证过滤器
14 | * @author: lizhizhong
15 | * CreatedDate: 2018/11/30.
16 | */
17 | public class CustomUserTypeAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
18 |
19 | public static final String SPRING_SECURITY_FORM_DOMAIN_KEY = "userType";
20 |
21 | /**
22 | *
23 | * @param request
24 | * @param response
25 | * @return Authentication 对象
26 | * @throws AuthenticationException
27 | */
28 | @Override
29 | public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
30 | throws AuthenticationException {
31 |
32 | if (!request.getMethod()
33 | .equals("POST")) {
34 | throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
35 | }
36 |
37 | UsernamePasswordAuthenticationToken authRequest = getAuthRequest(request);
38 | setDetails(request, authRequest);
39 | return this.getAuthenticationManager()
40 | .authenticate(authRequest);
41 | }
42 |
43 | private UsernamePasswordAuthenticationToken getAuthRequest(HttpServletRequest request) {
44 | String username = obtainUsername(request);
45 | String password = obtainPassword(request);
46 | String userType = obtainUserType(request);
47 |
48 | if (username == null) {
49 | username = "";
50 | }
51 | if (password == null) {
52 | password = "";
53 | }
54 | if (userType == null) {
55 | userType = "";
56 | }
57 |
58 | String usernameAndType = String.format("%s%s%s", username.trim(),
59 | String.valueOf(Character.LINE_SEPARATOR), userType);
60 |
61 | return new UsernamePasswordAuthenticationToken(usernameAndType, password);
62 | }
63 |
64 | /**
65 | * 得到用户类型userType 以在UserDetailServices中进行登录验证
66 | * @param request
67 | * @return 用户类型
68 | */
69 | private String obtainUserType(HttpServletRequest request) {
70 | return request.getParameter(SPRING_SECURITY_FORM_DOMAIN_KEY);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/DateConverter.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import org.springframework.core.convert.converter.Converter;
4 |
5 | import java.text.ParseException;
6 | import java.text.SimpleDateFormat;
7 | import java.util.Date;
8 |
9 | /**
10 | * Created by lizhizhong on 2018/11/26
11 | */
12 | public class DateConverter implements Converter {
13 | private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
14 | @Override
15 | public Date convert(String s) {
16 | if ("".equals(s) || s == null) {
17 | return null;
18 | }
19 | try {
20 | return simpleDateFormat.parse(s);
21 | } catch (ParseException e) {
22 | e.printStackTrace();
23 | }
24 | return null;
25 | }
26 | }
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/GlobalAuthenticationConfigurerAdapter.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | /**
6 | * @author: lizhizhong
7 | * CreatedDate: 2018/12/14.
8 | */
9 | @Component
10 | public class GlobalAuthenticationConfigurerAdapter extends org.springframework.security.config.annotation.authentication.configuration.GlobalAuthenticationConfigurerAdapter {
11 | }
12 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/LogTrackInterceptor.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.slf4j.MDC;
5 | import org.springframework.stereotype.Component;
6 | import org.springframework.web.servlet.HandlerInterceptor;
7 | import org.springframework.web.servlet.ModelAndView;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import javax.servlet.http.HttpSession;
12 | import java.security.Principal;
13 |
14 | /**
15 | * @author: lizhizhong
16 | * CreatedDate: 2018/12/1.
17 | */
18 | @Component
19 | @Slf4j
20 | public class LogTrackInterceptor implements HandlerInterceptor {
21 |
22 | private static final String USER_ID = "userId";
23 |
24 | private static final String SESSION_ID = "sessionId";
25 |
26 | private static final String ANONYMOUS = "匿名用户";
27 |
28 | @Override
29 | public boolean preHandle(HttpServletRequest request, HttpServletResponse httpServletResponse, Object o) throws Exception {
30 |
31 | String xForwardedForHeader = request.getHeader("X-Forwarded-For");
32 | String remoteIp = request.getRemoteAddr();
33 |
34 | if(log.isDebugEnabled()){
35 | log.debug("client ip:{}, X-Forwarded-For:{}", remoteIp, xForwardedForHeader);
36 | }
37 |
38 | Principal auth = request.getUserPrincipal();
39 | String userId = "";
40 | if (auth != null) {
41 | userId = auth.getName();
42 | } else {
43 | userId = ANONYMOUS;
44 | }
45 | MDC.put(USER_ID, userId);
46 |
47 | HttpSession session = request.getSession(false);
48 | if (session != null) {
49 | MDC.put(SESSION_ID, session.getId());
50 | }
51 |
52 | return true;
53 | }
54 |
55 | @Override
56 | public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
57 |
58 | if(log.isDebugEnabled()){
59 | log.debug("清除用户ID和SessionID");
60 | }
61 |
62 | MDC.remove(USER_ID);
63 | MDC.remove(SESSION_ID);
64 | }
65 |
66 | @Override
67 | public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
68 |
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/LoginFailedEventListener.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.context.ApplicationListener;
5 | import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent;
6 | import org.springframework.stereotype.Component;
7 |
8 | @Component
9 | @Slf4j
10 | public class LoginFailedEventListener implements ApplicationListener {
11 | @Override
12 | public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent event) {
13 | String username= event.getAuthentication().getName();
14 | log.info("{}登录失败!",username);
15 |
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/ResponseCode.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | /**
4 | * @author lizhizhong
5 | * 自定义响应码
6 | */
7 | public enum ResponseCode {
8 |
9 | /**成功*/
10 | SUCCESS(0,"SUCCESS"),
11 |
12 | /**失败*/
13 | ERROR(1,"ERROR"),
14 |
15 | /**需要登录*/
16 | NEED_LOGIN(10,"NEED_LOGIN"),
17 |
18 | /**非法的参数*/
19 | ILLEGAL_ARGUMENT(2,"ILLEGAL_ARGUMENT");
20 |
21 | private final int code;
22 | private final String desc;
23 |
24 |
25 | ResponseCode(int code, String desc){
26 | this.code = code;
27 | this.desc = desc;
28 | }
29 |
30 | public int getCode(){
31 | return code;
32 | }
33 | public String getDesc(){
34 | return desc;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/RestUsernamePasswordAuthenticationProvider.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
4 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
5 | import org.springframework.security.core.Authentication;
6 | import org.springframework.security.core.AuthenticationException;
7 | import org.springframework.security.core.userdetails.UserDetails;
8 |
9 | /**
10 | *
11 | * @author: lizhizhong
12 | * CreatedDate: 2018/11/28.
13 | */
14 | public class RestUsernamePasswordAuthenticationProvider extends DaoAuthenticationProvider {
15 |
16 | @Override
17 | protected void additionalAuthenticationChecks(UserDetails userDetails,
18 | UsernamePasswordAuthenticationToken authentication)
19 | throws AuthenticationException {
20 |
21 | super.additionalAuthenticationChecks(userDetails, authentication);
22 |
23 | }
24 |
25 | @Override
26 | protected Authentication createSuccessAuthentication(Object principal, Authentication authentication,
27 | UserDetails user) {
28 |
29 | UsernamePasswordAuthenticationToken s = (UsernamePasswordAuthenticationToken) super.createSuccessAuthentication(
30 | principal, authentication, user);
31 |
32 | UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
33 | UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(
34 | principal, token.getCredentials(), s.getAuthorities());
35 | result.setDetails(token.getDetails());
36 |
37 | return result;
38 | }
39 |
40 | @Override
41 | public boolean supports(Class> authentication) {
42 | return UsernamePasswordAuthenticationToken.class
43 | .isAssignableFrom(authentication);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/SecurityConstants.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package org.zeus.common;
5 |
6 | /**
7 | * @author zhailiang
8 | *
9 | */
10 | public interface SecurityConstants {
11 |
12 | /**
13 | * 默认的处理验证码的url前缀
14 | */
15 | String DEFAULT_VALIDATE_CODE_URL_PREFIX = "/code";
16 | /**
17 | * 当请求需要身份认证时,默认跳转的url
18 | *
19 | * @see SecurityController
20 | */
21 | String DEFAULT_UNAUTHENTICATION_URL = "/authentication/require";
22 | /**
23 | * 默认的用户名密码登录请求处理url
24 | */
25 | String DEFAULT_SIGN_IN_PROCESSING_URL_FORM = "/authentication/form";
26 | /**
27 | * 默认的手机验证码登录请求处理url
28 | */
29 | String DEFAULT_SIGN_IN_PROCESSING_URL_MOBILE = "/authentication/mobile";
30 | /**
31 | * 默认的OPENID登录请求处理url
32 | */
33 | String DEFAULT_SIGN_IN_PROCESSING_URL_OPENID = "/authentication/openid";
34 | /**
35 | * 默认登录页面
36 | *
37 | */
38 | String DEFAULT_SIGN_IN_PAGE_URL = "/imooc-signIn.html";
39 | /**
40 | * 验证图片验证码时,http请求中默认的携带图片验证码信息的参数的名称
41 | */
42 | String DEFAULT_PARAMETER_NAME_CODE_IMAGE = "imageCode";
43 | /**
44 | * 验证短信验证码时,http请求中默认的携带短信验证码信息的参数的名称
45 | */
46 | String DEFAULT_PARAMETER_NAME_CODE_SMS = "smsCode";
47 | /**
48 | * 发送短信验证码 或 验证短信验证码时,传递手机号的参数的名称
49 | */
50 | String DEFAULT_PARAMETER_NAME_MOBILE = "mobile";
51 | /**
52 | * openid参数名
53 | */
54 | String DEFAULT_PARAMETER_NAME_OPENID = "openId";
55 | /**
56 | * providerId参数名
57 | */
58 | String DEFAULT_PARAMETER_NAME_PROVIDERID = "providerId";
59 | /**
60 | * session失效默认的跳转地址
61 | */
62 | String DEFAULT_SESSION_INVALID_URL = "/imooc-session-invalid.html";
63 | /**
64 | * 获取第三方用户信息的url
65 | */
66 | String DEFAULT_SOCIAL_USER_INFO_URL = "/social/user";
67 | }
68 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/SecurityCoreConfig.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.zeus.common.validator.SecurityProperties;
6 |
7 | /**
8 | * @author: lizhizhong
9 | * CreatedDate: 2019/1/14.
10 | */
11 | @Configuration
12 | @EnableConfigurationProperties(SecurityProperties.class)
13 | public class SecurityCoreConfig {
14 |
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/ServerResponse.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 |
4 | import com.fasterxml.jackson.annotation.JsonIgnore;
5 | import com.fasterxml.jackson.annotation.JsonInclude;
6 |
7 | import java.io.Serializable;
8 |
9 | /**
10 | * 服务响应对象封装
11 | * @author aichaellee
12 | */
13 | //保证序列化json的时候,如果是null的对象,key也会消失*/
14 | //@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
15 | @JsonInclude(JsonInclude.Include.NON_NULL)
16 | public class ServerResponse implements Serializable {
17 |
18 | private int status;
19 | private String msg;
20 | private T data;
21 |
22 | private ServerResponse(int status){
23 | this.status = status;
24 | }
25 | private ServerResponse(int status, T data){
26 | this.status = status;
27 | this.data = data;
28 | }
29 |
30 | private ServerResponse(int status, String msg, T data){
31 | this.status = status;
32 | this.msg = msg;
33 | this.data = data;
34 | }
35 |
36 | private ServerResponse(int status, String msg){
37 | this.status = status;
38 | this.msg = msg;
39 | }
40 |
41 | @JsonIgnore
42 | // 使之不在json序列化结果当中
43 | public boolean isSuccess(){
44 | return this.status == ResponseCode.SUCCESS.getCode();
45 | }
46 |
47 | public int getStatus(){
48 | return status;
49 | }
50 | public T getData(){
51 | return data;
52 | }
53 | public String getMsg(){
54 | return msg;
55 | }
56 |
57 |
58 | public static ServerResponse createBySuccess(){
59 | return new ServerResponse(ResponseCode.SUCCESS.getCode());
60 | }
61 |
62 | public static ServerResponse createBySuccess(String msg){
63 | return new ServerResponse(ResponseCode.SUCCESS.getCode(),msg);
64 | }
65 |
66 | public static ServerResponse createBySuccess(T data){
67 | return new ServerResponse(ResponseCode.SUCCESS.getCode(),data);
68 | }
69 |
70 | public static ServerResponse createBySuccess(String msg,T data){
71 | return new ServerResponse(ResponseCode.SUCCESS.getCode(),msg,data);
72 | }
73 |
74 |
75 | public static ServerResponse createByError(){
76 | return new ServerResponse(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDesc());
77 | }
78 |
79 |
80 | public static ServerResponse createByError(String errorMessage){
81 | return new ServerResponse(ResponseCode.ERROR.getCode(),errorMessage);
82 | }
83 |
84 | public static ServerResponse createByErrorCodeMessage(int errorCode,String errorMessage){
85 | return new ServerResponse(errorCode,errorMessage);
86 | }
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/SmsCodeAuthenticationFilter.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import org.springframework.security.authentication.AuthenticationServiceException;
4 | import org.springframework.security.core.Authentication;
5 | import org.springframework.security.core.AuthenticationException;
6 | import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
7 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
8 | import org.springframework.util.Assert;
9 |
10 | import javax.servlet.ServletException;
11 | import javax.servlet.http.HttpServletRequest;
12 | import javax.servlet.http.HttpServletResponse;
13 | import java.io.IOException;
14 |
15 | public class SmsCodeAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
16 | /**
17 | * request中必须含有mobile参数
18 | */
19 | private String mobileParameter = SecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE;
20 | /**
21 | * post请求
22 | */
23 | private boolean postOnly = true;
24 |
25 | protected SmsCodeAuthenticationFilter() {
26 | /**
27 | * 处理的手机验证码登录请求处理url
28 | */
29 | super(new AntPathRequestMatcher(SecurityConstants.DEFAULT_SIGN_IN_PROCESSING_URL_MOBILE, "POST"));
30 | }
31 |
32 | @Override
33 | public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
34 | //判断是是不是post请求
35 | if (postOnly && !request.getMethod().equals("POST")) {
36 | throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
37 | }
38 | //从请求中获取手机号码
39 | String mobile = obtainMobile(request);
40 |
41 | if (mobile == null) {
42 | mobile = "";
43 | }
44 |
45 | mobile = mobile.trim();
46 | //创建SmsCodeAuthenticationToken(未认证)
47 | SmsCodeAuthenticationToken authRequest = new SmsCodeAuthenticationToken(mobile);
48 |
49 | //设置用户信息
50 | setDetails(request, authRequest);
51 | //返回Authentication实例
52 | return this.getAuthenticationManager().authenticate(authRequest);
53 | }
54 |
55 | /**
56 | * 获取手机号
57 | */
58 | protected String obtainMobile(HttpServletRequest request) {
59 | return request.getParameter(mobileParameter);
60 | }
61 |
62 | protected void setDetails(HttpServletRequest request, SmsCodeAuthenticationToken authRequest) {
63 | authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
64 | }
65 |
66 | public void setMobileParameter(String usernameParameter) {
67 | Assert.hasText(usernameParameter, "Username parameter must not be empty or null");
68 | this.mobileParameter = usernameParameter;
69 | }
70 |
71 | public void setPostOnly(boolean postOnly) {
72 | this.postOnly = postOnly;
73 | }
74 |
75 | public final String getMobileParameter() {
76 | return mobileParameter;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/SmsCodeAuthenticationProvider.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import org.springframework.security.authentication.AuthenticationProvider;
4 | import org.springframework.security.authentication.InternalAuthenticationServiceException;
5 | import org.springframework.security.core.Authentication;
6 | import org.springframework.security.core.AuthenticationException;
7 | import org.springframework.security.core.userdetails.UserDetails;
8 | import org.springframework.security.core.userdetails.UserDetailsService;
9 | import org.zeus.service.SecurityMobileUserDetailService;
10 |
11 | public class SmsCodeAuthenticationProvider implements AuthenticationProvider {
12 | private SecurityMobileUserDetailService userDetailsService;
13 |
14 | @Override
15 | public Authentication authenticate(Authentication authentication) throws AuthenticationException {
16 | SmsCodeAuthenticationToken authenticationToken = (SmsCodeAuthenticationToken) authentication;
17 | //调用自定义的userDetailsService认证
18 | UserDetails user = userDetailsService.loadUserByUsername((String) authenticationToken.getPrincipal());
19 |
20 | if (user == null) {
21 | throw new InternalAuthenticationServiceException("无法获取用户信息");
22 | }
23 | //如果user不为空重新构建SmsCodeAuthenticationToken(已认证)
24 | SmsCodeAuthenticationToken authenticationResult = new SmsCodeAuthenticationToken(user, user.getAuthorities());
25 |
26 | authenticationResult.setDetails(authenticationToken.getDetails());
27 |
28 | return authenticationResult;
29 | }
30 |
31 | /**
32 | * 只有Authentication为SmsCodeAuthenticationToken使用此Provider认证
33 | * @param authentication
34 | * @return
35 | */
36 | @Override
37 | public boolean supports(Class> authentication) {
38 | return SmsCodeAuthenticationToken.class.isAssignableFrom(authentication);
39 | }
40 |
41 | public UserDetailsService getUserDetailsService() {
42 | return userDetailsService;
43 | }
44 |
45 | public void setUserDetailsService(SecurityMobileUserDetailService userDetailsService) {
46 | this.userDetailsService = userDetailsService;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/SmsCodeAuthenticationToken.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | import org.springframework.security.authentication.AbstractAuthenticationToken;
4 | import org.springframework.security.core.GrantedAuthority;
5 |
6 | import java.util.Collection;
7 |
8 | public class SmsCodeAuthenticationToken extends AbstractAuthenticationToken {
9 | private static final long serialVersionUID = 2383092775910246006L;
10 |
11 | /**
12 | * 手机号
13 | */
14 | private final Object principal;
15 |
16 | /**
17 | * SmsCodeAuthenticationFilter中构建的未认证的Authentication
18 | * @param mobile
19 | */
20 | public SmsCodeAuthenticationToken(String mobile) {
21 | super(null);
22 | this.principal = mobile;
23 | setAuthenticated(false);
24 | }
25 |
26 | /**
27 | * SmsCodeAuthenticationProvider中构建已认证的Authentication
28 | * @param principal
29 | * @param authorities
30 | */
31 | public SmsCodeAuthenticationToken(Object principal,
32 | Collection extends GrantedAuthority> authorities) {
33 | super(authorities);
34 | this.principal = principal;
35 | super.setAuthenticated(true); // must use super, as we override
36 | }
37 |
38 | @Override
39 | public Object getCredentials() {
40 | return null;
41 | }
42 |
43 | @Override
44 | public Object getPrincipal() {
45 | return this.principal;
46 | }
47 |
48 | /**
49 | * @param isAuthenticated
50 | * @throws IllegalArgumentException
51 | */
52 | public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
53 | if (isAuthenticated) {
54 | throw new IllegalArgumentException(
55 | "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
56 | }
57 |
58 | super.setAuthenticated(false);
59 | }
60 |
61 | @Override
62 | public void eraseCredentials() {
63 | super.eraseCredentials();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/UserTypeEnum.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 |
3 | /**
4 | * @author: lizhizhong
5 | * CreatedDate: 2018/12/1.
6 | */
7 | public enum UserTypeEnum {
8 |
9 | /**
10 | * 学生
11 | */
12 | STUDENT("学生","3"),
13 |
14 | /**
15 | * 管理员
16 | */
17 | ADMIN("管理员","1"),
18 |
19 | /**
20 | * 教师
21 | */
22 | TEACHER("教师","2");
23 |
24 | private String userTypeZh;
25 | private String userType;
26 |
27 |
28 | UserTypeEnum(String userTypename,String userType){
29 | this.userTypeZh = userTypename;
30 | this.userType = userType;
31 |
32 | }
33 |
34 | public String getUserType(){
35 | return this.userType;
36 | }
37 |
38 | /**
39 | *
40 | * @param userType
41 | * @return 用户类型的中文名称
42 | */
43 | public static String getUserTypeZh(String userType){
44 |
45 | for(UserTypeEnum value:UserTypeEnum.values()){
46 | if(value.getUserType().equals(userType)){
47 | return value.userTypeZh;
48 | }
49 |
50 | }
51 | return null;
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/UserUtils.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common;
2 | import org.springframework.security.core.context.SecurityContextHolder;
3 | import org.zeus.bean.User;
4 |
5 | /**
6 | * 得到当前用户信息
7 | * @author: lizhizhong
8 | * CreatedDate: 2018/11/28.
9 | */
10 | public class UserUtils {
11 | public static User getCurrentUser() {
12 |
13 | return (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
14 |
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/fw/LogType.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common.fw;
2 |
3 | /**
4 | * 日志类型
5 | * @author: lizhizhong
6 | * CreatedDate: 2018/12/04.
7 | */
8 |
9 | public enum LogType {
10 |
11 | /**
12 | * 默认0操作
13 | */
14 | OPERATION(0,"流程操作"),
15 |
16 | /**
17 | * 1登录
18 | */
19 | LOGIN(1,"登录操作"),
20 |
21 | /**
22 | * 2 删除
23 | */
24 | DELETE(2,"删除操作"),
25 |
26 | /**
27 | * 3 更改
28 | */
29 | UPDATE(3,"更改操作"),
30 |
31 | /**
32 | * 审核
33 | */
34 | AUDITING(4,"审核操作"),
35 |
36 | /**
37 | * 检测
38 | */
39 | DETECTION(5,"检测操作"),
40 |
41 | /**
42 | * 课题相似性
43 | */
44 | TOPIC_SIMILARITY(6,"相关性操作");
45 |
46 | private int code;
47 | private String desc;
48 |
49 | LogType(int code,String desc){
50 | this.code = code;
51 | this.desc = desc;
52 | }
53 |
54 | public String getDesc(){
55 | return this.desc;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/fw/annotation/SystemLog.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common.fw.annotation;
2 |
3 |
4 | import org.zeus.common.fw.LogType;
5 |
6 | import java.lang.annotation.*;
7 |
8 | /**
9 | * 方法级别的系统日志
10 | * @author lizhizhong
11 | * @date 2018-12-04
12 | */
13 | @Target({ElementType.PARAMETER, ElementType.METHOD})//作用于参数或方法上
14 | @Retention(RetentionPolicy.RUNTIME)
15 | @Documented
16 | public @interface SystemLog {
17 |
18 | /**
19 | * 日志名称
20 | * @return
21 | */
22 | String description() default "";
23 |
24 | /**
25 | * 日志类型
26 | * @return
27 | */
28 | LogType type() default LogType.OPERATION;
29 | }
30 |
--------------------------------------------------------------------------------
/zeus-web/src/main/java/org/zeus/common/util/DBUtil.java:
--------------------------------------------------------------------------------
1 | package org.zeus.common.util;
2 |
3 |
4 | import java.util.Map;
5 |
6 | import com.alibaba.druid.pool.DruidDataSource;
7 |
8 | import org.zeus.config.DataSourceContextHolder;
9 | import org.zeus.config.DynamicDataSource;
10 | import org.zeus.entity.University;
11 |
12 | public class DBUtil {
13 |
14 | public static void addOrChangeDataSource(University user){
15 |
16 | /**
17 | * 创建动态数据源
18 | */
19 | Map