【发布时间】:2021-10-23 16:48:53
【问题描述】:
我正在尝试更新以下代码示例 (Java) 以防止损坏的访问控制,我在理论上了解损坏的访问控制。但是我被困在我需要围绕用户名进行的令人兴奋的代码更改上,以便用户只能看到允许看到的内容。
任何帮助都会很棒
import java.sql.*;
import java.util.*;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.Claims;
class LoggedOutException extends Exception {
public LoggedOutException(String message) {
super(message);
}
}
public class External{
public static HashMap<String, String> accountLookup(String accountId, String jwt) throws Exception{
if (jwt == null) { ;
throw new LoggedOutException("User is not logged in");
} else {
Claims claims = Jwts.parser()
.setSigningKey("Key".getBytes("UTF-8"))
.parseClaimsJws(jwt).getBody();
if ((claims.get("logged_in")).toString().equals("true")) {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://mysql:3306/BankApp?useSSL=false", "root", "letmein");
Statement stmt = con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT username FROM tbl_user WHERE id = '" + accountId + "';");
if (!rs.next()) {
con.close();
throw new Exception("Account not found");
}
String user = new String();
user = rs.getString("username");
rs=stmt.executeQuery("SELECT balance, dob FROM tbl_account WHERE user_id = '" + accountId + "';");
HashMap<String, String> results = new HashMap<String, String>();
if(rs.next()){
results.put("balance", rs.getString("balance").toString());
results.put("dob", rs.getString("dob").toString());
results.put("username", user);
}
con.close();
return results;
} else {
throw new LoggedOutException("User is not logged in");
}
}
}
}
【问题讨论】:
-
可能想要编辑该密钥。
标签: java jwt access-control