fix problem storing ticket in .hsadmin.tgt

This commit is contained in:
Peter Hormanns 2013-01-21 13:17:15 +01:00
parent 5b55f7a74c
commit 83968cf292

View File

@ -3,9 +3,8 @@ package de.hsadmin.jscli;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
@ -106,10 +105,6 @@ public class CASTicket {
if (ticket != null && ticket.startsWith("ST-")) {
result = ticket;
}
} catch (FileNotFoundException e) {
grantingTicket = getGrantingTicket();
writeFiledGrantingTicket(grantingTicket);
return getTicket();
} catch (IOException e) {
throw new JSCliException(e);
}
@ -121,8 +116,8 @@ public class CASTicket {
String userHome = System.getProperty("user.home");
String ticketFileName = userHome + "/.hsadmin.tgt";
File file = new File(ticketFileName);
Properties properties = new Properties();
if (file.isFile() && file.canRead()) {
Properties properties = new Properties();
try {
properties.load(new FileReader(file));
filedTicket = properties.getProperty(user);
@ -132,24 +127,15 @@ public class CASTicket {
}
if (filedTicket == null) {
filedTicket = getGrantingTicket();
}
return filedTicket;
}
private void writeFiledGrantingTicket(String ticket) throws JSCliException {
String userHome = System.getProperty("user.home");
String ticketFileName = userHome + "/.hsadmin.tgt";
File file = new File(ticketFileName);
if (file.isFile() && file.canWrite()) {
Properties properties = new Properties();
try {
properties.load(new FileReader(file));
properties.put(user, ticket);
properties.store(new FileWriter(file), "hsscript");
} catch (IOException e) {
throw new JSCliException(e);
if (filedTicket != null) {
properties.setProperty(user, filedTicket);
try {
properties.store(new FileOutputStream(file), "");
} catch (IOException e) {
}
}
}
return filedTicket;
}
@Override