diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3d8eb8dd50765ff490ea0a49d6b841d552aa82c6..01fe57d8e4d4ddefef675c433d9c005bbcbd6cda 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,17 +5,16 @@ </component> <component name="ChangeListManager"> <list default="true" id="8522785e-cde9-49a6-ad14-9d935d110316" name="Changes" comment=""> + <change afterPath="$PROJECT_DIR$/src/main/java/com/gymtracker/service/ApplicationService.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/docker-compose.yml" beforeDir="false" afterPath="$PROJECT_DIR$/docker-compose.yml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/gymtracker/Main.java" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/controllers/GenerateAPIKeyController.java" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/example/TestingService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/gymtracker/example/TestingService.java" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/middleware/APIKeyValidator.java" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/resources/META-INF/beans.xml" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/resources/META-INF/persistence.xml" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/webapp/WEB-INF/web.xml" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/webapp/index.jsp" beforeDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/example/TestingService.java" beforeDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/handler/LogAuthHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/gymtracker/handler/LogAuthHandler.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/model/Application.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/gymtracker/model/Application.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/service/Application.java" beforeDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/service/Logging.java" beforeDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/util/HibernateUtil.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/gymtracker/util/HibernateUtil.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/gymtracker/util/Util.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/gymtracker/util/Util.java" afterDir="false" /> </list> <option name="SHOW_DIALOG" value="false" /> <option name="HIGHLIGHT_CONFLICTS" value="true" /> @@ -52,21 +51,21 @@ <option name="hideEmptyMiddlePackages" value="true" /> <option name="showLibraryContents" value="true" /> </component> - <component name="PropertiesComponent"><![CDATA[{ - "keyToString": { - "ASKED_ADD_EXTERNAL_FILES": "true", - "RunOnceActivity.OpenProjectViewOnStart": "true", - "RunOnceActivity.ShowReadmeOnStart": "true", - "SHARE_PROJECT_CONFIGURATION_FILES": "true", - "WebServerToolWindowFactoryState": "false", - "last_opened_file_path": "C:/Webdev/WBD/tugas-besar-2/jax-ws", - "project.structure.last.edited": "Modules", - "project.structure.proportion": "0.15", - "project.structure.side.proportion": "0.2", - "settings.editor.selected.configurable": "reference.projectsettings.compiler.javacompiler", - "vue.rearranger.settings.migration": "true" + <component name="PropertiesComponent">{ + "keyToString": { + "ASKED_ADD_EXTERNAL_FILES": "true", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "WebServerToolWindowFactoryState": "false", + "last_opened_file_path": "C:/Webdev/WBD/tugas-besar-2/jax-ws", + "project.structure.last.edited": "Modules", + "project.structure.proportion": "0.15", + "project.structure.side.proportion": "0.2", + "settings.editor.selected.configurable": "reference.projectsettings.compiler.javacompiler", + "vue.rearranger.settings.migration": "true" } -}]]></component> +}</component> <component name="RecentsManager"> <key name="MoveFile.RECENT_KEYS"> <recent name="C:\Webdev\WBD\tugas-besar-2\jax-ws\src\main\java\com\example\jaxw\com\example" /> diff --git a/src/main/java/com/gymtracker/Main.java b/src/main/java/com/gymtracker/Main.java index 58ea50e5f17539cb1ced33fe97c1e0affb695bda..7564eb11b14b1747d8204f7130c86498fb547b53 100644 --- a/src/main/java/com/gymtracker/Main.java +++ b/src/main/java/com/gymtracker/Main.java @@ -1,13 +1,13 @@ package com.gymtracker; -import com.gymtracker.example.TestingService; +import com.gymtracker.service.ApplicationService; import javax.xml.ws.Endpoint; public class Main { public static void main(String[] args) { try { - Endpoint.publish("http://0.0.0.0:3001/ws/testing", new TestingService()); + Endpoint.publish("http://0.0.0.0:3001/ws/application", new ApplicationService()); System.out.println("Server started"); } catch (Exception e) { System.out.println("Something's wrong"); diff --git a/src/main/java/com/gymtracker/example/TestingService.java b/src/main/java/com/gymtracker/example/TestingService.java deleted file mode 100644 index ce01a720e281769125e3780442851c12be7a8491..0000000000000000000000000000000000000000 --- a/src/main/java/com/gymtracker/example/TestingService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.gymtracker.example; - -import javax.jws.HandlerChain; -import javax.jws.WebMethod; -import javax.jws.WebService; -import javax.xml.ws.WebServiceContext; -import javax.annotation.Resource; - -@WebService -@HandlerChain(file = "log_and_auth.xml") -public class TestingService { - @Resource - WebServiceContext wsContext; - @WebMethod - public String Test() { - return "Test successful"; - } -} diff --git a/src/main/java/com/gymtracker/handler/LogAuthHandler.java b/src/main/java/com/gymtracker/handler/LogAuthHandler.java index 851c0cc0985aa9ec392e8861e28eece11bed16ad..2bafb44c27223205aec492fe1fd72bb17c618c0d 100644 --- a/src/main/java/com/gymtracker/handler/LogAuthHandler.java +++ b/src/main/java/com/gymtracker/handler/LogAuthHandler.java @@ -2,7 +2,7 @@ package com.gymtracker.handler; import com.gymtracker.util.HibernateUtil; import com.gymtracker.util.Util; -import com.gymtracker.service.Logging; +import com.gymtracker.model.Logging; import io.github.cdimascio.dotenv.Dotenv; import org.hibernate.Session; import org.hibernate.SessionFactory; @@ -33,10 +33,15 @@ public class LogAuthHandler implements SOAPHandler<SOAPMessageContext> { } public boolean handleMessage(SOAPMessageContext smc) { - Boolean outbound = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); - if (!outbound) { + try { + Boolean outbound = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); boolean authorized = authorize(smc); - log(smc, authorized); + if (!outbound) { + log(smc, authorized); + } + smc.put("authorized", authorized); + } catch (Exception e) { + e.printStackTrace(); } return true; } @@ -53,7 +58,9 @@ public class LogAuthHandler implements SOAPHandler<SOAPMessageContext> { String phpKey = dotenv.get("PHP_KEY"); String nodeKey = dotenv.get("NODE_KEY"); - return token.equals(phpKey) || token.equals(nodeKey); + if(token.equals(phpKey) || token.equals(nodeKey)) { + return true; + } } } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/gymtracker/model/Application.java b/src/main/java/com/gymtracker/model/Application.java new file mode 100644 index 0000000000000000000000000000000000000000..e77a85e03dfb2ad04c82b684a250f56bcb45a6dd --- /dev/null +++ b/src/main/java/com/gymtracker/model/Application.java @@ -0,0 +1,79 @@ +package com.gymtracker.model; + +import javax.persistence.*; +import java.io.Serializable; + +@Entity +@Table(name = "application") +public class Application implements Serializable { + @Id + @Column(nullable = false) + private String username; + + @Id + @Column(nullable = false) + private int gym_id; + + @Column(nullable = false) + private int acceptance; + + @Column(nullable = false) + private String trainer_name; + + @Column(nullable = false) + private String trainer_description; + + @Lob + @Column(nullable = false) + private String application_description; + + // Getters + public String getUsername() { + return username; + } + + public int getGymID() { + return gym_id; + } + + public int getAcceptance() { + return acceptance; + } + + public String getTrainerName() { + return trainer_name; + } + + public String getTrainerDescription() { + return trainer_description; + } + + public String getApplicationDescription() { + return application_description; + } + + //Setters + public void setUsername(String username) { + this.username = username; + } + + public void setGymID(int gym_id) { + this.gym_id = gym_id; + } + + public void setAcceptance(int acceptance) { + this.acceptance = acceptance; + } + + public void setTrainerName(String trainer_name) { + this.trainer_name = trainer_name; + } + + public void setTrainerDescription(String trainer_description) { + this.trainer_description = trainer_description; + } + + public void setApplicationDescription(String application_description) { + this.application_description = application_description; + } +} diff --git a/src/main/java/com/gymtracker/service/Logging.java b/src/main/java/com/gymtracker/model/Logging.java similarity index 96% rename from src/main/java/com/gymtracker/service/Logging.java rename to src/main/java/com/gymtracker/model/Logging.java index 8fc7c78403876eb7d8430f2b4d0814d78637a3e9..d60b6aabf50947f33a2ed85b1d351ecdd475b49f 100644 --- a/src/main/java/com/gymtracker/service/Logging.java +++ b/src/main/java/com/gymtracker/model/Logging.java @@ -1,7 +1,6 @@ -package com.gymtracker.service; +package com.gymtracker.model; import javax.persistence.*; -import java.sql.Time; import java.sql.Timestamp; @Entity diff --git a/src/main/java/com/gymtracker/service/Application.java b/src/main/java/com/gymtracker/service/Application.java deleted file mode 100644 index 023b84c5b757422512e9e791e5264cc881c8bfe1..0000000000000000000000000000000000000000 --- a/src/main/java/com/gymtracker/service/Application.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.gymtracker.service; - -public class Application { - -} diff --git a/src/main/java/com/gymtracker/service/ApplicationService.java b/src/main/java/com/gymtracker/service/ApplicationService.java new file mode 100644 index 0000000000000000000000000000000000000000..337057d759632dd1d30b49e740565b8abf1a6bad --- /dev/null +++ b/src/main/java/com/gymtracker/service/ApplicationService.java @@ -0,0 +1,61 @@ +package com.gymtracker.service; + +import com.gymtracker.model.Application; +import com.gymtracker.util.HibernateUtil; +import org.hibernate.Session; +import org.hibernate.SessionFactory; + +import javax.annotation.Resource; +import javax.jws.HandlerChain; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebService; +import javax.xml.soap.SOAPMessage; +import javax.xml.ws.WebServiceContext; +import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.handler.soap.SOAPMessageContext; +import java.util.Map; + +@WebService +@HandlerChain(file = "log_and_auth.xml") +public class ApplicationService { + @Resource + private WebServiceContext wsContext; + @WebMethod + public String apply( + @WebParam(name = "username") String username, + @WebParam(name = "gym_id") int gym_id, + @WebParam(name = "trainer_name") String trainer_name, + @WebParam(name = "trainer_description") String trainer_description, + @WebParam(name = "application_description") String application_description + ) { + try { +// Boolean authorized = (Boolean) wsContext.getMessageContext().get("authorized"); +// +// +// if(!authorized) { +// return "Unauthorized access, application failed"; +// } + + Application application = new Application(); + application.setUsername(username); + application.setGymID(gym_id); + application.setAcceptance(0); + application.setTrainerName(trainer_name); + application.setTrainerDescription(trainer_description); + application.setApplicationDescription(application_description); + + SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); + Session session = sessionFactory.getCurrentSession(); + + session.beginTransaction(); + session.save(application); + session.getTransaction().commit(); + + return "Application successful"; + } catch (Exception e) { + e.printStackTrace(); + return "Application failed"; + } + } +} diff --git a/src/main/java/com/gymtracker/util/HibernateUtil.java b/src/main/java/com/gymtracker/util/HibernateUtil.java index 4ecc441905b09dbe31e42e7f988f4cbd19dd9084..8fd29a7578c2fa3eccda8d41e85189b6bafbeeba 100644 --- a/src/main/java/com/gymtracker/util/HibernateUtil.java +++ b/src/main/java/com/gymtracker/util/HibernateUtil.java @@ -1,13 +1,13 @@ package com.gymtracker.util; +import com.gymtracker.model.Application; +import com.gymtracker.model.Logging; import io.github.cdimascio.dotenv.Dotenv; import org.hibernate.SessionFactory; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; -import com.gymtracker.service.Logging; - import java.util.Properties; public class HibernateUtil { @@ -32,6 +32,7 @@ public class HibernateUtil { Configuration configuration = new Configuration(); configuration.setProperties(properties); configuration.addAnnotatedClass(Logging.class); + configuration.addAnnotatedClass(Application.class); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); return configuration.buildSessionFactory(serviceRegistry); diff --git a/src/main/java/com/gymtracker/util/Util.java b/src/main/java/com/gymtracker/util/Util.java index a764a59bf2b89b430bb29d044cd2656dba727c9c..6a88ed9070750dc97cf101e7ec55c2a7339deee7 100644 --- a/src/main/java/com/gymtracker/util/Util.java +++ b/src/main/java/com/gymtracker/util/Util.java @@ -1,6 +1,12 @@ package com.gymtracker.util; +import javax.xml.namespace.QName; +import javax.xml.soap.SOAPBody; +import javax.xml.soap.SOAPElement; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPMessage; import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.handler.soap.SOAPMessageContext; import java.lang.reflect.Method; import java.net.InetSocketAddress; import java.net.URI;