Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMIFMerdu - 13513049 - Ahmad Naufal Farhan #24

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fd10417
Init commit: added all prev projects
ahmadnaufal Nov 29, 2015
73be09e
new dump inserted
ahmadnaufal Nov 30, 2015
164175c
Added MD5 encryption to password
squilliams Dec 2, 2015
e2b0c2a
add Web Project for Comment & Vote
ahmadnaufal Dec 4, 2015
90cdd84
gitignore updated
ahmadnaufal Dec 4, 2015
be466e8
deleted unnecessary files
ahmadnaufal Dec 4, 2015
b41da28
Added token with client IP & user agent (browser)
trymochamad Dec 5, 2015
5b82bee
Client check user agent and IP address every time
squilliams Dec 5, 2015
f3aec65
add Comment, Vote Question and Answer service
ahmadnaufal Dec 5, 2015
947ce03
finishing Comment
ahmadnaufal Dec 5, 2015
58700f0
Merge branch 'master' of http://www.github.com/HMIFMerdu/IF3110-2015-T3
squilliams Dec 5, 2015
f234b06
Client solved: Unreferenced WSDL
ahmadnaufal Dec 5, 2015
09ab20e
Fixing token for user agent & IP address
squilliams Dec 5, 2015
6a61900
fixed servlet client validate and error message
trymochamad Dec 6, 2015
2ec8250
Client cleaning and cookie validation (from Bimo)
ahmadnaufal Dec 6, 2015
bbc8041
Merge origin/master
ahmadnaufal Dec 6, 2015
facc77a
token succesfully with useragent in Login Logout
trymochamad Dec 6, 2015
b79e897
Token for every page, fixing ClientValidate method
squilliams Dec 6, 2015
e6dd9b0
client controller for navigating secure
trymochamad Dec 6, 2015
1e80c97
Moving token validation to IS
squilliams Dec 6, 2015
a370037
Merge branch 'master' of http://www.github.com/HMIFMerdu/IF3110-2015-T3
squilliams Dec 6, 2015
78e2dc3
update comment service
trymochamad Dec 6, 2015
50c0921
Added option for invalid token (expired, different ip, different brow…
squilliams Dec 6, 2015
01f7de4
resolving web services references token validation
trymochamad Dec 6, 2015
e91cab0
Fixing login and service authorization
squilliams Dec 6, 2015
3fdbfeb
added servlet for bridge
ahmadnaufal Dec 6, 2015
e6ab02d
Added error message description (IP Address, Browser, Token Timeout)
squilliams Dec 6, 2015
11248f5
Laporan Final
trymochamad Dec 6, 2015
9525fa0
adding vote and comment angular
ahmadnaufal Dec 6, 2015
eb993bf
Merge branch 'master' of https://github.com/HMIFMerdu/IF3110-2015-T3
ahmadnaufal Dec 6, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/StackExchangeWS/build/
/StackExchangeWS/dist/
/StackExchangeWS/nbproject/
/StackExchangeClient/build/
/StackExchangeClient/dist/
/StackExchangeClient/nbproject/
/StackExchangeIS/build/
/StackExchangeIS/dist/
/StackExchangeIS/nbproject/
/StackExchangeClient/WebApplication1/nbproject/private/
/StackExchangeAJS/nbproject/
/StackExchangeAJS/build/
/StackExchangeAJS/dist/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Diharapkan dengan tugas ini anda dapat mengerti:

### Link Laporan

*Masukkan link laporan anda di sini*
https://drive.google.com/a/std.stei.itb.ac.id/file/d/0B5FDXnomS9GOQm9iVS1QMW5CdzQ/view?usp=sharing


### Arsitektur Umum Server

Expand Down
71 changes: 71 additions & 0 deletions StackExchangeAJS/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="StackExchangeAJS" default="default" basedir=".">
<description>Builds, tests, and runs the project StackExchangeAJS.</description>
<import file="nbproject/build-impl.xml"/>
<!--

There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:

-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-dist: called before archive building
-post-dist: called after archive building
-post-clean: called after cleaning build products
-pre-run-deploy: called before deploying
-post-run-deploy: called after deploying

Example of pluging an obfuscator after the compilation could look like

<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>

For list of available properties check the imported
nbproject/build-impl.xml file.


Other way how to customize the build is by overriding existing main targets.
The target of interest are:

init-macrodef-javac: defines macro for javac compilation
init-macrodef-junit: defines macro for junit execution
init-macrodef-debug: defines macro for class debugging
do-dist: archive building
run: execution of project
javadoc-build: javadoc generation

Example of overriding the target for project execution could look like

<target name="run" depends="<PROJNAME>-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>

Notice that overridden target depends on jar target and not only on
compile target as regular run target does. Again, for list of available
properties which you can use check the target you are overriding in
nbproject/build-impl.xml file.

-->
</project>
Binary file added StackExchangeAJS/json-simple-1.1.1.jar
Binary file not shown.
Binary file added StackExchangeAJS/mysql-connector.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions StackExchangeAJS/src/conf/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

37 changes: 37 additions & 0 deletions StackExchangeAJS/src/java/Database/DB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Ahmad Naufal Farhan
*/
public class DB {
public static Connection getConnection() {

Connection conn = null;

try {
// create a mysql database connection
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/stackexchange";
String username = "root";
String password = "";
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url, username, password);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException ex) {
Logger.getLogger(DB.class.getName()).log(Level.SEVERE, null, ex);
}

return conn;
}
}
172 changes: 172 additions & 0 deletions StackExchangeAJS/src/java/Post/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Post;

import Database.DB;
import Validation.Validation;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;

/**
*
* @author Ahmad Naufal Farhan
*/
public class Comment extends HttpServlet {

Connection conn = DB.getConnection();
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Comment</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet Comment at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int res = 0;
ArrayList<JSONObject> comments = new ArrayList<>();
JSONObject obj = new JSONObject();
try (PrintWriter out = response.getWriter()) {

int qid = Integer.parseInt(request.getParameter("qid"));
String query = "SELECT * FROM comments WHERE qid = ?";

// set the prepared statement by the query and enter the value of where clause
try (PreparedStatement pst = conn.prepareStatement(query)){
pst.setInt(1, qid);
// execuResultSette select
ResultSet ret = pst.executeQuery();
while (ret.next()) {
JSONObject comment = new JSONObject();
comment.put("uid", ret.getInt("uid"));
comment.put("content", ret.getString("content"));
comment.put("timestamp", ret.getString("timestamp"));
comments.add(comment);
}

}

// put the results
obj.put("success", 1);
obj.put("qid", qid);
obj.put("comments", comments);

out.print(obj);

} catch (SQLException ex) {
Logger.getLogger(VoteQuestion.class.getName()).log(Level.SEVERE, null, ex);
}
}

/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//TODO write your implementation code here:
String token = request.getParameter("token");
int qid = Integer.parseInt(request.getParameter("qid"));
int content = Integer.parseInt(request.getParameter("content"));
String ipAddress = request.getParameter("ipaddress");
String useragent = request.getParameter("uagent");

JSONObject obj = new JSONObject();

int res = Validation.AUTH_INVALID; // initialize result with error first (assumption)
long user_id = Validation.validateToken(token, ipAddress, useragent); // validate token and get the user id

try (PrintWriter out = response.getWriter()) {
// token is valid if user_id value is not -1
if (user_id != -1) {

try (Statement st = conn.createStatement()) {

String query = "INSERT INTO `comments` (uid, qid, content) VALUES (?, ?, ?)";

// set the prepared statement by the query and enter the value of where clause
try (PreparedStatement pst = conn.prepareStatement(query)) {
pst.setLong(1, user_id);
pst.setInt(2, qid);
pst.setInt(3, content);
// execute update
res = pst.executeUpdate();
if (res > 0)
res = Validation.AUTH_VALID;
}

} catch (SQLException ex) {
Logger.getLogger(Comment.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
// else: token is invalid, deny request
res = Validation.AUTH_INVALID;
}

obj.put("success", res);
out.print(obj);

}
}

/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

}
Loading