blob: ba88ad4985f032be64a3c2aaf6f2c37e18fb86a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* Copyright (c) 2009 Manuel Traut and Volker Dahnke
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors: Manuel Traut and Volker Dahnke
*/
package YalpAuth.YalpPGSqlAuth;
import YalpInterfaces.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
/*
* Class PGSqlAuth
*
* <em>Postgre SQL database connection</em>
*
* @author Volker Dahnke / Manuel Traut
*
* @version 2.1 2009-11-21<br>
*/
public class PGSqlAuth {
private static ORB orb;
private static POA poa;
private static YalpAuthPluginImpl psql;
private static AuthPluginInterface authPlugin;
private static ServerControlInterface srvCon;
private static PluginInfo pluginInfo;
public PGSqlAuth(String[] argv) {
pluginInfo = new PluginInfo();
pluginInfo.name = "Postgre SQL Auth Plugin";
pluginInfo.description = "provides Postgre SQL database based user authentification";
pluginInfo.type = PluginType.AUTH_PLUGIN;
// pluginInfo.supportedTypes = new MediaType[];
try {
this.orb = ORB.init(argv, null);
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
} catch(Exception e) {
/* t.b.d. error handling */
System.out.println("couldn't host plugin implementation");
}
try {
poa.the_POAManager().activate();
} catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive e) {
/* t.b.d. error handling */
System.out.println("poa inactive");
}
YalpErrorHolder err = new YalpErrorHolder();
try {
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
String name = "YALP_Server";
srvCon = ServerControlInterfaceHelper.narrow(ncRef.resolve_str(name));
} catch (Exception e) {
System.out.println("Couldn't connect to YALP Server");
System.exit(0);
}
psql = new YalpAuthPluginImpl();
psql.setORB(orb);
try {
poa.activate_object(psql);
org.omg.CORBA.Object ref = poa.servant_to_reference(psql);
authPlugin = AuthPluginInterfaceHelper.narrow(ref);
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
String name = "YALP_Postgre_SQL_Auth";
NameComponent path[] = ncRef.to_name(name);
ncRef.rebind(path, authPlugin);
PluginInfoHolder tmp = new PluginInfoHolder(pluginInfo);
srvCon.ping(err);
System.out.println(err.value.descr);
srvCon.registerAuthPlugin(authPlugin, tmp, err );
pluginInfo = tmp.value;
if(err.value.code != YalpErrorCode.OK)
{
System.out.println("registring authplugin failed");
return;
}
psql.setInfo(pluginInfo);
System.out.println("auth plugin registered");
orb.run();
} catch (Exception e) {
System.out.println("binding plugin failed 1");
e.printStackTrace();
System.exit(0);
}
}
}
|