diff --git a/IdentityService/data/db_ojek_account.sql b/IdentityService/data/db_ojek_account.sql index d6fb7f27a280b6e422cd2616b0f1624c8b6c3000..4eaaf778158f24dff3f11027a244913625a1d104 100644 --- a/IdentityService/data/db_ojek_account.sql +++ b/IdentityService/data/db_ojek_account.sql @@ -3,7 +3,7 @@ -- http://www.phpmyadmin.net -- -- Host: localhost --- Generation Time: 04 Nov 2017 pada 09.26 +-- Generation Time: 07 Nov 2017 pada 16.42 -- Versi Server: 10.0.31-MariaDB-0ubuntu0.16.04.2 -- PHP Version: 7.0.22-0ubuntu0.16.04.1 @@ -48,9 +48,30 @@ INSERT INTO `account` (`id`, `name`, `username`, `email`, `password`, `phone`, ` (4, 'Abdullah Malik Ibrahim', 'malikibrahim', 'malik@gmail.com', 'ac43724f16e9241d990427ab7c8f4228', '0247657917', '/img/profile/UFBqemxTWmtkZytjSmNSVWE4S2lTQT09', 1), (5, 'Joko Akbar', 'joko', 'jokoakbar@gmail.com', 'ac43724f16e9241d990427ab7c8f4228', '085797490039', '/img/empty_profile.png', 0), (6, 'Lifardi Muhammad', 'lifardi', 'lifardi@gmail.com', 'ac43724f16e9241d990427ab7c8f4228', '085797490039', '/img/empty_profile.png', 1), -(7, 'Coba 3', 'coba', 'coba@gmail.com', 'ac43724f16e9241d990427ab7c8f4228', '085797490039', '/img/empty_profile.png', 0), +(7, 'Coba 3', 'coba', 'coba@gmail.com', 'coba', '085797490039', '/img/empty_profile.png', 0), (8, 'Fadhil Imam', 'fadhil', 'fadhil@itb.ac.id', 'ac43724f16e9241d990427ab7c8f4228', '0872318283192', '/img/empty_profile.png', 0); +-- -------------------------------------------------------- + +-- +-- Struktur dari tabel `token` +-- + +CREATE TABLE `token` ( + `token` varchar(100) NOT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `expire_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `id_account` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Dumping data untuk tabel `token` +-- + +INSERT INTO `token` (`token`, `created_at`, `expire_at`, `id_account`) VALUES +('5a9da397ca3949981d3b61f31c365a5aa3a1dd24ec73f244ba987f66e860faf8', '2017-11-07 09:11:59', '2017-11-07 09:16:59', 1), +('84ad58d5e1fea4b479bce138484682715b9f3a0b264e5e6c0dc157eb86023116', '2017-11-06 14:09:28', '2017-11-06 15:13:23', 5); + -- -- Indexes for dumped tables -- @@ -62,6 +83,14 @@ ALTER TABLE `account` ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `username` (`username`,`email`); +-- +-- Indexes for table `token` +-- +ALTER TABLE `token` + ADD PRIMARY KEY (`token`), + ADD UNIQUE KEY `id_account_2` (`id_account`), + ADD KEY `id_account` (`id_account`); + -- -- AUTO_INCREMENT for dumped tables -- @@ -71,6 +100,16 @@ ALTER TABLE `account` -- ALTER TABLE `account` MODIFY `id` int(15) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9; +-- +-- Ketidakleluasaan untuk tabel pelimpahan (Dumped Tables) +-- + +-- +-- Ketidakleluasaan untuk tabel `token` +-- +ALTER TABLE `token` + ADD CONSTRAINT `fk_token_account` FOREIGN KEY (`id_account`) REFERENCES `account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; + /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/IdentityService/web/WEB-INF/web.xml b/IdentityService/web/WEB-INF/web.xml index 2a2157c3c3eb60ba82d08ddf63ec7c73cffb291e..5664796562536d25b1cdda53344afdce04d70b16 100644 --- a/IdentityService/web/WEB-INF/web.xml +++ b/IdentityService/web/WEB-INF/web.xml @@ -53,7 +53,7 @@ </context-param> <context-param> <param-name>jdbcPassword</param-name> - <param-value>superadmin</param-value> + <param-value></param-value> </context-param> </web-app> \ No newline at end of file diff --git a/WebService/src/com/informatika/ojek/webservice/Main.java b/WebService/src/com/informatika/ojek/webservice/Main.java index e6efcf7d1b33baab296db49031a87c0206a0d9c0..2a9853189c37ef159d9cf3ecfd37ca7cfa1b5ef8 100644 --- a/WebService/src/com/informatika/ojek/webservice/Main.java +++ b/WebService/src/com/informatika/ojek/webservice/Main.java @@ -6,10 +6,11 @@ import javax.xml.ws.Endpoint; public class Main{ public static void main(String[] args) { Order order = new Order(); - order.PuttransactionDetails("a", 2, "jakarta", "bandung", 4, "mantep gaans"); - Endpoint.publish("http://localhost:9999/ws/profile", new Profile()); - Endpoint.publish("http://localhost:9999/ws/order", new Order()); - Endpoint.publish("http://localhost:9999/ws/history", new History()); + // order.PuttransactionDetails("a", 2, "jakarta", "bandung", 4, "mantep gaans"); + Account [] dd = order.getPrefferedDriver("a","a","a", "a"); + // Endpoint.publish("http://localhost:9999/ws/profile", new Profile()); + // Endpoint.publish("http://localhost:9999/ws/order", new Order()); + // Endpoint.publish("http://localhost:9999/ws/history", new History()); } } \ No newline at end of file diff --git a/WebService/src/com/informatika/ojek/webservice/Order.java b/WebService/src/com/informatika/ojek/webservice/Order.java index 51aee0bb2ab7de483d728c2cc7b91ce654fdc119..a3d2cc03d6605d5576fba99306d0c8f7e82ff362 100644 --- a/WebService/src/com/informatika/ojek/webservice/Order.java +++ b/WebService/src/com/informatika/ojek/webservice/Order.java @@ -1,9 +1,9 @@ package com.informatika.ojek.webservice; -import java.io.IOException; -import java.io.ObjectOutputStream; +import java.io.*; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.sql.*; import javax.jws.WebService; import java.text.DateFormat; @@ -12,10 +12,11 @@ import java.util.Date; //Service Implementation @WebService(endpointInterface = "com.informatika.ojek.webservice.IOrder") public class Order implements IOrder { + final public static String IDENTITY_SERVICE_SERVER = "http://localhost:8083"; @Override public Account[] getPrefferedDriver(String access_token, String preffered_driver, String picking_point, String destination){ - boolean valid = true; + boolean valid = validateToken(access_token); //cek akses token int id_active; @@ -135,32 +136,6 @@ public class Order implements IOrder { boolean valid = true; int id_active; - //RequestValidation - URL gwtServlet = null; - try { - gwtServlet = new URL("http://localhost:8083/validate"); - HttpURLConnection servletConnection = (HttpURLConnection) gwtServlet.openConnection(); - servletConnection.setRequestMethod("POST"); - servletConnection.setDoOutput(true); - NameValuePair[] data = { - new NameValuePair("user", "joe"), - new NameValuePair("password", "bloggs") - }; - post.setRequestBody(data); - ObjectOutputStream objOut = new ObjectOutputStream(servletConnection.getOutputStream()); - objOut.writeObject(p); - objOut.flush(); - objOut.close(); - - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - if(valid){ id_active = 1; @@ -219,4 +194,48 @@ public class Order implements IOrder { } + public boolean validateToken(String token){ + String urlParameters = "token="+token; + byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 ); + int postDataLength = postData.length; + String request = IDENTITY_SERVICE_SERVER + "/validate"; + URL url = null; + + try { + url = new URL(request); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setDoOutput( true ); + conn.setInstanceFollowRedirects( false ); + conn.setRequestMethod("POST"); + conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded"); + conn.setRequestProperty( "charset", "utf-8"); + conn.setRequestProperty( "Content-Length", Integer.toString( postDataLength )); + conn.setUseCaches( false ); + DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); + wr.write(postData); + wr.flush(); + wr.close(); + + int responseCode = conn.getResponseCode(); + System.out.println("\nSending 'POST' request to URL : " + url); + System.out.println("Post parameters : " + urlParameters); + System.out.println("Response Code : " + responseCode); + + BufferedReader in = new BufferedReader( + new InputStreamReader(conn.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + //print result + System.out.println(response.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } } \ No newline at end of file