Added gitignore; Common module created; TTResponse created; TTLogger created; Auth RMI created;
This commit is contained in:
parent
ac694a1776
commit
f18d7c4bb4
90 changed files with 844 additions and 2105 deletions
|
|
@ -7,5 +7,7 @@
|
|||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="com.github.cliftonlabs:json-simple:2.1.2" level="project" />
|
||||
<orderEntry type="module" module-name="Commons" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -1,8 +1,18 @@
|
|||
package com.texttwist.server;
|
||||
|
||||
import com.texttwist.server.components.TTServer;
|
||||
import utilities.TTLogger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println("Server start");
|
||||
TTLogger logger = new TTLogger(new File("./log"));
|
||||
TTServer ttServer = new TTServer();
|
||||
ttServer.start();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
34
Server/src/com/texttwist/server/components/TTServer.java
Normal file
34
Server/src/com/texttwist/server/components/TTServer.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package com.texttwist.server.components;
|
||||
|
||||
import com.texttwist.server.components.auth.TTAuth;
|
||||
|
||||
import java.rmi.AlreadyBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
|
||||
/**
|
||||
* Created by loke on 15/06/2017.
|
||||
*/
|
||||
public class TTServer {
|
||||
|
||||
private static final int PORT = 9999;
|
||||
|
||||
public void start() {
|
||||
|
||||
try {
|
||||
TTAuth auth = new TTAuth();
|
||||
Registry registry = LocateRegistry.createRegistry(PORT);
|
||||
registry.bind("auth", auth);
|
||||
System.out.println("Auth Service running at "+PORT+" port...");
|
||||
|
||||
} catch (RemoteException e) {
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (AlreadyBoundException e) {
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
52
Server/src/com/texttwist/server/components/auth/TTAuth.java
Normal file
52
Server/src/com/texttwist/server/components/auth/TTAuth.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package com.texttwist.server.components.auth;
|
||||
import interfaces.ITTAuth;
|
||||
import models.TTResponse;
|
||||
import org.json.simple.JsonObject;
|
||||
import utilities.TTLogger;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
/**
|
||||
* Created by loke on 15/06/2017.
|
||||
*/
|
||||
public class TTAuth extends UnicastRemoteObject implements ITTAuth {
|
||||
|
||||
private SecureRandom random = new SecureRandom();
|
||||
|
||||
public String nextSessionId() {
|
||||
return new BigInteger(130, random).toString(32);
|
||||
}
|
||||
public TTAuth() throws RemoteException{
|
||||
}
|
||||
|
||||
@Override
|
||||
public TTResponse login(String userName, String password) throws RemoteException {
|
||||
TTLogger.write("LOGGER: Invoked login with username=" + userName + " AND " + " password=" + password);
|
||||
if ((userName != null && !userName.isEmpty())
|
||||
&& (password != null && !password.equals(""))) {
|
||||
|
||||
if((userName.equalsIgnoreCase("admin"))
|
||||
&& (password.equals("admin"))) {
|
||||
JsonObject data = new JsonObject();
|
||||
data.put("token", nextSessionId());
|
||||
System.out.println("LOGGER: Login successfull");
|
||||
return new TTResponse("Login successfull", 200, data);
|
||||
}
|
||||
}
|
||||
System.out.println("LOGGER: Login unsuccessfull");
|
||||
return new TTResponse("Login unsuccessfull", 400, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TTResponse logout(String userName, String token) throws RemoteException {
|
||||
System.out.println("LOGGER: Invoked logout with username=" + userName + " AND " + " token=" + token);
|
||||
if ((userName != null && !userName.isEmpty())
|
||||
&& (token != null && !token.isEmpty())) {
|
||||
return new TTResponse("Logout successfull", 200, null);
|
||||
}
|
||||
return new TTResponse("Logout successfull (but something go wrong)", 200, null);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue