perfsonar-dev - perfsonar: r2309 - branches/as/src/org/perfsonar/service/topologyService
Subject: perfsonar development work
List archive
- From:
- To:
- Subject: perfsonar: r2309 - branches/as/src/org/perfsonar/service/topologyService
- Date: Wed, 28 Mar 2007 10:31:58 -0400
Author: rodriguez
Date: 2007-03-28 10:31:57 -0400 (Wed, 28 Mar 2007)
New Revision: 2309
Modified:
branches/as/src/org/perfsonar/service/topologyService/TopServiceEngine.java
branches/as/src/org/perfsonar/service/topologyService/TopsDownloadAction.java
Log:
The Topology Service is requiring a valid Security Token in request. Wow,
it's so simple to add authorization in a service... ;-)
Modified:
branches/as/src/org/perfsonar/service/topologyService/TopServiceEngine.java
===================================================================
---
branches/as/src/org/perfsonar/service/topologyService/TopServiceEngine.java
2007-03-28 14:29:43 UTC (rev 2308)
+++
branches/as/src/org/perfsonar/service/topologyService/TopServiceEngine.java
2007-03-28 14:31:57 UTC (rev 2309)
@@ -13,6 +13,12 @@
import org.perfsonar.commons.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.commons.auxiliary.ComponentNames;
import org.perfsonar.commons.auxiliary.components.logger.LoggerComponent;
+import org.perfsonar.service.commons.authn.AADispatchManager;
+import org.perfsonar.service.commons.authn.AADispatchProtocolFactory;
+import org.perfsonar.service.commons.authn.AuthNRequest;
+import org.perfsonar.service.commons.authn.AuthNResponse;
+import org.perfsonar.service.commons.authn.tokens.SecTokenManagerFactory;
+import org.perfsonar.service.commons.authn.tokens.SecurityToken;
import org.perfsonar.service.commons.engine.ActionType;
import org.perfsonar.service.commons.engine.ServiceEngine;
import org.perfsonar.service.commons.exceptions.DataFormatException;
@@ -22,11 +28,11 @@
/**
* ServiceEngine class for the Topology Service. (The heart of the Topology
* Service)
- *
+ *
* @see org.perfsonar.service.commons.ServiceEngine
* @author Ulisses Alonso, used Maciej Glowiak's LookupService as an
skeleton,
* and modified by Candido Rodriguez
- *
+ *
*/
public class TopServiceEngine implements ServiceEngine {
@@ -135,19 +141,6 @@
throw new SystemException("error.tops.dependency", m);
}
-/* String mm = "TopServiceEngine: trying to get registrator
component";
- logger.debug(mm);
-
- topsRegistration = (TopsLSRegistrationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(TOPS_REGISTRATOR_COMPONENT);
-
- if (topsRegistration == null) {
- String m = "TopServiceEngine: can't obtain ["
- + TOPS_REGISTRATOR_COMPONENT + "]
component";
- logger.error(m);
- throw new SystemException("error.tops.dependency", m);
- }
-*/
logger.debug("TopServiceEngine: started ");
} // constructor
@@ -157,9 +150,9 @@
/**
* Method which provides access the type of ServiceEngine. It
implements the
* method definition in ServiceEngine Interface
- *
+ *
* @return String containing ServiceEngine Type
- *
+ *
* @see org.perfsonar.service.commons.engine.ServiceEngine#getType()
*/
public String getType() {
@@ -171,13 +164,13 @@
/**
* Method to accept requests for action. It implements the method
definition
* in ServiceEngine Interface
- *
+ *
* @return Message object containing the response
- *
+ *
* @throws SystemException
* @throws RequestException
* @throws DataFormatException
- *
+ *
* @see org.perfsonar.service.commons.engine.ServiceEngine
*/
public Message takeAction(String actionType, Message request)
@@ -217,8 +210,31 @@
throw new
SystemException("error.common.action_not_supported", m);
}
- response = action.performAction(request);
+ // We need to check if client is allowed to request any to
this service
+ logger.debug("TopServiceEngine: making authorization of the
request");
+ AuthNResponse resp=null;
+ SecurityToken st=new
SecurityToken(SecTokenManagerFactory.getDefaultSecTokenManager());
+ if (!st.hasSecTokenInRequest()) {
+ String m = "TopServiceEngine: The request has not
sent a valid Security Token";
+ logger.info(m);
+ throw new
SystemException("error.authn.not_sectoken",m);
+ }
+ else {
+ st.setSecTokenFromRequest();
+ AuthNRequest req=new AuthNRequest(st);
+ AADispatchManager aaManager=new
AADispatchManager(AADispatchProtocolFactory.getDefaultAADispatchProtocol());
+ resp=aaManager.getAuthorizationService(getType(),
req);
+ }
+ if (resp!=null&&resp.getStatus()==AuthNResponse.AUTHORIZED) {
+ response = action.performAction(request);
+ }
+ else {
+ String m = "TopServiceEngine: The request has not
been authorized by the Authorization Service";
+ logger.info(m);
+ throw new
SystemException("error.authn.not_authorized",m);
+ }
+
// ------end of serving actions
---------------------------------------
String m;
Modified:
branches/as/src/org/perfsonar/service/topologyService/TopsDownloadAction.java
===================================================================
---
branches/as/src/org/perfsonar/service/topologyService/TopsDownloadAction.java
2007-03-28 14:29:43 UTC (rev 2308)
+++
branches/as/src/org/perfsonar/service/topologyService/TopsDownloadAction.java
2007-03-28 14:31:57 UTC (rev 2309)
@@ -6,7 +6,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
import java.util.UUID;
@@ -45,14 +44,14 @@
private static String TTL_PARAM = "ttl";
private static String EVENT_TYPE_SUCCESS = "success.tops.downloaddb";
private static String EVENT_TYPE_WRONG_PARAMS =
"error.tops.parameters";
-
+
private Properties interfacesDesc;
public TopsDownloadAction(Connection jdbc) throws SystemException {
super(jdbc);
readInterfacesDescription();
}
-
+
private void readInterfacesDescription() throws SystemException {
try {
interfacesDesc=new Properties();
@@ -65,15 +64,15 @@
throw new SystemException("error.tops.fetching", m);
}
}
-
+
private boolean checkParams(Metadata metadata) {
boolean res=false;
-
+
if
(metadata.getParameterByName(TIME_PARAM).getParameterValue().equals("now")&&
metadata.getParameterByName(DOMAINID_PARAM)!=null) {
res=true;
}
-
+
return res;
}
@@ -84,7 +83,7 @@
params.addParameter(REQUESTID_PARAM,
UUID.randomUUID().toString());
params.addParameter(SERVERID_PARAM,
basicMetadata.getParameterByName(DOMAINID_PARAM).getParameterValue());
}
-
+
@Override
public Message performAction(Message request) throws SystemException,
RequestException, DataFormatException {
@@ -93,7 +92,7 @@
Message response = new Message();
response.setType(TYPE_RESPONSE);
-
+
// Parsing metadata...
logger.debug(ROOT_LOG+"parsing metadatas...");
Metadata basicMetadata=null;
@@ -146,7 +145,7 @@
try {
Statement st = jdbc.createStatement();
ResultSet rs;
-
+
String select_network_interfaces= "SELECT speed,
if_highspeed, if_speed, " +
"if_type, if_index, if_description, " +
"default_ip_interface_address,
default_ip_network_subnet_prefix, object_id " +
@@ -165,11 +164,11 @@
String interface_ref = i.toString();
Interface iface = new Interface();
iface.setInterfaceIdRef(interface_ref);
-
+
Type type = new Type();
type.setType(convertIfTypeToDescription(rs.getInt(4)));
iface.setTypeElement(type);
-
+
if (rs.getString(5) != null) { // if_index
IfIndex ifindex=new IfIndex();
ifindex.setIfIndex(rs.getString(5));
@@ -181,18 +180,18 @@
ifdescription.setIfDescription(rs.getString(6));
iface.setIfDescriptionElement(ifdescription);
}
-
+
Long speed = getSpeedOfInterface(rs.getLong(1),
rs.getLong(2), rs.getLong(3));
Capacity capacity=new Capacity();
capacity.setCapacity(speed.toString());
iface.setCapacityElement(capacity);
-
+
if (rs.getString(7) != null) { //
default_ip_interface_address
IpAddress ipaddress= new IpAddress();
ipaddress.setIpAddress(rs.getString(7));
iface.setIpAddressElement(ipaddress);
}
-
+
if (rs.getString(8) != null) { //
default_ip_network_subnet_prefix
Netmask netmask= new Netmask();
netmask.setNetmask(rs.getString(8));
@@ -214,7 +213,7 @@
try {
Statement st = jdbc.createStatement();
ResultSet rs;
-
+
String select_network= "SELECT network_type, network_name " +
"FROM network " +
"WHERE object_id = " + network_oid;
@@ -223,7 +222,7 @@
while (rs.next()) {
Link link = new Link();
-
+
if (rs.getString(1) != null) { // network_type field
Type type = new Type();
type.setType(rs.getString(1));
@@ -234,19 +233,19 @@
name.setName(rs.getString(2));
link.setNameElement(name);
}
-
+
fillNetworkInterfaces(link, network_oid);
networksData.setChild(link);
}
-
+
rs.close();
st.close();
-
+
} catch (SQLException e) {
- String m= ROOT_LOG+"fillNetwork: error while fetching from the
database:"
+ String m= ROOT_LOG+"fillNetwork: error while fetching from the
database:"
+ e.getMessage();
-
+
logger.error(m);
throw new SystemException("error.tops.fetching", m);
}
@@ -263,27 +262,27 @@
"INNER JOIN network_interface_key ON
network_interface.object_id = network_interface_key.object_id " +
"INNER JOIN network_node ON
network_interface_key.object_id_of_network_node = network_node.object_id " +
"INNER JOIN network_node_key ON network_node.object_id =
network_node_key.object_id AND network_node_key.domain_id = " + domain_id;
-
+
logger.debug(ROOT_LOG+"executing query: "+select_network_oid);
rs= st.executeQuery(select_network_oid);
while (rs.next()) { // iterate results
network_interface_oid= rs.getInt(2); //
network_interface_object_id
network_oid= rs.getInt(1); // network_object_id
-
+
fillNetwork(networksData, network_oid);
}
-
+
rs.close();
st.close();
} catch (SQLException e) {
- String m= ROOT_LOG+"fillNodesNetworks: error while fetching from
the database:"
+ String m= ROOT_LOG+"fillNodesNetworks: error while fetching from
the database:"
+ e.getMessage();
logger.error(m);
throw new SystemException("error.tops.fetching", m);
}
- }
+ }
protected void fillNodes(Data nodesData, String domain_id) throws
SystemException {
String m;
@@ -301,7 +300,7 @@
logger.debug(ROOT_LOG+"executing query: "+select_node);
ResultSet rs_nodes= st_nodes.executeQuery(select_node);
-
+
while (rs_nodes.next()) { // iterate results
Node node= new Node();
if (rs_nodes.getString(4) != null) { // HostName is optional
@@ -310,13 +309,13 @@
node.setHostNameElement(hostname);
}
if (rs_nodes.getString(6) != null) { // Type is optional
- org.ggf.ns.nmwg.topology.base.v3_0.Type type=
+ org.ggf.ns.nmwg.topology.base.v3_0.Type type=
new org.ggf.ns.nmwg.topology.base.v3_0.Type();
type.setType(rs_nodes.getString(6));
node.setTypeElement(type);
}
if (rs_nodes.getString(7) != null) { // Name is optional
- org.ggf.ns.nmwg.topology.base.v3_0.Name name=
+ org.ggf.ns.nmwg.topology.base.v3_0.Name name=
new org.ggf.ns.nmwg.topology.base.v3_0.Name();
name.setType(convertUsageTypeToDescription(rs_nodes.getString(6)));
name.setName(rs_nodes.getString(7));
@@ -328,23 +327,23 @@
setLocationOfNode(node,rs_nodes.getString(3),domain_id);
}
setInterfaceOfNode(node,node_id);
-
+
nodesData.setChild(node);
}
-
+
rs_nodes.close();
st_nodes.close();
-
+
} catch (SQLException e) {
-
- m= "TopServiceEngine: fillNodes: error while fetching from the
database:"
+
+ m= "TopServiceEngine: fillNodes: error while fetching from the
database:"
+ e.getMessage();
logger.error(m);
throw new SystemException("error.tops.fetching", m);
}
}
-
+
private void setLocationOfNode(Node node, String locationId, String
domainId) throws SQLException {
// Get the location field
Location location=new Location();
@@ -355,15 +354,15 @@
Statement st_location = jdbc.createStatement();
logger.debug(ROOT_LOG+"executing query: "+select_location);
ResultSet rs_location= st_location.executeQuery(select_location);
-
+
if (rs_location.getString(1) != null) {
location.setLocation(rs_location.getString(1));
}
-
+
String select_domain= "SELECT domain_name,
country_iso3166_code " +
"FROM domain" +
"WHERE domain_id=" + domainId;
-
+
Statement st_domain= jdbc.createStatement();
logger.debug(ROOT_LOG+"executing query: "+select_domain);
ResultSet rs_domain= st_domain.executeQuery(select_domain);
@@ -379,11 +378,11 @@
country.setCountry(rs_domain.getString(2));
location.setCountryElement(country);
}
-
+
// --FIXME: check what happens if an empty location is
inserted in the node
node.setLocationElement(location);
}
-
+
private void setInterfaceOfNode(Node node,int node_id) throws
SQLException{
String interface_ref;
Integer i;
@@ -395,26 +394,26 @@
Statement st_interfaces= jdbc.createStatement();
logger.debug(ROOT_LOG+"executing query:
"+select_node_interfaces);
ResultSet rs_interfaces=
st_interfaces.executeQuery(select_node_interfaces);
-
+
while(rs_interfaces.next()) {
i= rs_interfaces.getInt(1);
- interface_ref= i.toString(); // We use the object id of the
interface
+ interface_ref= i.toString(); // We use the object id of the
interface
// for reference within the document
- /*
+ /*
TODO:
- The following is not possible now (august 2006) and
according
- to Jason should be done this way. Instead we use base
interfaces
+ The following is not possible now (august 2006) and
according
+ to Jason should be done this way. Instead we use base
interfaces
and seems to generate proper xml.
-
- org.ggf.ns.nmwg.topology.l3.v3_0.Interface iface=
+
+ org.ggf.ns.nmwg.topology.l3.v3_0.Interface iface=
new
org.ggf.ns.nmwg.topology.l3.v3_0.Interface();
*/
- org.ggf.ns.nmwg.topology.base.v3_0.Interface iface=
+ org.ggf.ns.nmwg.topology.base.v3_0.Interface iface=
new org.ggf.ns.nmwg.topology.base.v3_0.Interface();
-
+
iface.setInterfaceIdRef(interface_ref);
node.setInterface(iface);
}
@@ -448,15 +447,15 @@
}
protected String convertUsageTypeToDescription(String usageType) {
- /*
+ /*
This is a kind of hack in the database, the IDs where
not specified when the Tops was developed, we specify the
meaning here:
-
+
from CNM GWIN:
core router
access router
other router
-
+
We add an additional code for "unspecified"
*/
String conv[] = {
@@ -467,15 +466,15 @@
};
try {
int usage_type=Integer.parseInt(usageType);
-
+
if ((usage_type < 0) || (usage_type > conv.length)) {
return conv[0]; // return "unspecified"
}
-
+
return conv[usage_type];
} catch (NumberFormatException e) {
return conv[0];
}
}
-
+
}
- perfsonar: r2309 - branches/as/src/org/perfsonar/service/topologyService, svnlog, 03/28/2007
Archive powered by MHonArc 2.6.16.