Skip to content

Commit

Permalink
user restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
ZihengSun committed Feb 26, 2019
1 parent cc0a6f1 commit 90dbcf7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
8 changes: 4 additions & 4 deletions WebContent/WEB-INF/views/frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<li><a href="feature" th:href="@{/web/function}">Function</a></li>
<li><a th:if="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="feature" th:href="@{/web/feature}">Feature</a></li>
<li><a th:if="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="demo" th:href="@{/web/demo}">Demo</a></li>
<li><a th:if="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="people" th:href="@{/web/people}">People</a></li>
<!-- <li><a th:if="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="people" th:href="@{/web/people}">People</a></li> -->
<li><a th:if="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="publication" th:href="@{/web/publication}">Publication</a></li>
<li><a th:if="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="about" th:href="@{/web/about}">About</a></li>
<li>
Expand All @@ -76,12 +76,12 @@
<li><a href="feature" th:href="@{/web/function}">Function</a></li>
<li><a href="feature" th:href="@{/web/feature}">Feature</a></li>
<li><a href="demo" th:href="@{/web/demo}">Demo</a></li>
<li><a href="people" th:href="@{/web/people}">People</a></li>
<!-- <li><a href="people" th:href="@{/web/people}">People</a></li> -->
<li><a href="publication" th:href="@{/web/publication}">Publication</a></li>
<li><a href="about" th:href="@{/web/about}">About</a></li>
<li>
<a th:if="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="#" >Welcome, Friend</a>
<a th:unless="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="user_profile" th:href="@{/web/user_profile}" th:text="'Welcome, '+${session.sessionUser}" >Welcome, Friend</a>
<a th:if="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="#" >Welcome</a>
<a th:unless="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="user_profile" th:href="@{/web/user_profile}" th:text="'Welcome, '+${session.sessionUser}" >Welcome</a>
</li>
<li>
<a th:if="${session.sessionUser == null} or ${session.sessionUser} eq 'Friend'" href="login" th:href="@{/web/login}" >Login</a>
Expand Down
38 changes: 37 additions & 1 deletion src/edu/gmu/csiss/earthcube/cyberconnector/user/UserTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import edu.gmu.csiss.earthcube.cyberconnector.services.Service;
import edu.gmu.csiss.earthcube.cyberconnector.utils.BaseTool;
import edu.gmu.csiss.earthcube.cyberconnector.utils.Message;
import edu.gmu.csiss.earthcube.cyberconnector.utils.SysDir;

/**
*Class UserTool.java
Expand Down Expand Up @@ -487,8 +488,41 @@ public static String get_SHA_512_SecurePassword(String passwordToHash, String sa
return generatedPassword;
}

/**
* Check if the user exists in the white list
* @param email
* @return
*/
public static boolean checkWhiteList(String email) {

boolean allowed = false;

for(int i=0;i<SysDir.whiteusers.size();i++) {

if(email.equals(SysDir.whiteusers.get(i))) {

allowed = true;

break;

}

}

return allowed;

}

public static Message registerNewUser(User user){

if(!checkWhiteList(user.getEmail())) {

Message msg = new Message("configuration", "user_login", "the email is not allowed for registration", false );

return msg;

}

BaseTool tool = new BaseTool();

Message msg = null;
Expand Down Expand Up @@ -630,7 +664,9 @@ public static void passwordResetEmail(User user) {
t.setExpireDate(timestamp.getTime()+5*60*1000);

String emailContent = "Please click the following link to reset password of your CyberConnector account. To ensure your account safety, do NOT share or let other people get this email. The link will be expired in 5 minutes.";
emailContent += "\nhttp://localhost:8081/CyberConnector/web/user_setpassword?token=" + t.getToken();
emailContent += "\n"+SysDir.PREFIXURL+"/CyberConnector/web/user_setpassword?token=" + t.getToken();

logger.info(emailContent);

BaseTool tool = new BaseTool();

Expand Down
27 changes: 27 additions & 0 deletions src/edu/gmu/csiss/earthcube/cyberconnector/utils/SysDir.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
Expand Down Expand Up @@ -69,6 +71,8 @@ public class SysDir {

public static boolean login_required = false;

public static List whiteusers = new ArrayList();

public static String getCovali_file_path() {

init();
Expand Down Expand Up @@ -98,11 +102,14 @@ static void init() {
try {

BaseTool t = new BaseTool();

String configFile = t.getClassPath()+File.separator+"config.properties";

Properties p = readProperties(configFile);

String secretConfigFile = p.getProperty("secret_properties_path");



Properties secrets = null;

Expand Down Expand Up @@ -174,6 +181,26 @@ static void init() {

ucar_rda_password = secrets.getProperty("ucar_rda_password");

String whitelist = t.readStringFromFile(t.getClassPath()+File.separator+"whitelist.user");

if(!t.isNull(whitelist.trim())) {

String[] emails = whitelist.trim().split("\n");

for(String email: emails) {

email = email.trim();

if(!t.isNull(email)) {

whiteusers.add(email);

}

}

}

} catch (Exception e) {

e.printStackTrace();
Expand Down
3 changes: 3 additions & 0 deletions src/whitelist.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[email protected]
[email protected]
[email protected]
Binary file modified sync.ffs_db
Binary file not shown.

0 comments on commit 90dbcf7

Please sign in to comment.