From ea9f9848a6e7a68dc90decc2e38bd3e1081ebf8a Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 2 Mar 2015 13:22:44 +0100 Subject: ThriftManager class: use getSatClient() and getMasterClient() to get the singleton instances of the thrift clients to satellite and master servers DO NOT CREATE NEW THRIFT OBJECTS!!! --- .../src/main/java/util/ListAllOtherUsers_GUI.java | 19 +++---------- .../main/java/util/ServiceProviderResponse.java | 13 ++------- .../src/main/java/util/ShibbolethECP.java | 32 ++++++++++++++++++---- 3 files changed, 34 insertions(+), 30 deletions(-) (limited to 'dozentenmodul/src/main/java/util') diff --git a/dozentenmodul/src/main/java/util/ListAllOtherUsers_GUI.java b/dozentenmodul/src/main/java/util/ListAllOtherUsers_GUI.java index e09f0b08..56adaf4f 100644 --- a/dozentenmodul/src/main/java/util/ListAllOtherUsers_GUI.java +++ b/dozentenmodul/src/main/java/util/ListAllOtherUsers_GUI.java @@ -30,7 +30,6 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSeparator; import javax.swing.JTable; -import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; @@ -46,9 +45,8 @@ import models.person; import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.openslx.sat.thrift.iface.Person; -import org.openslx.sat.thrift.iface.Server.Client; -import thrift.ThriftConnection; +import thrift.ThriftManager; @SuppressWarnings("serial") public class ListAllOtherUsers_GUI extends JFrame { @@ -62,14 +60,9 @@ public class ListAllOtherUsers_GUI extends JFrame { boolean activeSearch = false; String[] titles = { "userID", "Nachname", "Vorname", "Mail" }; - - ThriftConnection con = new ThriftConnection(); - Client client = models.Client.clientcon.getClient(); - //final DefaultTableModel modelUsers = new DefaultTableModel(titles, 0); private JButton btnAdd; private List map = null; // List of people - private JTextField textField; Component c = null; private JTable table; private int userIDPos; @@ -111,7 +104,6 @@ public class ListAllOtherUsers_GUI extends JFrame { @Override public void windowClosing(WindowEvent arg0) { // Beendet die Anwendung nach klick auf X - con.closeThriftConnection(); dispose(); } @@ -290,12 +282,10 @@ public class ListAllOtherUsers_GUI extends JFrame { @Override public void mousePressed(MouseEvent arg0) { - OpenLinks open = new OpenLinks(); - URI windows; try { windows = new URI(Links.getFAQ()); - open.openWebpage(windows); + OpenLinks.openWebpage(windows); } catch (URISyntaxException e) { e.printStackTrace(); @@ -309,11 +299,10 @@ public class ListAllOtherUsers_GUI extends JFrame { @Override public void mousePressed(MouseEvent arg0) { - OpenLinks open = new OpenLinks(); URI windows; try { windows = new URI(Links.getOTRS()); - open.openWebpage(windows); + OpenLinks.openWebpage(windows); } catch (URISyntaxException e) { e.printStackTrace(); } @@ -362,7 +351,7 @@ public class ListAllOtherUsers_GUI extends JFrame { } //get the info - map = client.getAllOtherSatelliteUsers(user,SessionData.session.getAuthToken()); + map = ThriftManager.getSatClient().getAllOtherSatelliteUsers(user,SessionData.session.getAuthToken()); Iterator i = map.iterator(); int x = 0; diff --git a/dozentenmodul/src/main/java/util/ServiceProviderResponse.java b/dozentenmodul/src/main/java/util/ServiceProviderResponse.java index 62819ded..99f120f1 100644 --- a/dozentenmodul/src/main/java/util/ServiceProviderResponse.java +++ b/dozentenmodul/src/main/java/util/ServiceProviderResponse.java @@ -1,14 +1,7 @@ package util; public class ServiceProviderResponse { - private String status; - - public String getStatus() { - return status; - } - - public void setStatus(String sTATUS) { - status = sTATUS; - } - + public String status; + public String id; + public String url; } diff --git a/dozentenmodul/src/main/java/util/ShibbolethECP.java b/dozentenmodul/src/main/java/util/ShibbolethECP.java index 3dea9e3e..b834b1a2 100644 --- a/dozentenmodul/src/main/java/util/ShibbolethECP.java +++ b/dozentenmodul/src/main/java/util/ShibbolethECP.java @@ -1,8 +1,10 @@ package util; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; import org.apache.http.HttpResponse; import org.apache.http.ParseException; @@ -30,14 +32,20 @@ public class ShibbolethECP { */ private static final Gson GSON = new GsonBuilder().create(); + /** + * URL for bwLehrpool registration + */ + private static URL _registrationUrl = null; /** * Return codes */ public static enum ReturnCode { NO_ERROR(0, "Authentication against the identity provider and request of the service provider resource worked."), ERROR_IDP(1, "Authentication against the identity provider failed."), - ERROR_SP(2, "Invalid resource of the service provider."), - ERROR_OTHER(3, "Internal class error."); + ERROR_UNREG(2, "User not registered to use bwLehrpool"), + ERROR_SP(3, "Invalid resource of the service provider."), + ERROR_URL(4, "Invalid URL received from master server."), + ERROR_OTHER(5, "Internal class error."); private final int id; private final String msg; @@ -63,7 +71,7 @@ public class ShibbolethECP { static { URI tmp; try { - tmp = new URI("https://bwlp-masterserver.ruf.uni-freiburg.de/secure-all/test.php"); + tmp = new URI("https://bwlp-masterserver.ruf.uni-freiburg.de/secure-all/api.php"); } catch (URISyntaxException e) { // should never happen! LOGGER.error("Bad URI syntax of the service provider, see trace: ", e); @@ -148,9 +156,23 @@ public class ShibbolethECP { LOGGER.error("Bad JSON syntax, see trace: ", e); return ReturnCode.ERROR_SP; } - LOGGER.debug("SP JSON STATUS: " + spr.getStatus()); // TODO: here we will need to parse the answer accordingly. // no errors, meaning everything worked fine. - return spr.getStatus().equals("funzt") ? ReturnCode.NO_ERROR : ReturnCode.ERROR_SP; + if (spr.status.equals("unregistered")) { + try { + _registrationUrl = new URL(spr.url); + } catch (MalformedURLException e) { + LOGGER.error("URL returned by masterserver is malformed, see trace: " + e); + return ReturnCode.ERROR_URL; + } + return ReturnCode.ERROR_UNREG; + } + // TODO the rest of the cases... + + // still here? then something else went wrong + return ReturnCode.ERROR_OTHER; + } + public static URL getRegistrationUrl() { + return _registrationUrl; } } -- cgit v1.2.3-55-g7522