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.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
@ -106,10 +105,6 @@ public class CASTicket {
if (ticket != null && ticket.startsWith("ST-")) { if (ticket != null && ticket.startsWith("ST-")) {
result = ticket; result = ticket;
} }
} catch (FileNotFoundException e) {
grantingTicket = getGrantingTicket();
writeFiledGrantingTicket(grantingTicket);
return getTicket();
} catch (IOException e) { } catch (IOException e) {
throw new JSCliException(e); throw new JSCliException(e);
} }
@ -121,8 +116,8 @@ public class CASTicket {
String userHome = System.getProperty("user.home"); String userHome = System.getProperty("user.home");
String ticketFileName = userHome + "/.hsadmin.tgt"; String ticketFileName = userHome + "/.hsadmin.tgt";
File file = new File(ticketFileName); File file = new File(ticketFileName);
if (file.isFile() && file.canRead()) {
Properties properties = new Properties(); Properties properties = new Properties();
if (file.isFile() && file.canRead()) {
try { try {
properties.load(new FileReader(file)); properties.load(new FileReader(file));
filedTicket = properties.getProperty(user); filedTicket = properties.getProperty(user);
@ -132,26 +127,17 @@ public class CASTicket {
} }
if (filedTicket == null) { if (filedTicket == null) {
filedTicket = getGrantingTicket(); filedTicket = getGrantingTicket();
if (filedTicket != null) {
properties.setProperty(user, filedTicket);
try {
properties.store(new FileOutputStream(file), "");
} catch (IOException e) {
}
}
} }
return filedTicket; 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);
}
}
}
@Override @Override
public String toString() { public String toString() {
return grantingTicket; return grantingTicket;