Revision 294
Added by bojilova over 24 years ago
src/edu/ucsb/nceas/metacat/MetaCatSession.java | ||
---|---|---|
17 | 17 |
import java.util.Properties; |
18 | 18 |
import java.util.PropertyResourceBundle; |
19 | 19 |
import java.io.FileInputStream; |
20 |
import java.io.PrintWriter; |
|
20 | 21 |
import java.rmi.*; |
21 | 22 |
import SrbJavaGlueInterface; |
23 |
import RMIControllerInterface; |
|
22 | 24 |
|
23 | 25 |
/** |
24 | 26 |
* A Class that implements session tracking for MetaCatServlet users. |
... | ... | |
27 | 29 |
*/ |
28 | 30 |
public class MetaCatSession { |
29 | 31 |
|
32 |
static String debug = null; |
|
30 | 33 |
HttpSession session = null; |
31 | 34 |
// JNI (Java Native Interface) routines for SRB |
32 | 35 |
static String srbHost; |
33 | 36 |
static String srbPort; |
37 |
static String RMIhost; |
|
38 |
static RMIControllerInterface rmicon; |
|
34 | 39 |
static SrbJavaGlueInterface srbJG; |
35 | 40 |
static { |
36 |
try { |
|
41 |
try {
|
|
37 | 42 |
PropertyResourceBundle SRBProps = null; |
38 | 43 |
// SRB properties that tells about the location of SRB RMI Server |
39 | 44 |
// srbProps.properties should reside on metacat server |
... | ... | |
42 | 47 |
srbHost = (String)SRBProps.handleGetObject("host"); |
43 | 48 |
srbPort = (String)SRBProps.handleGetObject("port"); |
44 | 49 |
// should handle missing RMIhost name here |
45 |
String RMIhost = (String)SRBProps.handleGetObject("RMIhost"); |
|
46 |
String name = "//" + RMIhost + "/SrbJavaGlue"; |
|
50 |
RMIhost = (String)SRBProps.handleGetObject("RMIhost"); |
|
51 |
String name = "//" + RMIhost + "/RMIController"; |
|
52 |
rmicon = (RMIControllerInterface)Naming.lookup(name); |
|
53 |
name = "//" + RMIhost + "/SrbJavaGlue"; |
|
47 | 54 |
srbJG = (SrbJavaGlueInterface)Naming.lookup(name); |
48 | 55 |
} catch (Exception e) { |
49 |
System.out.println("MetaCatSession static: " + e.getMessage()); |
|
56 |
System.err.println("MetaCatSession static: " + e.getMessage()); |
|
57 |
System.exit(0); |
|
50 | 58 |
} |
51 | 59 |
} |
52 | 60 |
|
... | ... | |
57 | 65 |
* @param password the password entered when login |
58 | 66 |
*/ |
59 | 67 |
public MetaCatSession (HttpServletRequest request, |
60 |
String username, String password) {
|
|
61 |
|
|
68 |
String username, String password) |
|
69 |
throws IllegalStateException { |
|
62 | 70 |
// create a new HTTPSession object |
63 | 71 |
this.session = getSession(request, username, password); |
64 | 72 |
} |
... | ... | |
85 | 93 |
} |
86 | 94 |
|
87 | 95 |
/** Try to make user authentication through SRB RMI Connection */ |
88 |
public boolean userAuth(String password) |
|
96 |
public boolean userAuth(String username, String password)
|
|
89 | 97 |
throws RemoteException { |
90 | 98 |
int srbconn = 0; |
91 |
int err; |
|
99 |
|
|
100 |
// look up for SRBJavaGlue |
|
101 |
try { |
|
102 |
String name = "//" + RMIhost + "/SrbJavaGlue"; |
|
103 |
srbJG = (SrbJavaGlueInterface)Naming.lookup(name); |
|
104 |
} catch (Exception e) { |
|
105 |
throw new |
|
106 |
RemoteException("MetaCatSession look up for SrbJavaGlue failed"); |
|
107 |
} |
|
92 | 108 |
|
93 | 109 |
// try SRB RMI Connection |
94 | 110 |
// integer value of the SBR Connection ID is returned only |
95 |
try { |
|
96 |
srbconn = srbJG.clConnectJ( srbHost, srbPort, password );
|
|
111 |
try {
|
|
112 |
srbconn = srbJG.rmiConnectJ( srbHost, srbPort, password, username );
|
|
97 | 113 |
} catch (RemoteException e) { |
114 |
rmicon.restart(); |
|
98 | 115 |
throw new RemoteException("MetaCatSession.userAuth() - " + |
99 |
"Error on clConnectJ(): " + e.getMessage());
|
|
116 |
"Error on rmiConnectJ(): " + e.getMessage());
|
|
100 | 117 |
} |
101 | 118 |
|
102 | 119 |
// check if successfull |
103 |
if ( srbconn < 0 ) { |
|
104 |
// srb connection is already finished from clConnectJ() routine
|
|
120 |
if ( srbconn <= 0 ) {
|
|
121 |
rmicon.restart();
|
|
105 | 122 |
return false; |
106 |
//throw new RemoteException("MetaCatSession.userAuth() failure: " + |
|
107 |
// "SRB Connection failed"); |
|
108 | 123 |
} |
109 | 124 |
|
110 | 125 |
// we don't need that connection. close it. |
111 | 126 |
try { |
112 |
err = srbJG.clFinishJ( srbconn ); |
|
113 |
} catch (RemoteException e) { |
|
114 |
throw new RemoteException("MetaCatSession.userAuth() - " + |
|
115 |
"Error on clFinishJ(): " + e.getMessage()); |
|
116 |
} |
|
127 |
int err = srbJG.rmiFinishJ( srbconn ); |
|
128 |
} catch (RemoteException e) {} |
|
117 | 129 |
|
118 | 130 |
// store SRB Connection in the session for later use if necessary |
119 | 131 |
this.session.putValue("srbconnection", new Integer(srbconn)); |
Also available in: Unified diff
no message