Skip to content

Commit 9ee604c

Browse files
committed
login password supplementary recording
1 parent f8a3134 commit 9ee604c

File tree

104 files changed

+4122
-1122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+4122
-1122
lines changed

agora-app-server/.mvn/wrapper/MavenWrapperDownloader.java

Lines changed: 0 additions & 118 deletions
This file was deleted.
-49.5 KB
Binary file not shown.

agora-app-server/.mvn/wrapper/maven-wrapper.properties

Lines changed: 0 additions & 2 deletions
This file was deleted.

agora-app-server/app_user_info.sql

Lines changed: 0 additions & 12 deletions
This file was deleted.

agora-app-server/pom.xml

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@
55
<parent>
66
<artifactId>easemob-im-app-server</artifactId>
77
<groupId>com.easemob.im</groupId>
8-
<version>1.1.2.1.Final</version>
8+
<version>1.1.3.3.Final</version>
99
</parent>
1010

1111
<artifactId>agora-app-server</artifactId>
1212

1313
<dependencies>
14-
<dependency>
15-
<groupId>org.springframework.boot</groupId>
16-
<artifactId>spring-boot-starter-data-redis</artifactId>
17-
</dependency>
18-
<!-- <dependency>-->
19-
<!-- <groupId>org.springframework.cloud</groupId>-->
20-
<!-- <artifactId>spring-cloud-starter-consul-discovery</artifactId>-->
21-
<!-- <version>2.1.0.RELEASE</version>-->
22-
<!-- </dependency>-->
2314
<dependency>
2415
<groupId>org.springframework.boot</groupId>
2516
<artifactId>spring-boot-starter-thymeleaf</artifactId>
@@ -49,33 +40,27 @@
4940
<dependency>
5041
<groupId>redis.clients</groupId>
5142
<artifactId>jedis</artifactId>
52-
<version>2.9.1</version>
43+
<!-- <version>2.9.1</version>-->
5344
</dependency>
5445
<dependency>
55-
<groupId>commons-lang</groupId>
56-
<artifactId>commons-lang</artifactId>
57-
<version>2.6</version>
58-
<scope>compile</scope>
46+
<groupId>org.springframework.data</groupId>
47+
<artifactId>spring-data-redis</artifactId>
48+
<!-- <version>2.3.2.RELEASE</version>-->
5949
</dependency>
6050
<dependency>
61-
<groupId>mysql</groupId>
62-
<artifactId>mysql-connector-java</artifactId>
63-
<version>5.1.36</version>
51+
<groupId>io.lettuce</groupId>
52+
<artifactId>lettuce-core</artifactId>
6453
</dependency>
6554
<dependency>
66-
<groupId>org.springframework.boot</groupId>
67-
<artifactId>spring-boot-starter-data-jpa</artifactId>
68-
<exclusions>
69-
<exclusion>
70-
<groupId>org.apache.logging.log4j</groupId>
71-
<artifactId>log4j-to-slf4j</artifactId>
72-
</exclusion>
73-
</exclusions>
55+
<groupId>commons-lang</groupId>
56+
<artifactId>commons-lang</artifactId>
57+
<version>2.6</version>
58+
<scope>compile</scope>
7459
</dependency>
7560
<dependency>
76-
<groupId>com.easemob.im</groupId>
77-
<artifactId>im-sdk-core</artifactId>
78-
<version>0.5.1</version>
61+
<groupId>org.springframework.cloud</groupId>
62+
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
63+
<version>2.1.0.RELEASE</version>
7964
</dependency>
8065
</dependencies>
8166

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
package com.easemob.agora.AgoraIO;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.IOException;
5+
import java.util.TreeMap;
6+
7+
import static com.easemob.agora.AgoraIO.Utils.crc32;
8+
9+
10+
public class AccessToken {
11+
public enum Privileges {
12+
kJoinChannel(1),
13+
kPublishAudioStream(2),
14+
kPublishVideoStream(3),
15+
kPublishDataStream(4),
16+
17+
// For RTM only
18+
kRtmLogin(1000);
19+
20+
// The following privileges have not
21+
// been implemented yet.
22+
23+
//kPublishAudiocdn(5),
24+
//kPublishVideoCdn(6),
25+
//kRequestPublishAudioStream(7),
26+
//kRequestPublishVideoStream(8),
27+
//kRequestPublishDataStream(9),
28+
//kInvitePublishAudioStream(10),
29+
//kInvitePublishVideoStream(11),
30+
//kInvitePublishDataStream(12),
31+
//kAdministrateChannel(101),
32+
33+
public short intValue;
34+
35+
Privileges(int value) {
36+
intValue = (short) value;
37+
}
38+
}
39+
40+
private static final String VER = "006";
41+
42+
public String appId;
43+
public String appCertificate;
44+
public String channelName;
45+
public String uid;
46+
public byte[] signature;
47+
public byte[] messageRawContent;
48+
public int crcChannelName;
49+
public int crcUid;
50+
public PrivilegeMessage message;
51+
public int expireTimestamp;
52+
53+
public AccessToken(String appId, String appCertificate, String channelName, String uid) {
54+
this.appId = appId;
55+
this.appCertificate = appCertificate;
56+
this.channelName = channelName;
57+
this.uid = uid;
58+
this.crcChannelName = 0;
59+
this.crcUid = 0;
60+
this.message = new PrivilegeMessage();
61+
}
62+
63+
public String build() throws Exception {
64+
if (! Utils.isUUID(appId)) {
65+
return "";
66+
}
67+
68+
if (!Utils.isUUID(appCertificate)) {
69+
return "";
70+
}
71+
72+
messageRawContent = Utils.pack(message);
73+
signature = generateSignature(appCertificate,
74+
appId, channelName, uid, messageRawContent);
75+
crcChannelName = Utils.crc32(channelName);
76+
crcUid = Utils.crc32(uid);
77+
78+
PackContent packContent = new PackContent(signature, crcChannelName, crcUid, messageRawContent);
79+
byte[] content = Utils.pack(packContent);
80+
return getVersion() + this.appId + Utils.base64Encode(content);
81+
}
82+
83+
public void addPrivilege(Privileges privilege, int expireTimestamp) {
84+
message.messages.put(privilege.intValue, expireTimestamp);
85+
}
86+
87+
public static String getVersion() {
88+
return VER;
89+
}
90+
91+
public static byte[] generateSignature(String appCertificate,
92+
String appID, String channelName, String uid, byte[] message) throws Exception {
93+
94+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
95+
try {
96+
baos.write(appID.getBytes());
97+
baos.write(channelName.getBytes());
98+
baos.write(uid.getBytes());
99+
baos.write(message);
100+
} catch (IOException e) {
101+
e.printStackTrace();
102+
}
103+
return Utils.hmacSign(appCertificate, baos.toByteArray());
104+
}
105+
106+
public boolean fromString(String token) {
107+
if (!getVersion().equals(token.substring(0, Utils.VERSION_LENGTH))) {
108+
return false;
109+
}
110+
111+
try {
112+
appId = token.substring(Utils.VERSION_LENGTH, Utils.VERSION_LENGTH + Utils.APP_ID_LENGTH);
113+
PackContent packContent = new PackContent();
114+
Utils.unpack(Utils.base64Decode(token.substring(Utils.VERSION_LENGTH + Utils.APP_ID_LENGTH, token.length())), packContent);
115+
signature = packContent.signature;
116+
crcChannelName = packContent.crcChannelName;
117+
crcUid = packContent.crcUid;
118+
messageRawContent = packContent.rawMessage;
119+
Utils.unpack(messageRawContent, message);
120+
} catch (Exception e) {
121+
e.printStackTrace();
122+
return false;
123+
}
124+
125+
return true;
126+
}
127+
128+
public class PrivilegeMessage implements PackableEx {
129+
public int salt;
130+
public int ts;
131+
public TreeMap<Short, Integer> messages;
132+
133+
public PrivilegeMessage() {
134+
salt = Utils.randomInt();
135+
ts = Utils.getTimestamp() + 24 * 3600;
136+
messages = new TreeMap<>();
137+
}
138+
139+
@Override
140+
public ByteBuf marshal(ByteBuf out) {
141+
return out.put(salt).put(ts).putIntMap(messages);
142+
}
143+
144+
@Override
145+
public void unmarshal(ByteBuf in) {
146+
salt = in.readInt();
147+
ts = in.readInt();
148+
messages = in.readIntMap();
149+
}
150+
}
151+
152+
public class PackContent implements PackableEx {
153+
public byte[] signature;
154+
public int crcChannelName;
155+
public int crcUid;
156+
public byte[] rawMessage;
157+
158+
public PackContent() {
159+
// Nothing done
160+
}
161+
162+
public PackContent(byte[] signature, int crcChannelName, int crcUid, byte[] rawMessage) {
163+
this.signature = signature;
164+
this.crcChannelName = crcChannelName;
165+
this.crcUid = crcUid;
166+
this.rawMessage = rawMessage;
167+
}
168+
169+
@Override
170+
public ByteBuf marshal(ByteBuf out) {
171+
return out.put(signature).put(crcChannelName).put(crcUid).put(rawMessage);
172+
}
173+
174+
@Override
175+
public void unmarshal(ByteBuf in) {
176+
signature = in.readBytes();
177+
crcChannelName = in.readInt();
178+
crcUid = in.readInt();
179+
rawMessage = in.readBytes();
180+
}
181+
}
182+
}

0 commit comments

Comments
 (0)