Skip to content

Commit 1dfb357

Browse files
HexelDevsgdc3
authored andcommitted
#1119 email show permission and privacy improvements (#1312)
* #1119 new permission and email hider * Updated commands.md * Improved email hiding method * Revert "Improved email hiding method" This reverts commit cb60d7b * New config option, updated tests, config.md and permission_nodes.md * Moved to service import, fixed typo and updated config.md * Removed unused imports O.o
1 parent acfc352 commit 1dfb357

File tree

9 files changed

+88
-28
lines changed

9 files changed

+88
-28
lines changed

docs/commands.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
2-
<!-- File auto-generated on Sat Apr 29 18:27:38 CEST 2017. See docs/commands/commands.tpl.md -->
2+
<!-- File auto-generated on Fri Aug 11 04:37:25 CEST 2017. See docs/commands/commands.tpl.md -->
33

44
## AuthMe Commands
55
You can use the following commands to use the features of AuthMe. Mandatory arguments are marked with `< >`
@@ -47,13 +47,27 @@ brackets; optional arguments are enclosed in square brackets (`[ ]`).
4747
- **/authme reload**: Reload the AuthMeReloaded plugin.
4848
<br />Requires `authme.admin.reload`
4949
- **/authme version**: Show detailed information about the installed AuthMeReloaded version, the developers, contributors, and license.
50-
- **/authme converter** &lt;job>: Converter command for AuthMeReloaded.
50+
- **/authme converter** [job]: Converter command for AuthMeReloaded.
5151
<br />Requires `authme.admin.converter`
5252
- **/authme messages**: Adds missing messages to the current messages file.
5353
<br />Requires `authme.admin.updatemessages`
5454
- **/authme debug** [child] [arg] [arg]: Allows various operations for debugging.
5555
<br />Requires `authme.debug.command`
5656
- **/authme help** [query]: View detailed help for /authme commands.
57+
- **/email**: The AuthMeReloaded email command base.
58+
- **/email show**: Show your current email address.
59+
<br />Requires `authme.player.email.see`
60+
- **/email add** &lt;email> &lt;verifyEmail>: Add a new email address to your account.
61+
<br />Requires `authme.player.email.add`
62+
- **/email change** &lt;oldEmail> &lt;newEmail>: Change an email address of your account.
63+
<br />Requires `authme.player.email.change`
64+
- **/email recover** &lt;email>: Recover your account using an Email address by sending a mail containing a new password.
65+
<br />Requires `authme.player.email.recover`
66+
- **/email code** &lt;code>: Recover your account by submitting a code delivered to your email.
67+
<br />Requires `authme.player.email.recover`
68+
- **/email setpassword** &lt;password>: Set a new password after successfully recovering your account.
69+
<br />Requires `authme.player.email.recover`
70+
- **/email help** [query]: View detailed help for /email commands.
5771
- **/login** &lt;password>: Command to log in using AuthMeReloaded.
5872
<br />Requires `authme.player.login`
5973
- **/login help** [query]: View detailed help for /login commands.
@@ -69,24 +83,11 @@ brackets; optional arguments are enclosed in square brackets (`[ ]`).
6983
- **/changepassword** &lt;oldPassword> &lt;newPassword>: Command to change your password using AuthMeReloaded.
7084
<br />Requires `authme.player.changepassword`
7185
- **/changepassword help** [query]: View detailed help for /changepassword commands.
72-
- **/email**: The AuthMeReloaded email command base.
73-
- **/email show**: Show your current email address.
74-
- **/email add** &lt;email> &lt;verifyEmail>: Add a new email address to your account.
75-
<br />Requires `authme.player.email.add`
76-
- **/email change** &lt;oldEmail> &lt;newEmail>: Change an email address of your account.
77-
<br />Requires `authme.player.email.change`
78-
- **/email recover** &lt;email>: Recover your account using an Email address by sending a mail containing a new password.
79-
<br />Requires `authme.player.email.recover`
80-
- **/email code** &lt;code>: Recover your account by submitting a code delivered to your email.
81-
<br />Requires `authme.player.email.recover`
82-
- **/email setpassword** &lt;password>: Set a new password after successfully recovering your account.
83-
<br />Requires `authme.player.email.recover`
84-
- **/email help** [query]: View detailed help for /email commands.
8586
- **/captcha** &lt;captcha>: Captcha command for AuthMeReloaded.
8687
<br />Requires `authme.player.captcha`
8788
- **/captcha help** [query]: View detailed help for /captcha commands.
8889

8990

9091
---
9192

92-
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Apr 29 18:27:38 CEST 2017
93+
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Fri Aug 11 04:37:25 CEST 2017

docs/config.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
2-
<!-- File auto-generated on Sat Jul 15 19:32:28 CEST 2017. See docs/config/config.tpl.md -->
2+
<!-- File auto-generated on Sat Aug 12 13:49:42 CEST 2017. See docs/config/config.tpl.md -->
33

44
## AuthMe Configuration
55
The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder,
@@ -457,6 +457,12 @@ Security:
457457
# Seconds a user has to wait for before a password recovery mail may be sent again
458458
# This prevents an attacker from abusing AuthMe's email feature.
459459
cooldown: 60
460+
privacy:
461+
# The maill shown using /email show will be partially hidden
462+
# E.g. (if enabled)
463+
# original email: my.email@example.com
464+
# hidden email: my.***@***mple.com
465+
enableEmailMasking: false
460466
# Before a user logs in, various properties are temporarily removed from the player,
461467
# such as OP status, ability to fly, and walk/fly speed.
462468
# Once the user is logged in, we add back the properties we previously saved.
@@ -534,4 +540,4 @@ To change settings on a running server, save your changes to config.yml and use
534540

535541
---
536542

537-
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Jul 15 19:32:28 CEST 2017
543+
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Aug 12 13:49:42 CEST 2017

docs/permission_nodes.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
2-
<!-- File auto-generated on Sat Apr 29 18:27:41 CEST 2017. See docs/permissions/permission_nodes.tpl.md -->
2+
<!-- File auto-generated on Sat Aug 12 13:42:15 CEST 2017. See docs/permissions/permission_nodes.tpl.md -->
33

44
## AuthMe Permission Nodes
55
The following are the permission nodes that are currently supported by the latest dev builds.
@@ -51,6 +51,7 @@ The following are the permission nodes that are currently supported by the lates
5151
- **authme.player.email.add** – Command permission to add an email address.
5252
- **authme.player.email.change** – Command permission to change the email address.
5353
- **authme.player.email.recover** – Command permission to recover an account using its email address.
54+
- **authme.player.email.see** – Command permission to see the own email address.
5455
- **authme.player.login** – Command permission to login.
5556
- **authme.player.logout** – Command permission to logout.
5657
- **authme.player.register** – Command permission to register.
@@ -61,4 +62,4 @@ The following are the permission nodes that are currently supported by the lates
6162

6263
---
6364

64-
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Apr 29 18:27:41 CEST 2017
65+
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Aug 12 13:42:15 CEST 2017

src/main/java/fr/xephi/authme/command/CommandInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ private CommandDescription buildEmailBaseCommand() {
456456
.labels("show", "myemail")
457457
.description("Show Email")
458458
.detailedDescription("Show your current email address.")
459+
.permission(PlayerPermission.SEE_EMAIL)
459460
.executableCommand(ShowEmailCommand.class)
460461
.register();
461462

src/main/java/fr/xephi/authme/command/executable/email/ShowEmailCommand.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import fr.xephi.authme.data.auth.PlayerCache;
66
import fr.xephi.authme.message.MessageKey;
77
import fr.xephi.authme.service.CommonService;
8+
import fr.xephi.authme.settings.properties.SecuritySettings;
89
import fr.xephi.authme.util.Utils;
910
import org.bukkit.entity.Player;
1011

@@ -26,9 +27,22 @@ public class ShowEmailCommand extends PlayerCommand {
2627
public void runCommand(Player player, List<String> arguments) {
2728
PlayerAuth auth = playerCache.getAuth(player.getName());
2829
if (auth != null && !Utils.isEmailEmpty(auth.getEmail())) {
29-
commonService.send(player, MessageKey.EMAIL_SHOW, auth.getEmail());
30+
if(commonService.getProperty(SecuritySettings.USE_EMAIL_MASKING)){
31+
commonService.send(player, MessageKey.EMAIL_SHOW, emailMask(auth.getEmail()));
32+
} else {
33+
commonService.send(player, MessageKey.EMAIL_SHOW, auth.getEmail());
34+
}
3035
} else {
3136
commonService.send(player, MessageKey.SHOW_NO_EMAIL);
3237
}
3338
}
39+
40+
private String emailMask(String email){
41+
String[] frag = email.split("@"); //Split id and domain
42+
int sid = frag[0].length() / 3 + 1; //Define the id view (required length >= 1)
43+
int sdomain = frag[1].length() / 3; //Define the domain view (required length >= 0)
44+
String id = frag[0].substring(0, sid) + "***"; //Build the id
45+
String domain = "***" + frag[1].substring(sdomain); //Build the domain
46+
return id + "@" + domain;
47+
}
3448
}

src/main/java/fr/xephi/authme/permission/PlayerPermission.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public enum PlayerPermission implements PermissionNode {
3030
*/
3131
CHANGE_PASSWORD("authme.player.changepassword"),
3232

33+
/**
34+
* Command permission to see the own email address.
35+
*/
36+
SEE_EMAIL("authme.player.email.see"),
37+
3338
/**
3439
* Command permission to add an email address.
3540
*/

src/main/java/fr/xephi/authme/settings/properties/SecuritySettings.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ public final class SecuritySettings implements SettingsHolder {
132132
public static final Property<Integer> EMAIL_RECOVERY_COOLDOWN_SECONDS =
133133
newProperty("Security.emailRecovery.cooldown", 60);
134134

135+
@Comment({
136+
"The maill shown using /email show will be partially hidden",
137+
"E.g. (if enabled)",
138+
" original email: my.email@example.com",
139+
" hidden email: my.***@***mple.com"
140+
})
141+
public static final Property<Boolean> USE_EMAIL_MASKING =
142+
newProperty("Security.privacy.enableEmailMasking", false);
143+
135144
private SecuritySettings() {
136145
}
137146

src/main/resources/plugin.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ commands:
1818
authme:
1919
description: AuthMe op commands
2020
usage: /authme register|unregister|forcelogin|password|lastlogin|accounts|email|setemail|getip|spawn|setspawn|firstspawn|setfirstspawn|purge|purgeplayer|backup|resetpos|purgebannedplayers|switchantibot|reload|version|converter|messages|debug
21+
email:
22+
description: Add email or recover password
23+
usage: /email show|add|change|recover|code|setpassword
2124
login:
2225
description: Login command
2326
usage: /login <password>
@@ -43,9 +46,6 @@ commands:
4346
aliases:
4447
- changepass
4548
- cp
46-
email:
47-
description: Add email or recover password
48-
usage: /email show|add|change|recover|code|setpassword
4949
captcha:
5050
description: Captcha Command
5151
usage: /captcha <captcha>
@@ -213,6 +213,7 @@ permissions:
213213
authme.player.email.add: true
214214
authme.player.email.change: true
215215
authme.player.email.recover: true
216+
authme.player.email.see: true
216217
authme.player.login: true
217218
authme.player.logout: true
218219
authme.player.register: true
@@ -233,6 +234,7 @@ permissions:
233234
authme.player.email.add: true
234235
authme.player.email.change: true
235236
authme.player.email.recover: true
237+
authme.player.email.see: true
236238
authme.player.email.add:
237239
description: Command permission to add an email address.
238240
default: true
@@ -242,6 +244,9 @@ permissions:
242244
authme.player.email.recover:
243245
description: Command permission to recover an account using its email address.
244246
default: true
247+
authme.player.email.see:
248+
description: Command permission to see the own email address.
249+
default: true
245250
authme.player.login:
246251
description: Command permission to login.
247252
default: true
@@ -258,5 +263,6 @@ permissions:
258263
description: Command permission to unregister.
259264
default: true
260265
authme.vip:
261-
description: When the server is full and someone with this permission joins the server, someone will be kicked.
266+
description: When the server is full and someone with this permission joins the
267+
server, someone will be kicked.
262268
default: op

src/test/java/fr/xephi/authme/command/executable/email/ShowEmailCommandTest.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import fr.xephi.authme.data.auth.PlayerCache;
55
import fr.xephi.authme.message.MessageKey;
66
import fr.xephi.authme.service.CommonService;
7+
import fr.xephi.authme.settings.properties.SecuritySettings;
78
import org.bukkit.entity.Player;
89
import org.junit.Test;
910
import org.junit.runner.RunWith;
@@ -30,7 +31,7 @@ public class ShowEmailCommandTest {
3031
private ShowEmailCommand command;
3132

3233
@Mock
33-
private CommonService commandService;
34+
private CommonService commonService;
3435

3536
@Mock
3637
private PlayerCache playerCache;
@@ -41,12 +42,28 @@ public void shouldShowCurrentEmailMessage() {
4142
Player sender = mock(Player.class);
4243
given(sender.getName()).willReturn(USERNAME);
4344
given(playerCache.getAuth(USERNAME)).willReturn(newAuthWithEmail(CURRENT_EMAIL));
45+
given(commonService.getProperty(SecuritySettings.USE_EMAIL_MASKING)).willReturn(false);
4446

4547
// when
4648
command.executeCommand(sender, Collections.emptyList());
4749

4850
// then
49-
verify(commandService).send(sender, MessageKey.EMAIL_SHOW, CURRENT_EMAIL);
51+
verify(commonService).send(sender, MessageKey.EMAIL_SHOW, CURRENT_EMAIL);
52+
}
53+
54+
@Test
55+
public void shouldShowHiddenEmailMessage() {
56+
// given
57+
Player sender = mock(Player.class);
58+
given(sender.getName()).willReturn(USERNAME);
59+
given(playerCache.getAuth(USERNAME)).willReturn(newAuthWithEmail(CURRENT_EMAIL));
60+
given(commonService.getProperty(SecuritySettings.USE_EMAIL_MASKING)).willReturn(true);
61+
62+
// when
63+
command.executeCommand(sender, Collections.emptyList());
64+
65+
// then
66+
verify(commonService).send(sender, MessageKey.EMAIL_SHOW, "my.***@***mple.com");
5067
}
5168

5269
@Test
@@ -60,7 +77,7 @@ public void shouldReturnNoEmailMessage() {
6077
command.executeCommand(sender, Collections.emptyList());
6178

6279
// then
63-
verify(commandService).send(sender, MessageKey.SHOW_NO_EMAIL);
80+
verify(commonService).send(sender, MessageKey.SHOW_NO_EMAIL);
6481
}
6582

6683
private static PlayerAuth newAuthWithEmail(String email) {

0 commit comments

Comments
 (0)