diff --git a/hsarjcli/src/de/hsadmin/jscli/CASTicket.java b/hsarjcli/src/de/hsadmin/jscli/CASTicket.java index e61eaaa..9dabcf3 100644 --- a/hsarjcli/src/de/hsadmin/jscli/CASTicket.java +++ b/hsarjcli/src/de/hsadmin/jscli/CASTicket.java @@ -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