perfsonar-dev - r1903 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security
Subject: perfsonar development work
List archive
r1903 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security
Chronological Thread
- From:
- To:
- Subject: r1903 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security
- Date: Thu, 11 Jan 2007 18:54:26 -0500
Author: uros
Date: 2007-01-11 18:54:25 -0500 (Thu, 11 Jan 2007)
New Revision: 1903
Modified:
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security/Credentials.java
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security/CredentialsException.java
Log:
Implementation of credentials supporting role based authorization retrieval
for filtering, sampling and anonymization.
Modified:
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security/Credentials.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security/Credentials.java
2007-01-10 21:18:18 UTC (rev 1902)
+++
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security/Credentials.java
2007-01-11 23:54:25 UTC (rev 1903)
@@ -13,6 +13,9 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.ArrayList;
/**
* This class provides access to user credentials (authentication and
@@ -23,15 +26,776 @@
public class Credentials {
+
+
+ /**
+ * Authorization type declaration.
+ */
+ public enum AuthorizationType {
+
+ UNUSED(null),
+ ANONYMIZATION("anonymization"),
+ HEADER_FILTER("header_filter"),
+ PAYLOAD_FILTER("payload_filter"),
+ SAMPLING("sampling");
+
+ /**
+ * Constructor with authorization type name argument.
+ *
+ * @param type authorization type name
+ */
+ private AuthorizationType(String type) {
+
+ this.type = type;
+
+ }
+
+ /**
+ * Authorization type name getter.
+ *
+ * @return authorization type name
+ */
+ public String getType() {
+
+ return type;
+
+ }
+
+ /**
+ * Return authorization type identified by authorization type name.
+ *
+ * @return authorization type or null if not found
+ */
+ public static AuthorizationType getTypeByName(String type) {
+
+ for (AuthorizationType at :
EnumSet.allOf(AuthorizationType.class)) {
+
+ if (at.getType().equals(type)) return at;
+
+ }
+
+ return null;
+
+ }
+
+ /**
+ * Sampling type name holder.
+ */
+ private final String type;
+ }
+
+ /**
+ * Sampling type declaration.
+ */
+ public enum SamplingType {
+
+ DETERMINISTIC("deterministic"),
+ PROBABILISTIC("probabilistic");
+
+ /**
+ * Constructor with sampling type name argument.
+ *
+ * @param type sampling type name
+ */
+ private SamplingType(String type) {
+
+ this.type = type;
+
+ }
+
+ /**
+ * Sampling type name getter.
+ *
+ * @return sampling type name
+ */
+ public String getType() {
+
+ return type;
+
+ }
+
+ /**
+ * Return sampling type identified by sampling type name.
+ *
+ * @return sampling type or null if not found
+ */
+ public static SamplingType getTypeByName(String type) {
+
+ for (SamplingType st : EnumSet.allOf(SamplingType.class)) {
+
+ if (st.getType().equals(type)) return st;
+
+ }
+
+ return null;
+
+ }
+
+ /**
+ * Sampling type name holder.
+ */
+ private final String type;
+ }
+
+ /**
+ * Anonymization protocol types.
+ */
+ public enum AnonymizationProtocolType {
+
+ IP("ip"),
+ TCP("tcp"),
+ UDP("udp"),
+ ICMP("icmp"),
+ HTTP("http"),
+ FTP("ftp");
+
+
+ /**
+ * Constructor with anonymization protocol type name.
+ *
+ * @param type anonymization protocol type name
+ */
+ private AnonymizationProtocolType(String type) {
+
+ this.type = type;
+
+ }
+
+ /**
+ * Anonymization protocol type name getter.
+ *
+ * @return anonymization protocol type name
+ */
+ public String getType() {
+
+ return type;
+
+ }
+
+ /**
+ * Return anonymization protocol type identified by anon type name.
+ *
+ * @return anonymization protocol type or null if not found
+ */
+ public static AnonymizationProtocolType getTypeByName(String type) {
+
+ for (AnonymizationProtocolType st :
+ EnumSet.allOf(AnonymizationProtocolType.class)) {
+
+ if (st.getType().equals(type)) return st;
+
+ }
+
+ return null;
+
+ }
+
+ private final String type;
+
+ }
+
+ /**
+ * Anonymization field types.
+ */
+ public enum AnonymizationFieldType {
+
+ PAYLOAD("payload"),
+ CHECKSUM("checksum"),
+ SRC_IP("srcIp"),
+ DST_IP("dstIp"),
+ TTL("ttl"),
+ TOS("tos"),
+ ID("id"),
+ IP_VERSION("fieldVersion"),
+ OPTIONS("options"),
+ PACKET_LENGTH("packetLength"),
+ IP_PROTO("ipProto"),
+ IHL("ihl"),
+ FRAGMENT_OFFSET("fragmentOffset"),
+ SRC_PORT("srcPort"),
+ DST_PORT("dstPort"),
+ SEQUENCE_NUMBER("sequenceNumber"),
+ OFFSET_AND_RESERVED("offsetAndReserved"),
+ ACK_NUMBER("ackNumber"),
+ FLAGS("flags"),
+ URGENT_POINTER("urgentPointer"),
+ WINDOW("window"),
+ TCP_OPTIONS("tcpOptions"),
+ UDP_DATAGRAM_LENGTH("udpDatagramLength"),
+ TYPE("type"),
+ CODE("code"),
+ HTTP_VERSION("httpVersion"),
+ METHOD("method"),
+ URI("uri"),
+ USER_AGENT("userAgent"),
+ ACCEPT("accept"),
+ ACCEPT_CHARSET("acceptCharset"),
+ ACCEPT_ENCODING("acceptEncoding"),
+ ACCEPT_LANGUAGE("acceptLanguage"),
+ ACCEPT_RANGES("acceptRanges"),
+ AGE("age"),
+ ALLOW("allow"),
+ AUTHORIZATION("authorization"),
+ CACHE_CONTROL("chacheControl"),
+ CONNECTION_TYPE("connectionType"),
+ CONTENT_TYPE("contentType"),
+ CONTENT_LENGTH("contentLength"),
+ CONTENT_LOCATION("contentLocation"),
+ CONTENT_MD5("contentMd5"),
+ CONTENT_RANGE("contentRange"),
+ COOKIE("cookie"),
+ ETAG("etag"),
+ EXPECT("expect"),
+ EXPIRES("expires"),
+ FROM("from"),
+ HOST("host"),
+ IF_MATCH("ifMatch"),
+ IF_MODIFIED_SINCE("ifModifiedSince"),
+ IF_NONE_MATCH("ifNoneMatch"),
+ IF_RANGE("ifRange"),
+ IF_UNMODIFIED_SINCE("ifUnmodifiedSince"),
+ LAST_MODIFIED("lastModified"),
+ MAX_FORWRDS("maxForwrds"),
+ PRAGMA("pragma"),
+ PROXY_AUTHENTICATE("proxyAuthenticate"),
+ PROXY_AUTHORIZATION("proxyAuthorization"),
+ RANGE("range"),
+ REFERRER("referrer"),
+ RETRY_AFTER("retryAfter"),
+ SET_COOKIE("setCookie"),
+ SERVER("server"),
+ TE("te"),
+ TRAILER("trailer"),
+ TRANSFER_ENCODING("transferEncoding"),
+ UPGRADE("upgrade"),
+ VIA("via"),
+ WARNING("warning"),
+ WWW_AUTHENTICATE("wwwAuthenticate"),
+ X_POWERED_BY("xPoweredBy"),
+ RESPONSE_CODE("responseCode"),
+ RESP_CODE_DESCR("respCodeDescr"),
+ VARY("vary"),
+ DATE("date"),
+ CONTENT_ENCODING("contentEncoding"),
+ KEEP_ALIVE("keepAlive"),
+ LOCATION("location"),
+ CONTENT_LANGUAGE("contentLanguage"),
+ DERIVED_FROM("derivedForm"),
+ ALLOWED("allowed"),
+ MIME_VERSION("mimeVersion"),
+ TITLE("title"),
+ REFRESH("refresh"),
+ HTTP_PAYLOAD("httpPayload"),
+ USER("user"),
+ PASS("pass"),
+ ACCT("acct"),
+ FTP_TYPE("ftpType"),
+ STRU("stru"),
+ MODE("mode"),
+ CWD("cwd"),
+ PWD("pwd"),
+ CDUP("cdup"),
+ PASV("pasv"),
+ RETR("retr"),
+ REST("rest"),
+ PORT("port"),
+ LIST("list"),
+ NLST("nlst"),
+ QUIT("quit"),
+ SYST("syst"),
+ STAT("stat"),
+ HELP("help"),
+ NOOP("noop"),
+ STOR("stor"),
+ APPE("appe"),
+ STOU("stou"),
+ ALLO("allo"),
+ MKD("mkd"),
+ RMD("rmd"),
+ DELE("dele"),
+ RNFR("rnfr"),
+ RNTO("rnto"),
+ SITE("site"),
+ FTP_RESPONSE_CODE("ftpResponseCode"),
+ FTP_RESPONSE_ARG("ftpResponseArg");
+
+
+ /**
+ * Constructor with anonymization field type name.
+ *
+ * @param type anonymization field type name
+ */
+ private AnonymizationFieldType(String type) {
+
+ this.type = type;
+
+ }
+
+ /**
+ * Anonymization field type name getter.
+ *
+ * @return anonymization field type name
+ */
+ public String getType() {
+
+ return type;
+
+ }
+
+ /**
+ * Return anonymization field type identified by anon type name.
+ *
+ * @return anonymization field type or null if not found
+ */
+ public static AnonymizationFieldType getTypeByName(String type) {
+
+ for (AnonymizationFieldType aft :
+ EnumSet.allOf(AnonymizationFieldType.class)) {
+
+ if (aft.getType().equals(type)) return aft;
+
+ }
+
+ return null;
+
+ }
+
+ private final String type;
+
+ }
+
+ /**
+ * Anonymization function types.
+ */
+ public enum AnonymizationFunctionType {
+
+ UNCHANGED("unchanged"),
+ MAP("map"),
+ MAP_DISTRIBUTION("mapDistribution"),
+ STRIP("strip"),
+ RANDOM("random"),
+ HASHED("hashed"),
+ PATTERN_FILL("patternFill"),
+ ZERO("zero"),
+ REPLACE("replace"),
+ PREFIX_PRESERVING("prefixPreserving"),
+ PREFIX_PRESERVING_MAP("prefixPreservingMap"),
+ CHECKSUM_ADJUST("checksumAdjust"),
+ FILENAME_RANDOM("filenameRandom"),
+ REGEXP("regexp");
+
+
+ /**
+ * Constructor with anonymization function type name.
+ *
+ * @param type anonymization function type name
+ */
+ private AnonymizationFunctionType(String type) {
+
+ this.type = type;
+
+ }
+
+ /**
+ * Anonymization function type name getter.
+ *
+ * @return anonymization function type name
+ */
+ public String getType() {
+
+ return type;
+
+ }
+
+ /**
+ * Return anonymization function type identified by anon type name.
+ *
+ * @return anonymization function type or null if not found
+ */
+ public static AnonymizationFunctionType getTypeByName(String type) {
+
+ for (AnonymizationFunctionType aft :
+ EnumSet.allOf(AnonymizationFunctionType.class)) {
+
+ if (aft.getType().equals(type)) return aft;
+
+ }
+
+ return null;
+
+ }
+
+ private final String type;
+
+ }
+
+ /**
+ * Anonymization hash function types.
+ */
+ public enum AnonymizationHashFunctionType {
+
+ SHA("sha"),
+ MD5("md5"),
+ CRC32("crc32"),
+ SHA_2("sha2"),
+ TRIPLEDES("trippleDes"),
+ AES("aes"),
+ DES("des");
+
+
+ /**
+ * Constructor with anonymization hash function type name.
+ *
+ * @param type anonymization hash function type name
+ */
+ private AnonymizationHashFunctionType(String type) {
+
+ this.type = type;
+
+ }
+
+ /**
+ * Anonymization hash function type name getter.
+ *
+ * @return anonymization hash function type name
+ */
+ public String getType() {
+
+ return type;
+
+ }
+
+ /**
+ * Return anonymization hash function type identified by anon type
name.
+ *
+ * @return anonymization hash function type or null if not found
+ */
+ public static AnonymizationHashFunctionType getTypeByName(String
type) {
+
+ for (AnonymizationHashFunctionType ahft :
+ EnumSet.allOf(AnonymizationHashFunctionType.class)) {
+
+ if (ahft.getType().equals(type)) return ahft;
+
+ }
+
+ return null;
+
+ }
+
+ private final String type;
+
+ }
+
+ /**
+ * Anonymization hash function padding types.
+ */
+ public enum AnonymizationHashFunctionPaddingType {
+
+ PAD_WITH_ZERO("padWithZero"),
+ STRIP_REST("stripRest");
+
+
+ /**
+ * Constructor with anonymization hash function padding type name.
+ *
+ * @param type anonymization hash function padding type name
+ */
+ private AnonymizationHashFunctionPaddingType(String type) {
+
+ this.type = type;
+
+ }
+
+ /**
+ * Anonymization hash function padding type name getter.
+ *
+ * @return anonymization hash function padding type name
+ */
+ public String getType() {
+
+ return type;
+
+ }
+
+ /**
+ * Return anonymization hash function padding type
+ * identified by anon type name.
+ *
+ * @return anonymization hash function padding type or null if not
found
+ */
+ public static AnonymizationHashFunctionPaddingType getTypeByName(
+ String type) {
+
+ for (AnonymizationHashFunctionPaddingType ahfpt :
+ EnumSet.allOf(AnonymizationHashFunctionPaddingType.class)) {
+
+ if (ahfpt.getType().equals(type)) return ahfpt;
+
+ }
+
+ return null;
+
+ }
+
+ private final String type;
+
+ }
+
+ /**
+ * This class provides placeholder for sampling authorization data
+ *
+ * @author urosj
+ */
+ public class Sampling {
+
+
+ // ---------------------------------- class fields
+
+
+ private SamplingType type = null;
+ private int threshold = -1;
+
+ // ---------------------------------- constructors
+
+
+ /**
+ * Default constructor
+ */
+ public Sampling() {
+
+ }
+
+ /**
+ * Constructor with type and threshold.
+ *
+ * @param type sampling type
+ * @param threshold sampling threshold
+ */
+ public Sampling(SamplingType type, int threshold) {
+
+ this.type = type;
+ this.threshold = threshold;
+
+ }
+
+
+ // ---------------------------------- public methods
+
+
+ /**
+ * Sampling type setter.
+ *
+ * @param type sampling type
+ */
+ public void setType(SamplingType type) {
+
+ this.type = type;
+
+ }
+
+ /**
+ * Sampling type getter.
+ *
+ * @return sampling type
+ */
+ public SamplingType getType() {
+
+ return type;
+
+ }
+
+ /**
+ * Threshold setter.
+ *
+ * @param threshold sampling threshold
+ */
+ public void setThreshold(int threshold) {
+
+ this.threshold = threshold;
+
+ }
+
+ /**
+ * Threshold getter.
+ *
+ * @return sampling threshold
+ */
+ public int getThreshold() {
+
+ return threshold;
+
+ }
+
+ }
+
+ /**
+ * This class provides placeholder for anonymization authorization data
+ *
+ * @author urosj
+ */
+ public class Anonymization {
+
+
+ // ---------------------------------- class fields
+
+
+ private AnonymizationProtocolType protocolType = null;
+ private AnonymizationFieldType fieldType = null;
+ private AnonymizationFunctionType functionType = null;
+ private String[] functionParams = null;
+
+
+
+ // ---------------------------------- constructors
+
+
+ /**
+ * Default constructor
+ */
+ public Anonymization() {
+
+ }
+
+ /**
+ * Constructor to fill al the variables.
+ *
+ * @param protocolType
+ * @param fieldType
+ * @param functionType
+ * @param functionParams
+ */
+ public Anonymization(AnonymizationProtocolType protocolType,
+ AnonymizationFieldType fieldType,
+ AnonymizationFunctionType functionType,
+ String[] functionParams) {
+
+ this.protocolType = protocolType;
+ this.fieldType = fieldType;
+ this.functionType = functionType;
+ this.functionParams = functionParams;
+
+ }
+
+ // ---------------------------------- public methods
+
+
+ /**
+ * Protocol type setter.
+ *
+ * @param type protocol type
+ */
+ public void setProtocolType(AnonymizationProtocolType protocolType) {
+
+ this.protocolType = protocolType;
+
+ }
+
+ /**
+ * Protocol type getter.
+ *
+ * @return protocol type
+ */
+ public AnonymizationProtocolType getProtocolType() {
+
+ return protocolType;
+
+ }
+
+ /**
+ * Field type setter.
+ *
+ * @param type field type
+ */
+ public void setFieldType(AnonymizationFieldType fieldType) {
+
+ this.fieldType = fieldType;
+
+ }
+
+ /**
+ * Field type getter.
+ *
+ * @return field type
+ */
+ public AnonymizationFieldType getFieldType() {
+
+ return fieldType;
+
+ }
+
+ /**
+ * Function type setter.
+ *
+ * @param type function type
+ */
+ public void setFunctionType(AnonymizationFunctionType functionType) {
+
+ this.functionType = functionType;
+
+ }
+
+ /**
+ * Function type getter.
+ *
+ * @return function type
+ */
+ public AnonymizationFunctionType getFunctionType() {
+
+ return functionType;
+
+ }
+
+ /**
+ * Function params setter.
+ *
+ * @param params function params
+ */
+ public void setFunctionParams(String[] functionParams) {
+
+ this.functionParams = functionParams;
+
+ }
+
+ /**
+ * Function params getter.
+ *
+ * @return function params
+ */
+ public String[] getFunctionParams() {
+
+ return functionParams;
+
+ }
+
+ }
+
// ---------------------------------- class fields
/**
- * SqlManager holder.
+ * SqlManager holder and all the required connections params.
*/
private SqlManager sqlManager = null;
+ private String sqlHost = null;
+ private String sqlPort = null;
+ private String sqlDbName = null;
+ private String sqlUsername = null;
+ private String sqlPassword = null;
+
+ /**
+ * All the credential information
+ */
+ private String username = null;
+ private String password = null;
+ private String role = null;
+ private String[] headerFilters = null;
+ private String[] payloadFilters = null;
+ private Sampling[] samplings = null;
+ private Anonymization[] anonymizations = null;
+
// ---------------------------------- constructors
@@ -48,11 +812,22 @@
* Set SQL manager.
*
* @param sqlManager
+ * @param sqlHost
+ * @param sqlPort
+ * @param sqlDbName
+ * @param sqlUsername
+ * @param sqlPassword
*/
- public Credentials(SqlManager sqlManager) {
+ public Credentials(SqlManager sqlManager,
+ String sqlHost, String sqlPort, String sqlDbName,
+ String sqlUsername, String sqlPassword) {
this.sqlManager = sqlManager;
-
+ this.sqlHost = sqlHost;
+ this.sqlPort = sqlPort;
+ this.sqlDbName = sqlDbName;
+ this.sqlUsername = sqlUsername;
+ this.sqlPassword = sqlPassword;
}
@@ -73,9 +848,214 @@
public Credentials getCredentials(String username, String password)
throws SQLException, CredentialsException {
- return null;
- //TODO
+ Credentials retCreds = new Credentials();
+ Connection conn = null;
+ PreparedStatement pstmt = null;
+ ResultSet rst = null;
+
+ try {
+
+ conn = sqlManager.getConnection(sqlHost, sqlPort, sqlDbName,
+ sqlUsername, sqlPassword);
+
+ // Retrieve role for the given user,
+ // if the given (username, password) pair matches one in DB
+ pstmt = conn.prepareStatement(
+ "SELECT ur.role FROM user AS u, user_role AS ur WHERE"
+ + " u.username=? AND u.password=? AND
u.username=ur.username");
+ pstmt.setString(1, username);
+ pstmt.setString(2, password);
+ rst = pstmt.executeQuery();
+
+ if (! rst.next())
+ throw new CredentialsException(
+ "Authentication failure (invalid"
+ + " username and/or password)");
+
+ retCreds.username = username;
+ retCreds.password = password;
+ retCreds.role = rst.getString(1);
+
+ // Retrieve all the header filters
+ pstmt.close();
+ pstmt = conn.prepareStatement(
+ "SELECT hf.value FROM role_authorization AS ra,"
+ + " authorization AS a, authorization_type AS at,"
+ + " header_filter AS hf WHERE"
+ + " at.name='" + AuthorizationType.HEADER_FILTER.getType()
+ + "' AND ra.role=? AND ra.authorization_id=a.id"
+ + " AND a.authorization_type_id=at.id"
+ + " AND a.authorization_ref_id=hf.id");
+ pstmt.setString(1, retCreds.role);
+ rst.close();
+ rst = pstmt.executeQuery();
+
+ rst.last();
+ int nRows = rst.getRow();
+ retCreds.headerFilters = new String[nRows];
+ rst.beforeFirst();
+ int i = 0;
+ while (rst.next()) retCreds.headerFilters[i++] =
rst.getString(1);
+
+ // Retrieve all the payload filters
+ pstmt.close();
+ pstmt = conn.prepareStatement(
+ "SELECT pf.value FROM role_authorization AS ra,"
+ + " authorization AS a, authorization_type AS at,"
+ + " payload_filter AS pf WHERE"
+ + " at.name='" + AuthorizationType.PAYLOAD_FILTER.getType()
+ + "' AND ra.role=? AND ra.authorization_id=a.id"
+ + " AND a.authorization_type_id=at.id"
+ + " AND a.authorization_ref_id=pf.id");
+ pstmt.setString(1, retCreds.role);
+ rst.close();
+ rst = pstmt.executeQuery();
+
+ rst.last();
+ nRows = rst.getRow();
+ retCreds.payloadFilters = new String[nRows];
+ rst.beforeFirst();
+ i = 0;
+ while (rst.next()) retCreds.payloadFilters[i++] =
rst.getString(1);
+
+ // Retrieve all the sampling params
+ pstmt.close();
+ pstmt = conn.prepareStatement(
+ "SELECT s.id,s.type,s.threshold FROM role_authorization AS
ra,"
+ + " authorization AS a, authorization_type AS at,"
+ + " sampling AS s WHERE"
+ + " at.name='" + AuthorizationType.SAMPLING.getType()
+ + "' AND ra.role=? AND ra.authorization_id=a.id"
+ + " AND a.authorization_type_id=at.id"
+ + " AND a.authorization_ref_id=s.id");
+ pstmt.setString(1, retCreds.role);
+ rst.close();
+ rst = pstmt.executeQuery();
+
+ rst.last();
+ nRows = rst.getRow();
+ retCreds.samplings = new Sampling[nRows];
+ rst.beforeFirst();
+ i = 0;
+ while (rst.next()) {
+
+ SamplingType st =
SamplingType.getTypeByName(rst.getString(2));
+ if (st == null)
+ throw new CredentialsException(
+ "Unknown sampling type (" + rst.getString(2)
+ + ") with id " + rst.getInt(1));
+
+ retCreds.samplings[i++] = new Sampling(st, rst.getInt(3));
+
+ }
+
+ // Retrieve all the anonymization params
+ pstmt.close();
+ pstmt = conn.prepareStatement(
+ "SELECT an.id,an.proto,an.field,an.func,p.id,p.value"
+ + " FROM role_authorization AS ra,"
+ + " authorization AS a, authorization_type AS at,"
+ + " anonymization AS an LEFT JOIN param AS p ON"
+ + " an.id=p.authorization_ref_id LEFT JOIN"
+ + " authorization_type AS at2 ON"
+ + " p.authorization_type_id=at2.id WHERE"
+ + " at.name='" + AuthorizationType.ANONYMIZATION.getType()
+ + "' AND ra.role=? AND ra.authorization_id=a.id"
+ + " AND a.authorization_type_id=at.id"
+ + " AND a.authorization_ref_id=an.id"
+ + " ORDER BY an.id, p.idx");
+ pstmt.setString(1, retCreds.role);
+ rst.close();
+ rst = pstmt.executeQuery();
+
+ List<Anonymization> anonsList = new ArrayList<Anonymization>();
+ List<String> paramList = null;
+ Anonymization curAnon = null;
+ int prevAnonId = 0;
+ int curAnonId;
+ while (rst.next()) {
+
+ curAnonId = rst.getInt(1);
+ if (curAnonId != prevAnonId) {
+
+ if (paramList != null && curAnon != null) {
+
+ curAnon.setFunctionParams(
+ paramList.toArray(new String[paramList.size()]));
+ paramList.clear();
+ anonsList.add(curAnon);
+
+ }
+
+ curAnon = new Anonymization();
+
+ AnonymizationProtocolType apt =
+ AnonymizationProtocolType.getTypeByName(
+ rst.getString(2));
+ if (apt == null)
+ throw new CredentialsException(
+ "Invalid protocol type ("
+ + rst.getString(2)
+ + ") with anonymization id "
+ + curAnonId);
+ curAnon.setProtocolType(apt);
+
+ AnonymizationFieldType afit =
+ AnonymizationFieldType.getTypeByName(
+ rst.getString(3));
+ if (afit == null)
+ throw new CredentialsException(
+ "Invalid protocol field ("
+ + rst.getString(3)
+ + ") with anonymization id "
+ + curAnonId);
+ curAnon.setFieldType(afit);
+
+ AnonymizationFunctionType afut =
+ AnonymizationFunctionType.getTypeByName(
+ rst.getString(4));
+ if (afut == null)
+ throw new CredentialsException(
+ "Invalid protocol function ("
+ + rst.getString(4)
+ + ") with anonymization id "
+ + curAnonId);
+ curAnon.setFunctionType(afut);
+
+ }
+
+ if (rst.getInt(5) != 0) paramList.add(rst.getString(6));
+
+ prevAnonId = curAnonId;
+
+
+ }
+
+ if (paramList != null && curAnon != null) {
+
+ curAnon.setFunctionParams(
+ paramList.toArray(new String[paramList.size()]));
+ anonsList.add(curAnon);
+
+ }
+
+ retCreds.anonymizations =
+ anonsList.toArray(new Anonymization[anonsList.size()]);
+
+ } finally {
+ if (rst != null) {
+ rst.close();
+ }
+ if (pstmt != null) {
+ pstmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ return retCreds;
+
}
Modified:
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security/CredentialsException.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security/CredentialsException.java
2007-01-10 21:18:18 UTC (rev 1902)
+++
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security/CredentialsException.java
2007-01-11 23:54:25 UTC (rev 1903)
@@ -36,7 +36,31 @@
super(message);
}
- //TODO (other constructors)
+
+ /**
+ * Constructs a new exception with the specified detail message and
cause.
+ *
+ * @param message
+ * @param cause
+ */
+ public CredentialsException(String message, Throwable cause) {
+
+ super(message, cause);
+
+ }
+
+ /**
+ * Constructs a new exception with the specified cause and a detail
message
+ * of (cause==null ? null : cause.toString()) (which typically contains
the
+ * class and detail message of cause).
+ *
+ * @param cause
+ */
+ public CredentialsException(Throwable cause) {
+
+ super(cause);
+
+ }
}
- r1903 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/tracefileCaptureType/security, svnlog, 01/11/2007
Archive powered by MHonArc 2.6.16.