|
@ -1,4 +1,7 @@ |
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
|
import java.io.ObjectInputStream; |
|
|
|
|
|
import java.io.ObjectOutputStream; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Credential Repository for handling user credentials |
|
|
* Credential Repository for handling user credentials |
|
@ -8,7 +11,7 @@ import java.util.ArrayList; |
|
|
public class CredentialRepository implements CredentialRepositoryInterface{ |
|
|
public class CredentialRepository implements CredentialRepositoryInterface{ |
|
|
|
|
|
|
|
|
private int idCounter = 0; |
|
|
private int idCounter = 0; |
|
|
private ArrayList<Credential> credentials; |
|
|
|
|
|
|
|
|
private CredentialList credentials; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Konstruktor |
|
|
* Konstruktor |
|
@ -17,7 +20,7 @@ public class CredentialRepository implements CredentialRepositoryInterface{ |
|
|
*/ |
|
|
*/ |
|
|
public CredentialRepository() |
|
|
public CredentialRepository() |
|
|
{ |
|
|
{ |
|
|
this.credentials = new ArrayList<Credential>(); |
|
|
|
|
|
|
|
|
this.credentials = new CredentialList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -128,6 +131,48 @@ public class CredentialRepository implements CredentialRepositoryInterface{ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Function for serialization of all Credentials |
|
|
|
|
|
* @param fileName |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public void serializeObject(String fileName) |
|
|
|
|
|
{ |
|
|
|
|
|
if(fileName.equals("")) return; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
FileOutputStream file = new FileOutputStream(this.getWorkingDirectory() + fileName + ".claud11"); |
|
|
|
|
|
ObjectOutputStream out = new ObjectOutputStream(file); |
|
|
|
|
|
out.writeObject(this.credentials); |
|
|
|
|
|
} catch (Exception fail) { |
|
|
|
|
|
System.err.println("Serialization failed!"); |
|
|
|
|
|
fail.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Function to load serialized Objects from hard drive by path |
|
|
|
|
|
* @param fileName |
|
|
|
|
|
*/ |
|
|
|
|
|
public void deserializeObjects(String fileName) |
|
|
|
|
|
{ |
|
|
|
|
|
if(fileName.equals("")) return; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
FileInputStream file = new FileInputStream(this.getWorkingDirectory() + fileName + ".claud11"); |
|
|
|
|
|
ObjectInputStream in = new ObjectInputStream(file); |
|
|
|
|
|
|
|
|
|
|
|
this.credentials = (CredentialList)in.readObject(); |
|
|
|
|
|
|
|
|
|
|
|
in.close(); |
|
|
|
|
|
file.close(); |
|
|
|
|
|
|
|
|
|
|
|
} catch(Exception fail) |
|
|
|
|
|
{ |
|
|
|
|
|
System.err.println("Loading of CredentialRepository failed"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* helper function to check list size after insertion / deletion |
|
|
* helper function to check list size after insertion / deletion |
|
|
* @return |
|
|
* @return |
|
@ -138,6 +183,16 @@ public class CredentialRepository implements CredentialRepositoryInterface{ |
|
|
return this.credentials.size(); |
|
|
return this.credentials.size(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Helper function for serialization |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
private String getWorkingDirectory() |
|
|
|
|
|
{ |
|
|
|
|
|
return System.getProperty("user.dir"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|