From 36de8ef231f44d65bc065855ea0a3ec2c93e4d07 Mon Sep 17 00:00:00 2001 From: "U-NIH\\konkapv" Date: Thu, 30 May 2013 09:48:12 -0400 Subject: [PATCH] Update Copyright --- .../build-deploy.xml | 580 +-- .../build-stubs.xml | 536 +-- .../build.properties | 23 +- identifiers-namingauthority-gridsvc/build.xml | 1106 +++--- .../dependencies-1.4.xml | 9 + .../dependencies-build.xml | 57 +- .../deploy.properties | 9 + .../dev-build-deploy.xml | 146 +- .../dev-build.xml | 450 +-- .../IdentifiersNAService-security-desc.xml | 10 + ...IdentifiersNAService-security-metadata.xml | 93 +- .../etc/IdentifiersNAService_registration.xml | 10 + .../etc/applicationContext-na.xml | 10 + .../etc/client.properties | 13 +- .../etc/log4j.properties | 9 + .../etc/na.properties | 9 + .../etc/serviceMetadata.xml | 309 +- .../etc/sync-description.xml | 9 + .../ext/target_grid/service_urls.properties | 9 + .../introduce.properties | 9 + .../introduce.xml | 609 +-- identifiers-namingauthority-gridsvc/ivy.xml | 175 +- .../ivysettings.xml | 112 +- .../jndi-config.xml | 10 + .../project.properties | 31 +- .../run-tools.xml | 31 +- .../service.properties | 9 + .../sql/Schema.sql | 8 + .../sql/SchemaTest.sql | 8 + .../util/GridAuthenticationClient.java | 9 + .../client/IdentifiersNAServiceClient.java | 683 ++-- .../IdentifiersNAServiceClientBase.java | 9 + .../common/IdentifiersNAServiceConstants.java | 35 +- .../IdentifiersNAServiceConstantsBase.java | 11 +- .../common/IdentifiersNAServiceI.java | 297 +- .../identifiers/common/IdentifiersNAUtil.java | 487 +-- .../IdentifiersNAServiceConfiguration.java | 9 + .../service/IdentifiersNAServiceImpl.java | 949 ++--- .../service/IdentifiersNAServiceImplBase.java | 9 + .../IdentifiersNAServiceAuthorization.java | 9 + .../IdentifiersNAServiceProviderImpl.java | 163 +- .../IdentifiersNAServiceResource.java | 43 +- .../IdentifiersNAServiceResourceBase.java | 9 + ...tifiersNAServiceResourceConfiguration.java | 11 +- .../IdentifiersNAServiceResourceHome.java | 181 +- .../cagrid_SyncGTS/SyncGTS-security-desc.xml | 10 + .../SyncGTS-security-metadata.xml | 63 +- .../cagrid_SyncGTS/SyncGTS_registration.xml | 70 +- .../cagrid_SyncGTS/introduceDeployment.xml | 10 + .../etc/cagrid_SyncGTS/jndi-config.xml | 10 + .../etc/cagrid_SyncGTS/sync-description.xml | 9 + .../syncgts/WEB-INF/lib/ivy-1.4.xml | 147 +- ...nci.cagrid.identifiers.test.NATestCase.xml | 20 +- ...cagrid.identifiers.test.StressTestCase.xml | 12 +- .../cagrid/identifiers/test/NATestCase.java | 9 + .../nih/nci/cagrid/identifiers/test/Pair.java | 9 + .../identifiers/test/StressTestCase.java | 349 +- .../identifiers/test/StressTestUtil.java | 9 + .../nci/cagrid/identifiers/test/TestName.java | 9 + .../nci/cagrid/identifiers/test/TestUtil.java | 9 + .../test/test.xml | 195 +- .../tools/deploymentValidator.xml | 15 +- .../WEB-INF/applicationContext-na.xml | 10 + .../WEB-INF/applicationContext-properties.xml | 10 + .../WEB-INF/classes/log4j.properties | 35 +- .../WebContent/WEB-INF/na.properties | 63 +- .../WebContent/WEB-INF/web.xml | 112 +- identifiers-namingauthority/build.xml | 10 + .../checkstyle/resources/sun_checks.xml | 10 + .../dependencies-build.xml | 55 +- .../domain/IdentifierData.java | 155 +- .../domain/IdentifierValues.java | 157 +- .../namingauthority/domain/KeyData.java | 137 +- .../namingauthority/domain/KeyValues.java | 175 +- .../domain/NamingAuthorityConfig.java | 79 +- .../namingauthority/na-castor-mapping.xml | 136 +- identifiers-namingauthority/ivy.xml | 117 +- identifiers-namingauthority/ivysettings.xml | 112 +- .../project.properties | 9 + identifiers-namingauthority/sql/Schema.sql | 8 + .../sql/SchemaTest.sql | 8 + .../namingauthority/HttpProcessor.java | 33 +- .../namingauthority/IdentifierGenerator.java | 27 +- .../InvalidIdentifierException.java | 69 +- .../InvalidIdentifierValuesException.java | 67 +- .../MaintainerNamingAuthority.java | 9 + .../namingauthority/NamingAuthority.java | 9 + ...NamingAuthorityConfigurationException.java | 61 +- .../NamingAuthoritySecurityException.java | 61 +- .../namingauthority/SecurityInfo.java | 9 + .../UnexpectedIdentifiersException.java | 61 +- .../namingauthority/dao/AbstractDao.java | 189 +- .../dao/IdentifierMetadataDao.java | 3251 +++++++++-------- .../hibernate/IdentifierMetadata.java | 215 +- .../hibernate/IdentifierValueKey.java | 279 +- .../hibernate/URIUserType.java | 225 +- .../http/HttpProcessorImpl.java | 651 ++-- .../namingauthority/http/HttpServer.java | 113 +- .../impl/IdentifierGeneratorImpl.java | 35 +- .../impl/NamingAuthorityImpl.java | 9 + .../impl/NamingAuthorityService.java | 163 +- .../impl/SecurityInfoImpl.java | 9 + .../serialization/URIFieldHandler.java | 9 + .../namingauthority/util/Constant.java | 9 + .../namingauthority/util/IdentifierUtil.java | 347 +- .../namingauthority/util/Keys.java | 9 + .../namingauthority/util/SecurityUtil.java | 9 + .../namingauthority/util/Tree.java | 9 + .../test/resources/na.test.properties | 63 +- .../test-applicationContext-properties.xml | 10 + .../test/src/log4j.properties | 9 + .../NamingAuthoritySecurityTestCase.java | 973 ++--- .../NamingAuthorityTestCase.java | 949 ++--- .../identifiers/namingauthority/Pair.java | 9 + .../namingauthority/StressTestCase.java | 203 +- .../namingauthority/StressTestUtil.java | 9 + .../identifiers/namingauthority/TestName.java | 9 + .../identifiers/namingauthority/TestUtil.java | 9 + .../hibernate/HibernateMappingTestCase.java | 101 +- ...amingAuthorityIntegrationTestCaseBase.java | 45 +- .../test/NamingAuthorityTestCaseBase.java | 313 +- ...SpringTestApplicationContextConstants.java | 31 +- .../test/TestInstantiationException.java | 55 +- .../util/IdentifierUtilTestCase.java | 247 +- identifiers-namingauthority/test/test.xml | 191 +- identifiers-namingauthority/webapp.xml | 122 +- 126 files changed, 10053 insertions(+), 8898 deletions(-) diff --git a/identifiers-namingauthority-gridsvc/build-deploy.xml b/identifiers-namingauthority-gridsvc/build-deploy.xml index b543658..2fa14f9 100644 --- a/identifiers-namingauthority-gridsvc/build-deploy.xml +++ b/identifiers-namingauthority-gridsvc/build-deploy.xml @@ -1,285 +1,295 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/build-stubs.xml b/identifiers-namingauthority-gridsvc/build-stubs.xml index 4b73936..d661d63 100644 --- a/identifiers-namingauthority-gridsvc/build-stubs.xml +++ b/identifiers-namingauthority-gridsvc/build-stubs.xml @@ -1,263 +1,273 @@ - - - - - - Utility targets for generating invoking various wsdl - processing tools: - - * Porttype composition - * WSDL binding generation - * Java stubs from WSDL - - The targets in this script honor the following parameters: - - flatten: - - - deploy.dir The installation directory. Used to build - the classpath used when invoking this - target. Defaults to $GLOBUS_LOCATION if - set and the current directory if not set. - - source.flatten.dir The directory containing the WSDL file - to process. - - target.flatten.dir The directory to which to write the - processed file. - - wsdl.source The name of the WSDL file to process - - wsdl.target The name of file to which to write the - processed WSDL. - - wsdl.porttype The name of the porttype to process. - - generateBinding: - - - deploy.dir The installation directory. Used to build - the classpath used when invoking this - target. Defaults to $GLOBUS_LOCATION if - set and the current directory if not set. - - source.binding.dir The directory containing the WSDL file - to create a binding for. - - target.binding.dir The directory to which to write the - binding and service WSDL files. - - porttype.wsdl The WSDL file containing the porttype - definition for which to create a binding. - - binding.root The root name to use for the binding - files. The created files will look like - <root>_bindings.wsdl and - <root>_service.wsdl - - binding.protocol The protocol to use when generating the - binding. Defaults to http. - - generateStubs: - - - deploy.dir The installation directory. Used to build - the classpath used when invoking this - target and to find the Java WS Core mapping - file if no other mapping file was - specified. Defaults to $GLOBUS_LOCATION if - set and the current directory if not set. - - mapping.file The namespace to package name mapping file - to use. Defaults to - $deploy.dir/share/globus_wsrf_core/NStoPkg.properties - - server.side If this property is set then server-side - bindings will be emitted. You generally - only need to generate client-side stubs. - - wsdl.tool The class name of the WSDL2Java - tool. Defaults to - org.globus.wsrf.tools.wsdl.WSDL2Java - - wsdl.file The WSDL file for which to generate the stubs - - source.stubs.dir The directory containing the WSDL file. - - target.stubs.dir The directory to which to write the - generated stub code. - - ns.excludes A list of namespace for which stubs should - not be created. The default value for this - property can be found in the build - file. You should generally not change the - default. - - stubs.timeout The timeout to use when generating - stubs. Defaults to three minutes. - - mergePackageMapping: - - - deploy.dir The installation directory. Used to find - the Java WS Core mapping file. Defaults to - $GLOBUS_LOCATION if set and the current - directory if not set. - - mapping.src The full path to the mapping file that is - to be merged. - - mapping.dst The full path to a file to which to write - the result of the merge. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + Utility targets for generating invoking various wsdl + processing tools: + + * Porttype composition + * WSDL binding generation + * Java stubs from WSDL + + The targets in this script honor the following parameters: + + flatten: + + - deploy.dir The installation directory. Used to build + the classpath used when invoking this + target. Defaults to $GLOBUS_LOCATION if + set and the current directory if not set. + - source.flatten.dir The directory containing the WSDL file + to process. + - target.flatten.dir The directory to which to write the + processed file. + - wsdl.source The name of the WSDL file to process + - wsdl.target The name of file to which to write the + processed WSDL. + - wsdl.porttype The name of the porttype to process. + + generateBinding: + + - deploy.dir The installation directory. Used to build + the classpath used when invoking this + target. Defaults to $GLOBUS_LOCATION if + set and the current directory if not set. + - source.binding.dir The directory containing the WSDL file + to create a binding for. + - target.binding.dir The directory to which to write the + binding and service WSDL files. + - porttype.wsdl The WSDL file containing the porttype + definition for which to create a binding. + - binding.root The root name to use for the binding + files. The created files will look like + <root>_bindings.wsdl and + <root>_service.wsdl + - binding.protocol The protocol to use when generating the + binding. Defaults to http. + + generateStubs: + + - deploy.dir The installation directory. Used to build + the classpath used when invoking this + target and to find the Java WS Core mapping + file if no other mapping file was + specified. Defaults to $GLOBUS_LOCATION if + set and the current directory if not set. + - mapping.file The namespace to package name mapping file + to use. Defaults to + $deploy.dir/share/globus_wsrf_core/NStoPkg.properties + - server.side If this property is set then server-side + bindings will be emitted. You generally + only need to generate client-side stubs. + - wsdl.tool The class name of the WSDL2Java + tool. Defaults to + org.globus.wsrf.tools.wsdl.WSDL2Java + - wsdl.file The WSDL file for which to generate the stubs + - source.stubs.dir The directory containing the WSDL file. + - target.stubs.dir The directory to which to write the + generated stub code. + - ns.excludes A list of namespace for which stubs should + not be created. The default value for this + property can be found in the build + file. You should generally not change the + default. + - stubs.timeout The timeout to use when generating + stubs. Defaults to three minutes. + + mergePackageMapping: + + - deploy.dir The installation directory. Used to find + the Java WS Core mapping file. Defaults to + $GLOBUS_LOCATION if set and the current + directory if not set. + - mapping.src The full path to the mapping file that is + to be merged. + - mapping.dst The full path to a file to which to write + the result of the merge. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/build.properties b/identifiers-namingauthority-gridsvc/build.properties index 6d873a2..1dad5a6 100644 --- a/identifiers-namingauthority-gridsvc/build.properties +++ b/identifiers-namingauthority-gridsvc/build.properties @@ -1,7 +1,16 @@ -# tomcat and globus web URLs to download from .. -tomcat.src.url=https://ncisvn.nci.nih.gov/svn/commonlibrary/trunk/techstack-2008/os-independent/apache-tomcat-5.5.20.zip -globus.src.url=http://software.cagrid.org/community-repository/ws-core-enum-4.0.3.zip - -wsrf-war=wsrf-gsid - - +#L +# Copyright Washington University in St. Louis +# Copyright SemanticBits +# Copyright Persistent Systems +# +# Distributed under the OSI-approved BSD 3-Clause License. +# See http://ncip.github.com/gsid/LICENSE.txt for details. +#L + +# tomcat and globus web URLs to download from .. +tomcat.src.url=https://ncisvn.nci.nih.gov/svn/commonlibrary/trunk/techstack-2008/os-independent/apache-tomcat-5.5.20.zip +globus.src.url=http://software.cagrid.org/community-repository/ws-core-enum-4.0.3.zip + +wsrf-war=wsrf-gsid + + diff --git a/identifiers-namingauthority-gridsvc/build.xml b/identifiers-namingauthority-gridsvc/build.xml index 06f854a..1ca3ef2 100644 --- a/identifiers-namingauthority-gridsvc/build.xml +++ b/identifiers-namingauthority-gridsvc/build.xml @@ -1,549 +1,559 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - commit; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Integrating SyncGTS into the GSID Service WAR file... - - - - - - - - - - - - - - - - - Preparing sync-description.xml to point to the right grid: - gtsServiceURI=${gtsServiceURI} - GTSIdentity=${GTSIdentity} - CASubject=${CASubject} - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + commit; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Integrating SyncGTS into the GSID Service WAR file... + + + + + + + + + + + + + + + + + Preparing sync-description.xml to point to the right grid: + gtsServiceURI=${gtsServiceURI} + GTSIdentity=${GTSIdentity} + CASubject=${CASubject} + + + + + + + + + + + \ No newline at end of file diff --git a/identifiers-namingauthority-gridsvc/dependencies-1.4.xml b/identifiers-namingauthority-gridsvc/dependencies-1.4.xml index 446d5aa..bffd960 100644 --- a/identifiers-namingauthority-gridsvc/dependencies-1.4.xml +++ b/identifiers-namingauthority-gridsvc/dependencies-1.4.xml @@ -1,3 +1,12 @@ + + diff --git a/identifiers-namingauthority-gridsvc/dependencies-build.xml b/identifiers-namingauthority-gridsvc/dependencies-build.xml index 1aa6613..70278e9 100644 --- a/identifiers-namingauthority-gridsvc/dependencies-build.xml +++ b/identifiers-namingauthority-gridsvc/dependencies-build.xml @@ -1,24 +1,33 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/deploy.properties b/identifiers-namingauthority-gridsvc/deploy.properties index 8f1e494..010e8a0 100644 --- a/identifiers-namingauthority-gridsvc/deploy.properties +++ b/identifiers-namingauthority-gridsvc/deploy.properties @@ -1,3 +1,12 @@ +#L +# Copyright Washington University in St. Louis +# Copyright SemanticBits +# Copyright Persistent Systems +# +# Distributed under the OSI-approved BSD 3-Clause License. +# See http://ncip.github.com/gsid/LICENSE.txt for details. +#L + service.deployment.prefix=cagrid index.service.url=http://index.training.cagrid.org:8080/wsrf/services/DefaultIndexService perform.index.service.registration=true diff --git a/identifiers-namingauthority-gridsvc/dev-build-deploy.xml b/identifiers-namingauthority-gridsvc/dev-build-deploy.xml index fb9bd6c..1d06fa1 100644 --- a/identifiers-namingauthority-gridsvc/dev-build-deploy.xml +++ b/identifiers-namingauthority-gridsvc/dev-build-deploy.xml @@ -1,68 +1,78 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/dev-build.xml b/identifiers-namingauthority-gridsvc/dev-build.xml index aac3ca7..bc2599a 100644 --- a/identifiers-namingauthority-gridsvc/dev-build.xml +++ b/identifiers-namingauthority-gridsvc/dev-build.xml @@ -1,220 +1,230 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService-security-desc.xml b/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService-security-desc.xml index b4eab4d..c88fb2c 100644 --- a/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService-security-desc.xml +++ b/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService-security-desc.xml @@ -1,4 +1,14 @@ + + + diff --git a/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService-security-metadata.xml b/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService-security-metadata.xml index 233c576..c4831da 100644 --- a/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService-security-metadata.xml +++ b/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService-security-metadata.xml @@ -1,42 +1,51 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService_registration.xml b/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService_registration.xml index 822b7df..35b97b8 100644 --- a/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService_registration.xml +++ b/identifiers-namingauthority-gridsvc/etc/IdentifiersNAService_registration.xml @@ -1,4 +1,14 @@ + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/etc/sync-description.xml b/identifiers-namingauthority-gridsvc/etc/sync-description.xml index bec826b..33872dd 100644 --- a/identifiers-namingauthority-gridsvc/etc/sync-description.xml +++ b/identifiers-namingauthority-gridsvc/etc/sync-description.xml @@ -1,3 +1,12 @@ + + @gtsServiceURI@ diff --git a/identifiers-namingauthority-gridsvc/ext/target_grid/service_urls.properties b/identifiers-namingauthority-gridsvc/ext/target_grid/service_urls.properties index de4c25e..8e89e1c 100644 --- a/identifiers-namingauthority-gridsvc/ext/target_grid/service_urls.properties +++ b/identifiers-namingauthority-gridsvc/ext/target_grid/service_urls.properties @@ -1,3 +1,12 @@ +#L +# Copyright Washington University in St. Louis +# Copyright SemanticBits +# Copyright Persistent Systems +# +# Distributed under the OSI-approved BSD 3-Clause License. +# See http://ncip.github.com/gsid/LICENSE.txt for details. +#L + cagrid.master.index.service.url=http://index.training.cagrid.org:8080/wsrf/services/DefaultIndexService cagrid.master.cadsr.data.service.url=http://cadsr-dataservice.nci.nih.gov:80/wsrf/services/cagrid/CaDSRDataService cagrid.master.mms.service.url=http://mms.training.cagrid.org:8080/wsrf/services/cagrid/MetadataModelService diff --git a/identifiers-namingauthority-gridsvc/introduce.properties b/identifiers-namingauthority-gridsvc/introduce.properties index 2f91069..0f8ac93 100644 --- a/identifiers-namingauthority-gridsvc/introduce.properties +++ b/identifiers-namingauthority-gridsvc/introduce.properties @@ -1,3 +1,12 @@ +#L +# Copyright Washington University in St. Louis +# Copyright SemanticBits +# Copyright Persistent Systems +# +# Distributed under the OSI-approved BSD 3-Clause License. +# See http://ncip.github.com/gsid/LICENSE.txt for details. +#L + #Introduce Properties #Thu Mar 03 09:52:02 EST 2011 introduce.skeleton.services.list=IdentifiersNAService diff --git a/identifiers-namingauthority-gridsvc/introduce.xml b/identifiers-namingauthority-gridsvc/introduce.xml index a61d866..be160f5 100644 --- a/identifiers-namingauthority-gridsvc/introduce.xml +++ b/identifiers-namingauthority-gridsvc/introduce.xml @@ -1,300 +1,309 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - None - - - - - - - - None - - - - - - - - None - - - - - - - - None - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Custom - - Privacy - - System - No - - - - - - - - - - - - - - - - - - - Custom - - Privacy - - System - No - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Custom - - Privacy - - System - No - - - - - - - - - - - - - - - - - - - - - - The Naming Authority service enables users to maintain and resolve identifiers in the grid - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + None + + + + + + + + None + + + + + + + + None + + + + + + + + None + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Custom + + Privacy + + System + No + + + + + + + + + + + + + + + + + + + Custom + + Privacy + + System + No + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Custom + + Privacy + + System + No + + + + + + + + + + + + + + + + + + + + + + The Naming Authority service enables users to maintain and resolve identifiers in the grid + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/ivy.xml b/identifiers-namingauthority-gridsvc/ivy.xml index 257f02b..c38df0c 100644 --- a/identifiers-namingauthority-gridsvc/ivy.xml +++ b/identifiers-namingauthority-gridsvc/ivy.xml @@ -1,83 +1,92 @@ - - - - - - - Identifiers Naming Authority Grid Service - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + Identifiers Naming Authority Grid Service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/ivysettings.xml b/identifiers-namingauthority-gridsvc/ivysettings.xml index 07738de..9347dd1 100644 --- a/identifiers-namingauthority-gridsvc/ivysettings.xml +++ b/identifiers-namingauthority-gridsvc/ivysettings.xml @@ -1,51 +1,61 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/jndi-config.xml b/identifiers-namingauthority-gridsvc/jndi-config.xml index 26f889c..caf90e1 100644 --- a/identifiers-namingauthority-gridsvc/jndi-config.xml +++ b/identifiers-namingauthority-gridsvc/jndi-config.xml @@ -1,4 +1,14 @@ + + + diff --git a/identifiers-namingauthority-gridsvc/project.properties b/identifiers-namingauthority-gridsvc/project.properties index 082b8a6..b597106 100644 --- a/identifiers-namingauthority-gridsvc/project.properties +++ b/identifiers-namingauthority-gridsvc/project.properties @@ -1,12 +1,21 @@ -#Mon Sep 21 10:38:42 EDT 2009 -project.version=1.4.01-dev -configure.supported=true - -TARGET_GRID_VERSION=1.3 - -TRAINING_TARGET_GRID=training-${TARGET_GRID_VERSION} -NCI_PROD_TARGET_GRID=nci_prod-${TARGET_GRID_VERSION} -NCI_QA_TARGET_GRID=nci_qa-${TARGET_GRID_VERSION} -NCI_STAGE_TARGET_GRID=nci_stage-${TARGET_GRID_VERSION} - +#L +# Copyright Washington University in St. Louis +# Copyright SemanticBits +# Copyright Persistent Systems +# +# Distributed under the OSI-approved BSD 3-Clause License. +# See http://ncip.github.com/gsid/LICENSE.txt for details. +#L + +#Mon Sep 21 10:38:42 EDT 2009 +project.version=1.4.01-dev +configure.supported=true + +TARGET_GRID_VERSION=1.3 + +TRAINING_TARGET_GRID=training-${TARGET_GRID_VERSION} +NCI_PROD_TARGET_GRID=nci_prod-${TARGET_GRID_VERSION} +NCI_QA_TARGET_GRID=nci_qa-${TARGET_GRID_VERSION} +NCI_STAGE_TARGET_GRID=nci_stage-${TARGET_GRID_VERSION} + TARGET_GRID_LIST=${TRAINING_TARGET_GRID},${NCI_PROD_TARGET_GRID},${NCI_QA_TARGET_GRID},${NCI_STAGE_TARGET_GRID} \ No newline at end of file diff --git a/identifiers-namingauthority-gridsvc/run-tools.xml b/identifiers-namingauthority-gridsvc/run-tools.xml index bc450bb..df9cbf0 100644 --- a/identifiers-namingauthority-gridsvc/run-tools.xml +++ b/identifiers-namingauthority-gridsvc/run-tools.xml @@ -1,11 +1,20 @@ - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/service.properties b/identifiers-namingauthority-gridsvc/service.properties index cac6208..8987257 100644 --- a/identifiers-namingauthority-gridsvc/service.properties +++ b/identifiers-namingauthority-gridsvc/service.properties @@ -1,3 +1,12 @@ +#L +# Copyright Washington University in St. Louis +# Copyright SemanticBits +# Copyright Persistent Systems +# +# Distributed under the OSI-approved BSD 3-Clause License. +# See http://ncip.github.com/gsid/LICENSE.txt for details. +#L + #service deployment properties #Thu Mar 03 09:51:42 EST 2011 naPropertiesFile=na.properties diff --git a/identifiers-namingauthority-gridsvc/sql/Schema.sql b/identifiers-namingauthority-gridsvc/sql/Schema.sql index e94075e..087d6ea 100644 --- a/identifiers-namingauthority-gridsvc/sql/Schema.sql +++ b/identifiers-namingauthority-gridsvc/sql/Schema.sql @@ -1,3 +1,11 @@ +/*L + Copyright Washington University in St. Louis + Copyright SemanticBits + Copyright Persistent Systems + + Distributed under the OSI-approved BSD 3-Clause License. + See http://ncip.github.com/gsid/LICENSE.txt for details. +L*/ DROP TABLE IF EXISTS `identifier_key_values`; DROP TABLE IF EXISTS `identifier_keys`; diff --git a/identifiers-namingauthority-gridsvc/sql/SchemaTest.sql b/identifiers-namingauthority-gridsvc/sql/SchemaTest.sql index 31b7a7d..1304cf1 100644 --- a/identifiers-namingauthority-gridsvc/sql/SchemaTest.sql +++ b/identifiers-namingauthority-gridsvc/sql/SchemaTest.sql @@ -1,3 +1,11 @@ +/*L + Copyright Washington University in St. Louis + Copyright SemanticBits + Copyright Persistent Systems + + Distributed under the OSI-approved BSD 3-Clause License. + See http://ncip.github.com/gsid/LICENSE.txt for details. +L*/ -- -- Table structure for table `identifiers` diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cacoresdk/util/GridAuthenticationClient.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cacoresdk/util/GridAuthenticationClient.java index e291485..d50c4e7 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cacoresdk/util/GridAuthenticationClient.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cacoresdk/util/GridAuthenticationClient.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cacoresdk.util; import gov.nih.nci.cagrid.common.Utils; diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/client/IdentifiersNAServiceClient.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/client/IdentifiersNAServiceClient.java index 0e05b47..a853af1 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/client/IdentifiersNAServiceClient.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/client/IdentifiersNAServiceClient.java @@ -1,337 +1,346 @@ -package gov.nih.nci.cagrid.identifiers.client; - -import gov.nih.nci.cagrid.identifiers.common.IdentifiersNAServiceI; - -import java.rmi.RemoteException; - -import namingauthority.Tree; - -import org.apache.axis.client.Stub; -import org.apache.axis.message.addressing.EndpointReferenceType; -import org.apache.axis.types.URI.MalformedURIException; -import org.globus.gsi.GlobusCredential; - -/** - * This class is autogenerated, DO NOT EDIT GENERATED GRID SERVICE ACCESS METHODS. - * - * This client is generated automatically by Introduce to provide a clean unwrapped API to the - * service. - * - * On construction the class instance will contact the remote service and retrieve it's security - * metadata description which it will use to configure the Stub specifically for each method call. - * - * @created by Introduce Toolkit version 1.3 - */ -public class IdentifiersNAServiceClient extends IdentifiersNAServiceClientBase implements IdentifiersNAServiceI { - -// private static final String CLIENT_PROPERTIES = "etc/client.properties"; -// private static final String SYNC_DESCRIPTION = "sync.description"; -// -// protected static Properties props = null; -// static{ -// props=readProperties(); -// } -// -// private static Properties readProperties () { -// Properties properties = new Properties(); -// try { -// properties.load(new FileInputStream(CLIENT_PROPERTIES)); -// } -// catch (Exception e) { -// // TODO: Display appropriate client error -// System.out.println("Exception while accessing " + CLIENT_PROPERTIES + " : " + e.getMessage()); -// //System.exit(-1); -// } -// -// return properties; -// } - - public IdentifiersNAServiceClient(String url) throws MalformedURIException, RemoteException { - this(url,null); - } - - public IdentifiersNAServiceClient(String url, GlobusCredential proxy) throws MalformedURIException, RemoteException { - super(url,proxy); - } - - public IdentifiersNAServiceClient(EndpointReferenceType epr) throws MalformedURIException, RemoteException { - this(epr,null); - } - - public IdentifiersNAServiceClient(EndpointReferenceType epr, GlobusCredential proxy) throws MalformedURIException, RemoteException { - super(epr,proxy); - } - - public static void usage(){ - System.out.println(IdentifiersNAServiceClient.class.getName() + " -url "); - } - -// private static void syncTrust() { -// System.out.println("Synchronize Once..."); -// GridAuthenticationClient.synchronizeOnce( -// props.getProperty(SYNC_DESCRIPTION)); -// System.out.println("Synchronize Complete."); -// } - - - public static void main(String [] args){ - System.out.println("Running the Grid Service Client"); - -// try{ -// if(true){//!(args.length < 2)){ -// if(true){//args[0].equals("-url")){ -// GlobusCredential creds = null; -// try { -// syncTrust(); -// String userId=""; -// String password=""; -// String authenticationServiceURL="https://dorian.training.cagrid.org:8443/wsrf/services/cagrid/Dorian"; -// String dorianURL="https://dorian.training.cagrid.org:8443/wsrf/services/cagrid/Dorian"; -// creds=GridAuthenticationClient.authenticate(dorianURL, authenticationServiceURL, userId, password); -// System.out.println("Using proxy with id= " + creds.getIdentity() + " and lifetime " -// + creds.getTimeLeft()); -// } catch (Exception e1) { -// System.out.println("No proxy file loaded so running with no credentials\n"+e1.getMessage()); -// e1.getStackTrace(); -// } -// -// IdentifiersNAServiceClient client = new IdentifiersNAServiceClient("https://lslr2-vm2.semanticbits.com:8443/wsrf/services/cagrid/IdentifiersNAService",creds); -// client.setAnonymousPrefered(true); -//// client.registerSite("a", "a", "a", "a", "a", "a", "a"); -// //b71d518d-bb01-4135-8bb2-f3423a5b2d4b -// Tree temp=client.getParentHierarchy("0f0fc053-e955-4f04-9fa8-6468f1e86aa3"); -// printTree(temp, ""); -// // System.out.println("The identifier is "+client.registerGSID(null, null)); -// -// } else { -// usage(); -// System.exit(1); -// } -// } else { -// usage(); -// System.exit(1); -// } -// } catch (Exception e) { -// e.printStackTrace(); -// System.exit(1); -// } - } - - private static void printTree(Tree tree,String currentTabber) - { - if(tree!=null) - { - System.out.println(currentTabber+tree.getCurrentIdentifier()); - if(tree.getTree()!=null) - { - for(Tree t:tree.getTree()) - { - printTree(t,currentTabber+"\t"); - } - } - } - } - /****** - * This method is used to get the data associated with an identifier. This method is a non authentication oriented operation. - * @param identifier - * @return Identifier data. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - - /**** - * This method is used to register GSID in to the database of the GSID. This method is an authentication oriented operation. - * @param suggestedIdentifier is an optional parameter (can be null) which is used to register an non existing identifier. If the identifier already exists then new identifier is generated and returned. - * @param parentIdentifiers is an array of identifiers which are already registered and exists in the database. - * @return registered identifier. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - - /***************************** - * This method is used to add an identifier to a site. This method is an authentication oriented operation. The identifier should exists in the database. - * @param identifier is an existing GSID to which you would like to attach your site data. - * @return - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - - /********************************** - * This method is used to generate a batch of identifiers. This method is a non authentication oriented operation. - * @param numOfIdentifiers is the number of identifiers you are requesting for should be between 1 and 100. - * @return array of identifiers. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - - /**************************************** - * This method is used to get the parent hierarchy details about the identifiers. This method is a non authentication oriented operation. - * @param identifier is the GSID for which you would like to get parent hierarchy information. - * @return a tree representing the parent hierarchy. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - */ - - /***************************************** - * This method is used to get the child hierarchy details about the identifiers. - * This method is a non authentication oriented operation. - * @param identifier is the GSID for which you would like to get child hierarchy information. - * @return a tree representing the child hierarchy. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - - /****************************** - * This method is used to register site information related to a globus credential. - * This is an authentication oriented operation. This operation should be executed - * before any other authentication operation for a new globus credential. - * Throws an exception if the globus credentials has already registered a site. - * @param application is the name of the application - * @param applicationURL is the URL of the application - * @param applicationVersion is the version of the application - * @param contactName is the contact of the site. - * @param contactEmail is the email address of the contact of the site. - * @param contactPhone is the phone number of the contact. - * @param organization is the organization of the site. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - - /************************************************** - * This method checks if the identifier exists in the database or not. - * if identifier does not exists returns true else false. - * This is a non authentication oriented operation. - * @param identifier - * @return - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - */ - - public org.oasis.wsrf.properties.GetMultipleResourcePropertiesResponse getMultipleResourceProperties(org.oasis.wsrf.properties.GetMultipleResourceProperties_Element params) throws RemoteException { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"getMultipleResourceProperties"); - return portType.getMultipleResourceProperties(params); - } - } - - public org.oasis.wsrf.properties.GetResourcePropertyResponse getResourceProperty(javax.xml.namespace.QName params) throws RemoteException { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"getResourceProperty"); - return portType.getResourceProperty(params); - } - } - - public org.oasis.wsrf.properties.QueryResourcePropertiesResponse queryResourceProperties(org.oasis.wsrf.properties.QueryResourceProperties_Element params) throws RemoteException { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"queryResourceProperties"); - return portType.queryResourceProperties(params); - } - } - - public namingauthority.IdentifierData resolveIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"resolveIdentifier"); - gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierRequest params = new gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierRequest(); - params.setIdentifier(identifier); - gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierResponse boxedResult = portType.resolveIdentifier(params); - return boxedResult.getIdentifierData(); - } - } - - public java.lang.String registerGSID(java.lang.String suggestedIdentifier,java.lang.String[] parentIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"registerGSID"); - gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDRequest params = new gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDRequest(); - params.setSuggestedIdentifier(suggestedIdentifier); - params.setParentIdentifiers(parentIdentifiers); - gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDResponse boxedResult = portType.registerGSID(params); - return boxedResult.getResponse(); - } - } - - public org.apache.axis.types.URI addSite(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"addSite"); - gov.nih.nci.cagrid.identifiers.stubs.AddSiteRequest params = new gov.nih.nci.cagrid.identifiers.stubs.AddSiteRequest(); - params.setIdentifier(identifier); - gov.nih.nci.cagrid.identifiers.stubs.AddSiteResponse boxedResult = portType.addSite(params); - return boxedResult.getIdentifier(); - } - } - - public java.lang.String[] generateIdentifiers(int numOfIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"generateIdentifiers"); - gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersRequest params = new gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersRequest(); - params.setNumOfIdentifiers(numOfIdentifiers); - gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersResponse boxedResult = portType.generateIdentifiers(params); - return boxedResult.getResponse(); - } - } - - public namingauthority.Tree getParentHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"getParentHierarchy"); - gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyRequest params = new gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyRequest(); - params.setIdentifier(identifier); - gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyResponse boxedResult = portType.getParentHierarchy(params); - return boxedResult.getTree(); - } - } - - public namingauthority.Tree getChildHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"getChildHierarchy"); - gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyRequest params = new gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyRequest(); - params.setIdentifier(identifier); - gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyResponse boxedResult = portType.getChildHierarchy(params); - return boxedResult.getTree(); - } - } - - public void registerSite(java.lang.String application,java.lang.String applicationURL,java.lang.String applicationVersion,java.lang.String contactName,java.lang.String contactEmail,java.lang.String contactPhone,java.lang.String organization) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"registerSite"); - gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteRequest params = new gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteRequest(); - params.setApplication(application); - params.setApplicationURL(applicationURL); - params.setApplicationVersion(applicationVersion); - params.setContactName(contactName); - params.setContactEmail(contactEmail); - params.setContactPhone(contactPhone); - params.setOrganization(organization); - gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteResponse boxedResult = portType.registerSite(params); - } - } - - public boolean validateIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault { - synchronized(portTypeMutex){ - configureStubSecurity((Stub)portType,"validateIdentifier"); - gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierRequest params = new gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierRequest(); - params.setIdentifier(identifier); - gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierResponse boxedResult = portType.validateIdentifier(params); - return boxedResult.isResponse(); - } - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package gov.nih.nci.cagrid.identifiers.client; + +import gov.nih.nci.cagrid.identifiers.common.IdentifiersNAServiceI; + +import java.rmi.RemoteException; + +import namingauthority.Tree; + +import org.apache.axis.client.Stub; +import org.apache.axis.message.addressing.EndpointReferenceType; +import org.apache.axis.types.URI.MalformedURIException; +import org.globus.gsi.GlobusCredential; + +/** + * This class is autogenerated, DO NOT EDIT GENERATED GRID SERVICE ACCESS METHODS. + * + * This client is generated automatically by Introduce to provide a clean unwrapped API to the + * service. + * + * On construction the class instance will contact the remote service and retrieve it's security + * metadata description which it will use to configure the Stub specifically for each method call. + * + * @created by Introduce Toolkit version 1.3 + */ +public class IdentifiersNAServiceClient extends IdentifiersNAServiceClientBase implements IdentifiersNAServiceI { + +// private static final String CLIENT_PROPERTIES = "etc/client.properties"; +// private static final String SYNC_DESCRIPTION = "sync.description"; +// +// protected static Properties props = null; +// static{ +// props=readProperties(); +// } +// +// private static Properties readProperties () { +// Properties properties = new Properties(); +// try { +// properties.load(new FileInputStream(CLIENT_PROPERTIES)); +// } +// catch (Exception e) { +// // TODO: Display appropriate client error +// System.out.println("Exception while accessing " + CLIENT_PROPERTIES + " : " + e.getMessage()); +// //System.exit(-1); +// } +// +// return properties; +// } + + public IdentifiersNAServiceClient(String url) throws MalformedURIException, RemoteException { + this(url,null); + } + + public IdentifiersNAServiceClient(String url, GlobusCredential proxy) throws MalformedURIException, RemoteException { + super(url,proxy); + } + + public IdentifiersNAServiceClient(EndpointReferenceType epr) throws MalformedURIException, RemoteException { + this(epr,null); + } + + public IdentifiersNAServiceClient(EndpointReferenceType epr, GlobusCredential proxy) throws MalformedURIException, RemoteException { + super(epr,proxy); + } + + public static void usage(){ + System.out.println(IdentifiersNAServiceClient.class.getName() + " -url "); + } + +// private static void syncTrust() { +// System.out.println("Synchronize Once..."); +// GridAuthenticationClient.synchronizeOnce( +// props.getProperty(SYNC_DESCRIPTION)); +// System.out.println("Synchronize Complete."); +// } + + + public static void main(String [] args){ + System.out.println("Running the Grid Service Client"); + +// try{ +// if(true){//!(args.length < 2)){ +// if(true){//args[0].equals("-url")){ +// GlobusCredential creds = null; +// try { +// syncTrust(); +// String userId=""; +// String password=""; +// String authenticationServiceURL="https://dorian.training.cagrid.org:8443/wsrf/services/cagrid/Dorian"; +// String dorianURL="https://dorian.training.cagrid.org:8443/wsrf/services/cagrid/Dorian"; +// creds=GridAuthenticationClient.authenticate(dorianURL, authenticationServiceURL, userId, password); +// System.out.println("Using proxy with id= " + creds.getIdentity() + " and lifetime " +// + creds.getTimeLeft()); +// } catch (Exception e1) { +// System.out.println("No proxy file loaded so running with no credentials\n"+e1.getMessage()); +// e1.getStackTrace(); +// } +// +// IdentifiersNAServiceClient client = new IdentifiersNAServiceClient("https://lslr2-vm2.semanticbits.com:8443/wsrf/services/cagrid/IdentifiersNAService",creds); +// client.setAnonymousPrefered(true); +//// client.registerSite("a", "a", "a", "a", "a", "a", "a"); +// //b71d518d-bb01-4135-8bb2-f3423a5b2d4b +// Tree temp=client.getParentHierarchy("0f0fc053-e955-4f04-9fa8-6468f1e86aa3"); +// printTree(temp, ""); +// // System.out.println("The identifier is "+client.registerGSID(null, null)); +// +// } else { +// usage(); +// System.exit(1); +// } +// } else { +// usage(); +// System.exit(1); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// System.exit(1); +// } + } + + private static void printTree(Tree tree,String currentTabber) + { + if(tree!=null) + { + System.out.println(currentTabber+tree.getCurrentIdentifier()); + if(tree.getTree()!=null) + { + for(Tree t:tree.getTree()) + { + printTree(t,currentTabber+"\t"); + } + } + } + } + /****** + * This method is used to get the data associated with an identifier. This method is a non authentication oriented operation. + * @param identifier + * @return Identifier data. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + + /**** + * This method is used to register GSID in to the database of the GSID. This method is an authentication oriented operation. + * @param suggestedIdentifier is an optional parameter (can be null) which is used to register an non existing identifier. If the identifier already exists then new identifier is generated and returned. + * @param parentIdentifiers is an array of identifiers which are already registered and exists in the database. + * @return registered identifier. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + + /***************************** + * This method is used to add an identifier to a site. This method is an authentication oriented operation. The identifier should exists in the database. + * @param identifier is an existing GSID to which you would like to attach your site data. + * @return + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + + /********************************** + * This method is used to generate a batch of identifiers. This method is a non authentication oriented operation. + * @param numOfIdentifiers is the number of identifiers you are requesting for should be between 1 and 100. + * @return array of identifiers. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + + /**************************************** + * This method is used to get the parent hierarchy details about the identifiers. This method is a non authentication oriented operation. + * @param identifier is the GSID for which you would like to get parent hierarchy information. + * @return a tree representing the parent hierarchy. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + */ + + /***************************************** + * This method is used to get the child hierarchy details about the identifiers. + * This method is a non authentication oriented operation. + * @param identifier is the GSID for which you would like to get child hierarchy information. + * @return a tree representing the child hierarchy. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + + /****************************** + * This method is used to register site information related to a globus credential. + * This is an authentication oriented operation. This operation should be executed + * before any other authentication operation for a new globus credential. + * Throws an exception if the globus credentials has already registered a site. + * @param application is the name of the application + * @param applicationURL is the URL of the application + * @param applicationVersion is the version of the application + * @param contactName is the contact of the site. + * @param contactEmail is the email address of the contact of the site. + * @param contactPhone is the phone number of the contact. + * @param organization is the organization of the site. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + + /************************************************** + * This method checks if the identifier exists in the database or not. + * if identifier does not exists returns true else false. + * This is a non authentication oriented operation. + * @param identifier + * @return + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + */ + + public org.oasis.wsrf.properties.GetMultipleResourcePropertiesResponse getMultipleResourceProperties(org.oasis.wsrf.properties.GetMultipleResourceProperties_Element params) throws RemoteException { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"getMultipleResourceProperties"); + return portType.getMultipleResourceProperties(params); + } + } + + public org.oasis.wsrf.properties.GetResourcePropertyResponse getResourceProperty(javax.xml.namespace.QName params) throws RemoteException { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"getResourceProperty"); + return portType.getResourceProperty(params); + } + } + + public org.oasis.wsrf.properties.QueryResourcePropertiesResponse queryResourceProperties(org.oasis.wsrf.properties.QueryResourceProperties_Element params) throws RemoteException { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"queryResourceProperties"); + return portType.queryResourceProperties(params); + } + } + + public namingauthority.IdentifierData resolveIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"resolveIdentifier"); + gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierRequest params = new gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierRequest(); + params.setIdentifier(identifier); + gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierResponse boxedResult = portType.resolveIdentifier(params); + return boxedResult.getIdentifierData(); + } + } + + public java.lang.String registerGSID(java.lang.String suggestedIdentifier,java.lang.String[] parentIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"registerGSID"); + gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDRequest params = new gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDRequest(); + params.setSuggestedIdentifier(suggestedIdentifier); + params.setParentIdentifiers(parentIdentifiers); + gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDResponse boxedResult = portType.registerGSID(params); + return boxedResult.getResponse(); + } + } + + public org.apache.axis.types.URI addSite(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"addSite"); + gov.nih.nci.cagrid.identifiers.stubs.AddSiteRequest params = new gov.nih.nci.cagrid.identifiers.stubs.AddSiteRequest(); + params.setIdentifier(identifier); + gov.nih.nci.cagrid.identifiers.stubs.AddSiteResponse boxedResult = portType.addSite(params); + return boxedResult.getIdentifier(); + } + } + + public java.lang.String[] generateIdentifiers(int numOfIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"generateIdentifiers"); + gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersRequest params = new gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersRequest(); + params.setNumOfIdentifiers(numOfIdentifiers); + gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersResponse boxedResult = portType.generateIdentifiers(params); + return boxedResult.getResponse(); + } + } + + public namingauthority.Tree getParentHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"getParentHierarchy"); + gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyRequest params = new gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyRequest(); + params.setIdentifier(identifier); + gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyResponse boxedResult = portType.getParentHierarchy(params); + return boxedResult.getTree(); + } + } + + public namingauthority.Tree getChildHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"getChildHierarchy"); + gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyRequest params = new gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyRequest(); + params.setIdentifier(identifier); + gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyResponse boxedResult = portType.getChildHierarchy(params); + return boxedResult.getTree(); + } + } + + public void registerSite(java.lang.String application,java.lang.String applicationURL,java.lang.String applicationVersion,java.lang.String contactName,java.lang.String contactEmail,java.lang.String contactPhone,java.lang.String organization) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"registerSite"); + gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteRequest params = new gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteRequest(); + params.setApplication(application); + params.setApplicationURL(applicationURL); + params.setApplicationVersion(applicationVersion); + params.setContactName(contactName); + params.setContactEmail(contactEmail); + params.setContactPhone(contactPhone); + params.setOrganization(organization); + gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteResponse boxedResult = portType.registerSite(params); + } + } + + public boolean validateIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault { + synchronized(portTypeMutex){ + configureStubSecurity((Stub)portType,"validateIdentifier"); + gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierRequest params = new gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierRequest(); + params.setIdentifier(identifier); + gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierResponse boxedResult = portType.validateIdentifier(params); + return boxedResult.isResponse(); + } + } + +} diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/client/IdentifiersNAServiceClientBase.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/client/IdentifiersNAServiceClientBase.java index bd345b7..c7d2eb7 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/client/IdentifiersNAServiceClientBase.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/client/IdentifiersNAServiceClientBase.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.client; import java.io.InputStream; diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceConstants.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceConstants.java index 8ac5457..64bd497 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceConstants.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceConstants.java @@ -1,13 +1,22 @@ -package gov.nih.nci.cagrid.identifiers.common; - -import javax.xml.namespace.QName; - - -/** - * Constants class that extends the introduce managed constants. Developers can add constants to this file. - * - * @created by Introduce Toolkit version 1.3 - */ -public interface IdentifiersNAServiceConstants extends IdentifiersNAServiceConstantsBase { - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package gov.nih.nci.cagrid.identifiers.common; + +import javax.xml.namespace.QName; + + +/** + * Constants class that extends the introduce managed constants. Developers can add constants to this file. + * + * @created by Introduce Toolkit version 1.3 + */ +public interface IdentifiersNAServiceConstants extends IdentifiersNAServiceConstantsBase { + +} diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceConstantsBase.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceConstantsBase.java index 92fd180..4e2e346 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceConstantsBase.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceConstantsBase.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.common; import javax.xml.namespace.QName; @@ -12,6 +21,6 @@ public interface IdentifiersNAServiceConstantsBase { public static final String SERVICE_NS = "http://identifiers.cagrid.nci.nih.gov/IdentifiersNAService"; public static final QName RESOURCE_KEY = new QName(SERVICE_NS, "IdentifiersNAServiceKey"); public static final QName RESOURCE_PROPERTY_SET = new QName(SERVICE_NS, "IdentifiersNAServiceResourceProperties"); - public static final QName SERVICEMETADATA = new QName("gme://caGrid.caBIG/1.0/gov.nih.nci.cagrid.metadata", "ServiceMetadata"); + public static final QName SERVICEMETADATA = new QName("gme://caGrid.caBIG/1.0/gov.nih.nci.cagrid.metadata", "ServiceMetadata"); } diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceI.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceI.java index d3595a6..fabde2a 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceI.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAServiceI.java @@ -1,144 +1,153 @@ -package gov.nih.nci.cagrid.identifiers.common; - -import java.rmi.RemoteException; - -/** - * The Naming Authority service enables users to maintain and resolve identifiers in the grid - * - * This class is autogenerated, DO NOT EDIT. - * - * This interface represents the API which is accessable on the grid service from the client. - * - * @created by Introduce Toolkit version 1.3 - * - */ -public interface IdentifiersNAServiceI { - - public org.oasis.wsrf.properties.GetMultipleResourcePropertiesResponse getMultipleResourceProperties(org.oasis.wsrf.properties.GetMultipleResourceProperties_Element params) throws RemoteException ; - - public org.oasis.wsrf.properties.GetResourcePropertyResponse getResourceProperty(javax.xml.namespace.QName params) throws RemoteException ; - - public org.oasis.wsrf.properties.QueryResourcePropertiesResponse queryResourceProperties(org.oasis.wsrf.properties.QueryResourceProperties_Element params) throws RemoteException ; - - /** - * Returns metadata associated with the provided identifier - * - * @param identifier - * @return The metadata associated with the provided identifier - * @throws NamingAuthorityConfigurationFault - * A configuration error has been detected - * @throws InvalidIdentifierFault - * The provided identifier does not exist - * @throws NamingAuthoritySecurityFault - * User is not authorized to perform the operation - */ - public namingauthority.IdentifierData resolveIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; - - /** - * This operation registers a Specimen Identifier. - * - * @param suggestedIdentifier - * @param parentIdentifiers - * @throws NamingAuthorityConfigurationFault - * - * @throws InvalidIdentifierValuesFault - * - * @throws InvalidIdentifierFault - * - * @throws NamingAuthoritySecurityFault - * - */ - public java.lang.String registerGSID(java.lang.String suggestedIdentifier,java.lang.String[] parentIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; - - /** - * Add the current user as an site that has information about the input specimen identifier. - * - * @param identifier - * @throws NamingAuthorityConfigurationFault - * - * @throws InvalidIdentifierValuesFault - * - * @throws InvalidIdentifierFault - * - * @throws NamingAuthoritySecurityFault - * - */ - public org.apache.axis.types.URI addSite(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; - - /** - * Generates a batch of valid UUIDs. - * - * @param numOfIdentifiers - * @throws NamingAuthorityConfigurationFault - * - * @throws NamingAuthoritySecurityFault - * - */ - public java.lang.String[] generateIdentifiers(int numOfIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; - - /** - * Return the parent hierarchy of the input Specimen Identifier - * - * @param identifier - * @throws NamingAuthorityConfigurationFault - * - * @throws NamingAuthoritySecurityFault - * - * @throws InvalidIdentifierValuesFault - * - * @throws InvalidIdentifierFault - * - */ - public namingauthority.Tree getParentHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault ; - - /** - * Return the parent hierarchy of the input Specimen Identifier. - * - * @param identifier - * @throws NamingAuthorityConfigurationFault - * - * @throws InvalidIdentifierFault - * - * @throws InvalidIdentifierValuesFault - * - * @throws NamingAuthoritySecurityFault - * - */ - public namingauthority.Tree getChildHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; - - /** - * Registers a Site. - * - * @param application - * @param applicationURL - * @param applicationVersion - * @param contactName - * @param contactEmail - * @param contactPhone - * @param organization - * @throws InvalidIdentifierFault - * - * @throws InvalidIdentifierValuesFault - * - * @throws NamingAuthorityConfigurationFault - * - * @throws NamingAuthoritySecurityFault - * - */ - public void registerSite(java.lang.String application,java.lang.String applicationURL,java.lang.String applicationVersion,java.lang.String contactName,java.lang.String contactEmail,java.lang.String contactPhone,java.lang.String organization) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; - - /** - * validates an identifier - * - * @param identifier - * @throws InvalidIdentifierFault - * - * @throws InvalidIdentifierValuesFault - * - * @throws NamingAuthorityConfigurationFault - * - */ - public boolean validateIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault ; - -} - +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package gov.nih.nci.cagrid.identifiers.common; + +import java.rmi.RemoteException; + +/** + * The Naming Authority service enables users to maintain and resolve identifiers in the grid + * + * This class is autogenerated, DO NOT EDIT. + * + * This interface represents the API which is accessable on the grid service from the client. + * + * @created by Introduce Toolkit version 1.3 + * + */ +public interface IdentifiersNAServiceI { + + public org.oasis.wsrf.properties.GetMultipleResourcePropertiesResponse getMultipleResourceProperties(org.oasis.wsrf.properties.GetMultipleResourceProperties_Element params) throws RemoteException ; + + public org.oasis.wsrf.properties.GetResourcePropertyResponse getResourceProperty(javax.xml.namespace.QName params) throws RemoteException ; + + public org.oasis.wsrf.properties.QueryResourcePropertiesResponse queryResourceProperties(org.oasis.wsrf.properties.QueryResourceProperties_Element params) throws RemoteException ; + + /** + * Returns metadata associated with the provided identifier + * + * @param identifier + * @return The metadata associated with the provided identifier + * @throws NamingAuthorityConfigurationFault + * A configuration error has been detected + * @throws InvalidIdentifierFault + * The provided identifier does not exist + * @throws NamingAuthoritySecurityFault + * User is not authorized to perform the operation + */ + public namingauthority.IdentifierData resolveIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; + + /** + * This operation registers a Specimen Identifier. + * + * @param suggestedIdentifier + * @param parentIdentifiers + * @throws NamingAuthorityConfigurationFault + * + * @throws InvalidIdentifierValuesFault + * + * @throws InvalidIdentifierFault + * + * @throws NamingAuthoritySecurityFault + * + */ + public java.lang.String registerGSID(java.lang.String suggestedIdentifier,java.lang.String[] parentIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; + + /** + * Add the current user as an site that has information about the input specimen identifier. + * + * @param identifier + * @throws NamingAuthorityConfigurationFault + * + * @throws InvalidIdentifierValuesFault + * + * @throws InvalidIdentifierFault + * + * @throws NamingAuthoritySecurityFault + * + */ + public org.apache.axis.types.URI addSite(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; + + /** + * Generates a batch of valid UUIDs. + * + * @param numOfIdentifiers + * @throws NamingAuthorityConfigurationFault + * + * @throws NamingAuthoritySecurityFault + * + */ + public java.lang.String[] generateIdentifiers(int numOfIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; + + /** + * Return the parent hierarchy of the input Specimen Identifier + * + * @param identifier + * @throws NamingAuthorityConfigurationFault + * + * @throws NamingAuthoritySecurityFault + * + * @throws InvalidIdentifierValuesFault + * + * @throws InvalidIdentifierFault + * + */ + public namingauthority.Tree getParentHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault ; + + /** + * Return the parent hierarchy of the input Specimen Identifier. + * + * @param identifier + * @throws NamingAuthorityConfigurationFault + * + * @throws InvalidIdentifierFault + * + * @throws InvalidIdentifierValuesFault + * + * @throws NamingAuthoritySecurityFault + * + */ + public namingauthority.Tree getChildHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; + + /** + * Registers a Site. + * + * @param application + * @param applicationURL + * @param applicationVersion + * @param contactName + * @param contactEmail + * @param contactPhone + * @param organization + * @throws InvalidIdentifierFault + * + * @throws InvalidIdentifierValuesFault + * + * @throws NamingAuthorityConfigurationFault + * + * @throws NamingAuthoritySecurityFault + * + */ + public void registerSite(java.lang.String application,java.lang.String applicationURL,java.lang.String applicationVersion,java.lang.String contactName,java.lang.String contactEmail,java.lang.String contactPhone,java.lang.String organization) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault ; + + /** + * validates an identifier + * + * @param identifier + * @throws InvalidIdentifierFault + * + * @throws InvalidIdentifierValuesFault + * + * @throws NamingAuthorityConfigurationFault + * + */ + public boolean validateIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault ; + +} + diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAUtil.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAUtil.java index 17f94a1..790f392 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAUtil.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/common/IdentifiersNAUtil.java @@ -1,239 +1,248 @@ -package gov.nih.nci.cagrid.identifiers.common; - -import gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault; -import gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault; -import gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault; -import gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault; - -import java.net.URISyntaxException; -import java.util.Arrays; - -import junit.framework.Assert; - -import namingauthority.IdentifierData; -import namingauthority.KeyNameData; - -import org.apache.axis.types.URI.MalformedURIException; -import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; -import org.cagrid.identifiers.namingauthority.InvalidIdentifierValuesException; -import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; -import org.cagrid.identifiers.namingauthority.NamingAuthoritySecurityException; -import org.cagrid.identifiers.namingauthority.util.IdentifierUtil; - -public class IdentifiersNAUtil { - - public static org.cagrid.identifiers.namingauthority.domain.IdentifierData map( - namingauthority.IdentifierData identifierData) throws URISyntaxException { - - if (identifierData == null) - return null; - - org.cagrid.identifiers.namingauthority.domain.IdentifierData ivs = - new org.cagrid.identifiers.namingauthority.domain.IdentifierData(); - - if (identifierData.getKeyNameData() != null) { - for( namingauthority.KeyNameData kd : identifierData.getKeyNameData() ) { - ivs.put(kd.getKeyName(), map(kd)); - } - } - - return ivs; - } - - public static org.cagrid.identifiers.namingauthority.domain.IdentifierValues map( - namingauthority.IdentifierValues identifierKeyValues) throws URISyntaxException { - - if (identifierKeyValues == null) - return null; - - org.cagrid.identifiers.namingauthority.domain.IdentifierValues ivs = - new org.cagrid.identifiers.namingauthority.domain.IdentifierValues(); - - if (identifierKeyValues.getKeyNameValues() != null) { - for( namingauthority.KeyNameValues kv : identifierKeyValues.getKeyNameValues() ) { - ivs.put(kv.getKeyName(), map(kv)); - } - } - - return ivs; - } - - public static org.cagrid.identifiers.namingauthority.domain.KeyData map( - namingauthority.KeyNameData kd) throws URISyntaxException { - - if (kd == null || kd.getKeyData() == null) - return null; - - java.net.URI policyReference = null; - if (kd.getKeyData().getPolicyIdentifier() != null) - policyReference = new java.net.URI(kd.getKeyData().getPolicyIdentifier().toString()); - - return new org.cagrid.identifiers.namingauthority.domain.KeyData( - policyReference, kd.getKeyData().getValue()); - } - - public static org.cagrid.identifiers.namingauthority.domain.KeyValues map( - namingauthority.KeyNameValues kv) throws URISyntaxException { - - if (kv == null || kv.getKeyValues() == null) { - return null; - } - - return new org.cagrid.identifiers.namingauthority.domain.KeyValues( - kv.getKeyValues().getValue()); - } - - public static namingauthority.KeyNameData map( String keyName, - org.cagrid.identifiers.namingauthority.domain.KeyData kd) - throws - URISyntaxException, - MalformedURIException { - - if (kd == null) - return null; - - org.apache.axis.types.URI readWriteIdentifier = null; - if (kd.getPolicyIdentifier() != null) { - readWriteIdentifier = new org.apache.axis.types.URI(kd.getPolicyIdentifier().normalize().toString()); - } - - namingauthority.KeyData outKd = new namingauthority.KeyData(); - outKd.setPolicyIdentifier(readWriteIdentifier); - outKd.setValue(kd.getValuesAsArray()); - - return new namingauthority.KeyNameData(outKd, keyName); - } - - public static namingauthority.IdentifierData map( - org.cagrid.identifiers.namingauthority.domain.IdentifierData identifierValues) - throws - MalformedURIException, - URISyntaxException { - - if (identifierValues == null) { - return null; - } - - String[] keys = identifierValues.getKeys(); - namingauthority.KeyNameData[] kdArr = new namingauthority.KeyNameData[ keys.length ]; - for( int i=0; i < kdArr.length; i++) { - kdArr[i] = map(keys[i], identifierValues.getValues(keys[i])); - } - - return new namingauthority.IdentifierData( kdArr ); - } - - public static InvalidIdentifierFault map(InvalidIdentifierException e) { - InvalidIdentifierFault out = new InvalidIdentifierFault(); - out.setFaultString(e.getMessage()); - out.setFaultDetailString(IdentifierUtil.getStackTrace(e)); - return out; - } - - public static NamingAuthorityConfigurationFault map(NamingAuthorityConfigurationException e) { - NamingAuthorityConfigurationFault out = new NamingAuthorityConfigurationFault(); - out.setFaultString(e.getMessage()); - out.setFaultDetailString(IdentifierUtil.getStackTrace(e)); - return out; - } - - public static InvalidIdentifierValuesFault map(InvalidIdentifierValuesException e) { - InvalidIdentifierValuesFault out = new InvalidIdentifierValuesFault(); - out.setFaultString(e.getMessage()); - out.setFaultDetailString(IdentifierUtil.getStackTrace(e)); - return out; - } - - public static NamingAuthoritySecurityFault map(NamingAuthoritySecurityException e) { - NamingAuthoritySecurityFault out = new NamingAuthoritySecurityFault(); - out.setFaultString(e.getMessage()); - out.setFaultDetailString(IdentifierUtil.getStackTrace(e)); - return out; - } - - public static void assertEquals( IdentifierData values1, IdentifierData values2 ) { - IdentifiersNAUtil.assertEquals( values1.getKeyNameData(), values2.getKeyNameData() ); - } - -// public static void assertEquals(KeyNameValues[] tvs1, KeyNameValues[] tvs2) { -// -// // Make sure the Keys match -// if (!Arrays.equals(getSortedKeys(tvs1), getSortedKeys(tvs2))) { -// Assert.fail("keys are not the same"); -// } -// -// for( KeyNameValues tv : tvs1 ) { -// String[] values = null; -// if (tv.getKeyValues() != null && tv.getKeyValues().getValues() != null) { -// values = tv.getKeyValues().getValues().getValue(); -// } -// IdentifiersNAUtil.assertEquals(tvs2, tv.getKeyName(), values); -// } -// } - - public static void assertEquals(KeyNameData[] tvs1, KeyNameData[] tvs2) { - - // Make sure the Keys match - if (!Arrays.equals(getSortedKeys(tvs1), getSortedKeys(tvs2))) { - Assert.fail("keys are not the same"); - } - - for( KeyNameData tv : tvs1 ) { - String[] values = null; - if (tv.getKeyData() != null) { - values = tv.getKeyData().getValue(); - } - IdentifiersNAUtil.assertEquals(tvs2, tv.getKeyName(), values); - } - } - -// private static String[] getSortedKeys(KeyNameValues[] tvs) { -// String[]keys = new String[ tvs.length ]; -// for(int i=0; i < tvs.length; i++) { -// keys[i] = tvs[i].getKeyName(); -// } -// -// Arrays.sort(keys); -// return keys; -// } - - private static String[] getSortedKeys(KeyNameData[] tvs) { - String[]keys = new String[ tvs.length ]; - for(int i=0; i < tvs.length; i++) { - keys[i] = tvs[i].getKeyName(); - } - - Arrays.sort(keys); - return keys; - } - -// private static void assertEquals(KeyNameValues[] tvs, String Key, String[] values) { -// for( KeyNameValues tv : tvs ) { -// if (tv.getKeyName().equals(Key)) { -// String[] myValues = null; -// if (tv.getKeyValues() != null && tv.getKeyValues().getValues() != null) { -// myValues = tv.getKeyValues().getValues().getValue(); -// } -// -// Arrays.sort(values); -// Arrays.sort(myValues); -// Assert.assertEquals("values are not the same", true, Arrays.equals(values, myValues)); -// } -// } -// } - - private static void assertEquals(KeyNameData[] tvs, String Key, String[] values) { - for( KeyNameData tv : tvs ) { - if (tv.getKeyName().equals(Key)) { - String[] myValues = null; - if (tv.getKeyData() != null) { - myValues = tv.getKeyData().getValue(); - } - - Arrays.sort(values); - Arrays.sort(myValues); - Assert.assertEquals("values are not the same", true, Arrays.equals(values, myValues)); - } - } - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package gov.nih.nci.cagrid.identifiers.common; + +import gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault; +import gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault; +import gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault; +import gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault; + +import java.net.URISyntaxException; +import java.util.Arrays; + +import junit.framework.Assert; + +import namingauthority.IdentifierData; +import namingauthority.KeyNameData; + +import org.apache.axis.types.URI.MalformedURIException; +import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; +import org.cagrid.identifiers.namingauthority.InvalidIdentifierValuesException; +import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; +import org.cagrid.identifiers.namingauthority.NamingAuthoritySecurityException; +import org.cagrid.identifiers.namingauthority.util.IdentifierUtil; + +public class IdentifiersNAUtil { + + public static org.cagrid.identifiers.namingauthority.domain.IdentifierData map( + namingauthority.IdentifierData identifierData) throws URISyntaxException { + + if (identifierData == null) + return null; + + org.cagrid.identifiers.namingauthority.domain.IdentifierData ivs = + new org.cagrid.identifiers.namingauthority.domain.IdentifierData(); + + if (identifierData.getKeyNameData() != null) { + for( namingauthority.KeyNameData kd : identifierData.getKeyNameData() ) { + ivs.put(kd.getKeyName(), map(kd)); + } + } + + return ivs; + } + + public static org.cagrid.identifiers.namingauthority.domain.IdentifierValues map( + namingauthority.IdentifierValues identifierKeyValues) throws URISyntaxException { + + if (identifierKeyValues == null) + return null; + + org.cagrid.identifiers.namingauthority.domain.IdentifierValues ivs = + new org.cagrid.identifiers.namingauthority.domain.IdentifierValues(); + + if (identifierKeyValues.getKeyNameValues() != null) { + for( namingauthority.KeyNameValues kv : identifierKeyValues.getKeyNameValues() ) { + ivs.put(kv.getKeyName(), map(kv)); + } + } + + return ivs; + } + + public static org.cagrid.identifiers.namingauthority.domain.KeyData map( + namingauthority.KeyNameData kd) throws URISyntaxException { + + if (kd == null || kd.getKeyData() == null) + return null; + + java.net.URI policyReference = null; + if (kd.getKeyData().getPolicyIdentifier() != null) + policyReference = new java.net.URI(kd.getKeyData().getPolicyIdentifier().toString()); + + return new org.cagrid.identifiers.namingauthority.domain.KeyData( + policyReference, kd.getKeyData().getValue()); + } + + public static org.cagrid.identifiers.namingauthority.domain.KeyValues map( + namingauthority.KeyNameValues kv) throws URISyntaxException { + + if (kv == null || kv.getKeyValues() == null) { + return null; + } + + return new org.cagrid.identifiers.namingauthority.domain.KeyValues( + kv.getKeyValues().getValue()); + } + + public static namingauthority.KeyNameData map( String keyName, + org.cagrid.identifiers.namingauthority.domain.KeyData kd) + throws + URISyntaxException, + MalformedURIException { + + if (kd == null) + return null; + + org.apache.axis.types.URI readWriteIdentifier = null; + if (kd.getPolicyIdentifier() != null) { + readWriteIdentifier = new org.apache.axis.types.URI(kd.getPolicyIdentifier().normalize().toString()); + } + + namingauthority.KeyData outKd = new namingauthority.KeyData(); + outKd.setPolicyIdentifier(readWriteIdentifier); + outKd.setValue(kd.getValuesAsArray()); + + return new namingauthority.KeyNameData(outKd, keyName); + } + + public static namingauthority.IdentifierData map( + org.cagrid.identifiers.namingauthority.domain.IdentifierData identifierValues) + throws + MalformedURIException, + URISyntaxException { + + if (identifierValues == null) { + return null; + } + + String[] keys = identifierValues.getKeys(); + namingauthority.KeyNameData[] kdArr = new namingauthority.KeyNameData[ keys.length ]; + for( int i=0; i < kdArr.length; i++) { + kdArr[i] = map(keys[i], identifierValues.getValues(keys[i])); + } + + return new namingauthority.IdentifierData( kdArr ); + } + + public static InvalidIdentifierFault map(InvalidIdentifierException e) { + InvalidIdentifierFault out = new InvalidIdentifierFault(); + out.setFaultString(e.getMessage()); + out.setFaultDetailString(IdentifierUtil.getStackTrace(e)); + return out; + } + + public static NamingAuthorityConfigurationFault map(NamingAuthorityConfigurationException e) { + NamingAuthorityConfigurationFault out = new NamingAuthorityConfigurationFault(); + out.setFaultString(e.getMessage()); + out.setFaultDetailString(IdentifierUtil.getStackTrace(e)); + return out; + } + + public static InvalidIdentifierValuesFault map(InvalidIdentifierValuesException e) { + InvalidIdentifierValuesFault out = new InvalidIdentifierValuesFault(); + out.setFaultString(e.getMessage()); + out.setFaultDetailString(IdentifierUtil.getStackTrace(e)); + return out; + } + + public static NamingAuthoritySecurityFault map(NamingAuthoritySecurityException e) { + NamingAuthoritySecurityFault out = new NamingAuthoritySecurityFault(); + out.setFaultString(e.getMessage()); + out.setFaultDetailString(IdentifierUtil.getStackTrace(e)); + return out; + } + + public static void assertEquals( IdentifierData values1, IdentifierData values2 ) { + IdentifiersNAUtil.assertEquals( values1.getKeyNameData(), values2.getKeyNameData() ); + } + +// public static void assertEquals(KeyNameValues[] tvs1, KeyNameValues[] tvs2) { +// +// // Make sure the Keys match +// if (!Arrays.equals(getSortedKeys(tvs1), getSortedKeys(tvs2))) { +// Assert.fail("keys are not the same"); +// } +// +// for( KeyNameValues tv : tvs1 ) { +// String[] values = null; +// if (tv.getKeyValues() != null && tv.getKeyValues().getValues() != null) { +// values = tv.getKeyValues().getValues().getValue(); +// } +// IdentifiersNAUtil.assertEquals(tvs2, tv.getKeyName(), values); +// } +// } + + public static void assertEquals(KeyNameData[] tvs1, KeyNameData[] tvs2) { + + // Make sure the Keys match + if (!Arrays.equals(getSortedKeys(tvs1), getSortedKeys(tvs2))) { + Assert.fail("keys are not the same"); + } + + for( KeyNameData tv : tvs1 ) { + String[] values = null; + if (tv.getKeyData() != null) { + values = tv.getKeyData().getValue(); + } + IdentifiersNAUtil.assertEquals(tvs2, tv.getKeyName(), values); + } + } + +// private static String[] getSortedKeys(KeyNameValues[] tvs) { +// String[]keys = new String[ tvs.length ]; +// for(int i=0; i < tvs.length; i++) { +// keys[i] = tvs[i].getKeyName(); +// } +// +// Arrays.sort(keys); +// return keys; +// } + + private static String[] getSortedKeys(KeyNameData[] tvs) { + String[]keys = new String[ tvs.length ]; + for(int i=0; i < tvs.length; i++) { + keys[i] = tvs[i].getKeyName(); + } + + Arrays.sort(keys); + return keys; + } + +// private static void assertEquals(KeyNameValues[] tvs, String Key, String[] values) { +// for( KeyNameValues tv : tvs ) { +// if (tv.getKeyName().equals(Key)) { +// String[] myValues = null; +// if (tv.getKeyValues() != null && tv.getKeyValues().getValues() != null) { +// myValues = tv.getKeyValues().getValues().getValue(); +// } +// +// Arrays.sort(values); +// Arrays.sort(myValues); +// Assert.assertEquals("values are not the same", true, Arrays.equals(values, myValues)); +// } +// } +// } + + private static void assertEquals(KeyNameData[] tvs, String Key, String[] values) { + for( KeyNameData tv : tvs ) { + if (tv.getKeyName().equals(Key)) { + String[] myValues = null; + if (tv.getKeyData() != null) { + myValues = tv.getKeyData().getValue(); + } + + Arrays.sort(values); + Arrays.sort(myValues); + Assert.assertEquals("values are not the same", true, Arrays.equals(values, myValues)); + } + } + } +} diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceConfiguration.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceConfiguration.java index 87e083d..bc7e9ec 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceConfiguration.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceConfiguration.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.service; import gov.nih.nci.cagrid.introduce.servicetools.ServiceConfiguration; diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceImpl.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceImpl.java index 868ee1c..115e616 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceImpl.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceImpl.java @@ -1,470 +1,479 @@ -package gov.nih.nci.cagrid.identifiers.service; - -import gov.nih.nci.cagrid.identifiers.common.IdentifiersNAUtil; -import gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault; -import gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault; -import gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault; -import gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault; - -import java.net.URI; -import java.net.URISyntaxException; -import java.rmi.RemoteException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.axis.types.URI.MalformedURIException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; -import org.cagrid.identifiers.namingauthority.InvalidIdentifierValuesException; -import org.cagrid.identifiers.namingauthority.MaintainerNamingAuthority; -import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; -import org.cagrid.identifiers.namingauthority.NamingAuthoritySecurityException; -import org.cagrid.identifiers.namingauthority.SecurityInfo; -import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; -import org.cagrid.identifiers.namingauthority.util.Tree; -import org.globus.wsrf.security.SecurityManager; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.beans.factory.xml.XmlBeanFactory; -import org.springframework.core.io.FileSystemResource; - -/** - * The service side implementation class of the IdentifiersNAService, managed by - * Introduce. This mostly just delegates the operations to a Spring-loaded bean - * implementation of the NamingAuthority and does any necessary mapping to/from - * Axis types or arrays to the Naming Authority interface. - * - * @created by Introduce Toolkit version 1.3 - */ -public class IdentifiersNAServiceImpl extends IdentifiersNAServiceImplBase { - - protected static Log LOG = LogFactory.getLog(IdentifiersNAServiceImpl.class.getName()); - protected static final String NA_BEAN_NAME = "NamingAuthority"; - protected MaintainerNamingAuthority namingAuthority = null; - - public IdentifiersNAServiceImpl() throws RemoteException { - super(); - - try { - String naConfigurationFile = getConfiguration().getNaConfigurationFile(); - String naProperties = getConfiguration().getNaPropertiesFile(); - FileSystemResource naConfResource = new FileSystemResource(naConfigurationFile); - FileSystemResource naPropertiesResource = new FileSystemResource(naProperties); - - XmlBeanFactory factory = new XmlBeanFactory(naConfResource); - PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); - cfg.setLocation(naPropertiesResource); - cfg.postProcessBeanFactory(factory); - - this.namingAuthority = (MaintainerNamingAuthority) factory.getBean(NA_BEAN_NAME, - MaintainerNamingAuthority.class); - - } - catch (Exception e) { - String message = "Problem inititializing NamingAuthority while loading configuration:" + e.getMessage(); - LOG.error(message, e); - throw new RemoteException(message, e); - } - } - - /********************** - * creates an identifier - * - * @param identifierData - * @return - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - */ - - /****** - * This method is used to get the data associated with an identifier. This - * method is a non authentication oriented operation. - * - * @param identifier - * @return Identifier data. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - public namingauthority.IdentifierData resolveIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - - try { - LOG.info("resolveIdentifier: USER=========[" + SecurityManager.getManager().getCaller() + "]"); - SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); - return IdentifiersNAUtil.map(namingAuthority.resolveIdentifier(secInfo, URI.create(identifier))); - } - catch (InvalidIdentifierException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (NamingAuthoritySecurityException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (Exception e) { - e.printStackTrace(); - throw new RemoteException(e.toString()); - } - } - - /********** - * This method is used to create keys. - * @param identifier - * @param identifierData - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - */ - - /************* - * This method is used to get the key names of the of an identifier. - * @param identifier - * @return - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - - /************** - * This method is used to get the key data associated with a key for an identifier. - * @param identifier - * @param keyName - * @return - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - */ - - /**** - * This method is used to register GSID in to the database of the GSID. This - * method is an authentication oriented operation. - * - * @param suggestedIdentifier - * is an optional parameter (can be null) which is used to - * register an non existing identifier. If the identifier already - * exists then new identifier is generated and returned. - * @param parentIdentifiers - * is an array of identifiers which are already registered and - * exists in the database. - * @return registered identifier. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - public java.lang.String registerGSID(java.lang.String suggestedIdentifier,java.lang.String[] parentIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - LOG.info("registerGSID: USER=========[" + SecurityManager.getManager().getCaller() + "]"); - SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); - try { - return namingAuthority.registerGSID(secInfo, suggestedIdentifier, parentIdentifiers); - } - catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (InvalidIdentifierException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (NamingAuthoritySecurityException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (InvalidIdentifierValuesException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (Exception e) { - e.printStackTrace(); - throw new RemoteException(e.toString()); - } - } - - /***************************** - * This method is used to add an identifier to a site. This method is an - * authentication oriented operation. The identifier should exists in the - * database. - * - * @param identifier - * is an existing GSID to which you would like to attach your - * site data. - * @return - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - public org.apache.axis.types.URI addSite(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - LOG.info("addSite: USER=========[" + SecurityManager.getManager().getCaller() + "]"); - SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); - try { - namingAuthority.addSite(secInfo, identifier); - } - catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (InvalidIdentifierException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (NamingAuthoritySecurityException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (InvalidIdentifierValuesException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (Exception e) { - e.printStackTrace(); - throw new RemoteException(e.toString()); - } - - return null; - - } - - /********************************** - * This method is used to generate a batch of identifiers. This method is a - * non authentication oriented operation. - * - * @param numOfIdentifiers - * is the number of identifiers you are requesting for should be - * between 1 and 100. - * @return array of identifiers. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - public java.lang.String[] generateIdentifiers(int numOfIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - LOG.info("generateIdentifiers: USER=========[" + SecurityManager.getManager().getCaller() + "]"); - SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); - try { - return namingAuthority.createBatchIdentifiers(secInfo, numOfIdentifiers); - } - catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (InvalidIdentifierException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (NamingAuthoritySecurityException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (InvalidIdentifierValuesException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (Exception e) { - e.printStackTrace(); - throw new RemoteException(e.toString()); - } - - } - - /**************************************** - * This method is used to get the parent hierarchy details about the - * identifiers. This method is a non authentication oriented operation. - * - * @param identifier - * is the GSID for which you would like to get parent hierarchy - * information. - * @return a tree representing the parent hierarchy. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - */ - public namingauthority.Tree getParentHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault { - try { - LOG.info("getParentHierarchy: USER=========[" + SecurityManager.getManager().getCaller() + "]"); - SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); - Tree parents = namingAuthority.getParentHierarchy(secInfo, identifier.toString()); - return convert(parents); - } - catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (InvalidIdentifierException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (NamingAuthoritySecurityException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (Exception e) { - e.printStackTrace(); - throw new RemoteException(e.toString()); - } - - } - - /***************************************** - * This method is used to get the child hierarchy details about the - * identifiers. This method is a non authentication oriented operation. - * - * @param identifier - * is the GSID for which you would like to get child hierarchy - * information. - * @return a tree representing the child hierarchy. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - public namingauthority.Tree getChildHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - try { - LOG.info("getChildHierarchy: USER=========[" + SecurityManager.getManager().getCaller() + "]"); - SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); - Tree children = namingAuthority.getChildHierarchy(secInfo, identifier.toString()); - return convert(children); - } - catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (InvalidIdentifierException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (NamingAuthoritySecurityException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (Exception e) { - e.printStackTrace(); - throw new RemoteException(e.toString()); - } - } - - /****************************** - * This method is used to register site information related to a globus - * credential. This is an authentication oriented operation. This operation - * should be executed before any other authentication operation for a new - * globus credential. Throws an exception if the globus credentials has - * already registered a site. - * - * @param application - * is the name of the application - * @param applicationURL - * is the URL of the application - * @param applicationVersion - * is the version of the application - * @param contactName - * is the contact of the site. - * @param contactEmail - * is the email address of the contact of the site. - * @param contactPhone - * is the phone number of the contact. - * @param organization - * is the organization of the site. - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault - */ - public void registerSite(java.lang.String application,java.lang.String applicationURL,java.lang.String applicationVersion,java.lang.String contactName,java.lang.String contactEmail,java.lang.String contactPhone,java.lang.String organization) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - - LOG.info("registerSite: USER=========[" + SecurityManager.getManager().getCaller() + "]"); - try { - SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); - namingAuthority.registerSite(secInfo, application, applicationURL, applicationVersion, contactName, - contactEmail, contactPhone, organization); - } - catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (InvalidIdentifierException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (NamingAuthoritySecurityException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (Exception e) { - e.printStackTrace(); - throw new RemoteException(e.toString()); - } - - } - - /************************************************** - * This method checks if the identifier exists in the database or not. if - * identifier does not exists returns true else false. This is a non - * authentication oriented operation. - * - * @param identifier - * @return - * @throws RemoteException - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault - * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault - */ - public boolean validateIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault { - try { - LOG.info("getChildHierarchy: USER=========[" + SecurityManager.getManager().getCaller() + "]"); - SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); - boolean flag = namingAuthority.validateIdentifier(secInfo, identifier); - return flag; - } - catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (InvalidIdentifierException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (NamingAuthoritySecurityException e) { - e.printStackTrace(); - throw IdentifiersNAUtil.map(e); - } - catch (Exception e) { - e.printStackTrace(); - throw new RemoteException(e.toString()); - } - } - - private namingauthority.Tree convert(Tree tree) { - namingauthority.Tree temp = null; - if (tree != null) { - String identifier = tree.getIdentifier(); - namingauthority.Tree[] mytrees = null; - if (tree.getChildren() != null && tree.getChildren().size() > 0) { - mytrees = new namingauthority.Tree[tree.getChildren().size()]; - for (int i = 0; i < mytrees.length; i++) { - mytrees[i] = convert(tree.getChildren().get(i)); - } - } - temp = new namingauthority.Tree(identifier, mytrees); - } - return temp; - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package gov.nih.nci.cagrid.identifiers.service; + +import gov.nih.nci.cagrid.identifiers.common.IdentifiersNAUtil; +import gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault; +import gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault; +import gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault; +import gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault; + +import java.net.URI; +import java.net.URISyntaxException; +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.axis.types.URI.MalformedURIException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; +import org.cagrid.identifiers.namingauthority.InvalidIdentifierValuesException; +import org.cagrid.identifiers.namingauthority.MaintainerNamingAuthority; +import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; +import org.cagrid.identifiers.namingauthority.NamingAuthoritySecurityException; +import org.cagrid.identifiers.namingauthority.SecurityInfo; +import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; +import org.cagrid.identifiers.namingauthority.util.Tree; +import org.globus.wsrf.security.SecurityManager; +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; +import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.core.io.FileSystemResource; + +/** + * The service side implementation class of the IdentifiersNAService, managed by + * Introduce. This mostly just delegates the operations to a Spring-loaded bean + * implementation of the NamingAuthority and does any necessary mapping to/from + * Axis types or arrays to the Naming Authority interface. + * + * @created by Introduce Toolkit version 1.3 + */ +public class IdentifiersNAServiceImpl extends IdentifiersNAServiceImplBase { + + protected static Log LOG = LogFactory.getLog(IdentifiersNAServiceImpl.class.getName()); + protected static final String NA_BEAN_NAME = "NamingAuthority"; + protected MaintainerNamingAuthority namingAuthority = null; + + public IdentifiersNAServiceImpl() throws RemoteException { + super(); + + try { + String naConfigurationFile = getConfiguration().getNaConfigurationFile(); + String naProperties = getConfiguration().getNaPropertiesFile(); + FileSystemResource naConfResource = new FileSystemResource(naConfigurationFile); + FileSystemResource naPropertiesResource = new FileSystemResource(naProperties); + + XmlBeanFactory factory = new XmlBeanFactory(naConfResource); + PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); + cfg.setLocation(naPropertiesResource); + cfg.postProcessBeanFactory(factory); + + this.namingAuthority = (MaintainerNamingAuthority) factory.getBean(NA_BEAN_NAME, + MaintainerNamingAuthority.class); + + } + catch (Exception e) { + String message = "Problem inititializing NamingAuthority while loading configuration:" + e.getMessage(); + LOG.error(message, e); + throw new RemoteException(message, e); + } + } + + /********************** + * creates an identifier + * + * @param identifierData + * @return + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + */ + + /****** + * This method is used to get the data associated with an identifier. This + * method is a non authentication oriented operation. + * + * @param identifier + * @return Identifier data. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + public namingauthority.IdentifierData resolveIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + + try { + LOG.info("resolveIdentifier: USER=========[" + SecurityManager.getManager().getCaller() + "]"); + SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); + return IdentifiersNAUtil.map(namingAuthority.resolveIdentifier(secInfo, URI.create(identifier))); + } + catch (InvalidIdentifierException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (NamingAuthoritySecurityException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.toString()); + } + } + + /********** + * This method is used to create keys. + * @param identifier + * @param identifierData + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + */ + + /************* + * This method is used to get the key names of the of an identifier. + * @param identifier + * @return + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + + /************** + * This method is used to get the key data associated with a key for an identifier. + * @param identifier + * @param keyName + * @return + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + */ + + /**** + * This method is used to register GSID in to the database of the GSID. This + * method is an authentication oriented operation. + * + * @param suggestedIdentifier + * is an optional parameter (can be null) which is used to + * register an non existing identifier. If the identifier already + * exists then new identifier is generated and returned. + * @param parentIdentifiers + * is an array of identifiers which are already registered and + * exists in the database. + * @return registered identifier. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + public java.lang.String registerGSID(java.lang.String suggestedIdentifier,java.lang.String[] parentIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + LOG.info("registerGSID: USER=========[" + SecurityManager.getManager().getCaller() + "]"); + SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); + try { + return namingAuthority.registerGSID(secInfo, suggestedIdentifier, parentIdentifiers); + } + catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (InvalidIdentifierException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (NamingAuthoritySecurityException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (InvalidIdentifierValuesException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.toString()); + } + } + + /***************************** + * This method is used to add an identifier to a site. This method is an + * authentication oriented operation. The identifier should exists in the + * database. + * + * @param identifier + * is an existing GSID to which you would like to attach your + * site data. + * @return + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + public org.apache.axis.types.URI addSite(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + LOG.info("addSite: USER=========[" + SecurityManager.getManager().getCaller() + "]"); + SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); + try { + namingAuthority.addSite(secInfo, identifier); + } + catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (InvalidIdentifierException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (NamingAuthoritySecurityException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (InvalidIdentifierValuesException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.toString()); + } + + return null; + + } + + /********************************** + * This method is used to generate a batch of identifiers. This method is a + * non authentication oriented operation. + * + * @param numOfIdentifiers + * is the number of identifiers you are requesting for should be + * between 1 and 100. + * @return array of identifiers. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + public java.lang.String[] generateIdentifiers(int numOfIdentifiers) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + LOG.info("generateIdentifiers: USER=========[" + SecurityManager.getManager().getCaller() + "]"); + SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); + try { + return namingAuthority.createBatchIdentifiers(secInfo, numOfIdentifiers); + } + catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (InvalidIdentifierException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (NamingAuthoritySecurityException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (InvalidIdentifierValuesException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.toString()); + } + + } + + /**************************************** + * This method is used to get the parent hierarchy details about the + * identifiers. This method is a non authentication oriented operation. + * + * @param identifier + * is the GSID for which you would like to get parent hierarchy + * information. + * @return a tree representing the parent hierarchy. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + */ + public namingauthority.Tree getParentHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault { + try { + LOG.info("getParentHierarchy: USER=========[" + SecurityManager.getManager().getCaller() + "]"); + SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); + Tree parents = namingAuthority.getParentHierarchy(secInfo, identifier.toString()); + return convert(parents); + } + catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (InvalidIdentifierException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (NamingAuthoritySecurityException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.toString()); + } + + } + + /***************************************** + * This method is used to get the child hierarchy details about the + * identifiers. This method is a non authentication oriented operation. + * + * @param identifier + * is the GSID for which you would like to get child hierarchy + * information. + * @return a tree representing the child hierarchy. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + public namingauthority.Tree getChildHierarchy(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + try { + LOG.info("getChildHierarchy: USER=========[" + SecurityManager.getManager().getCaller() + "]"); + SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); + Tree children = namingAuthority.getChildHierarchy(secInfo, identifier.toString()); + return convert(children); + } + catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (InvalidIdentifierException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (NamingAuthoritySecurityException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.toString()); + } + } + + /****************************** + * This method is used to register site information related to a globus + * credential. This is an authentication oriented operation. This operation + * should be executed before any other authentication operation for a new + * globus credential. Throws an exception if the globus credentials has + * already registered a site. + * + * @param application + * is the name of the application + * @param applicationURL + * is the URL of the application + * @param applicationVersion + * is the version of the application + * @param contactName + * is the contact of the site. + * @param contactEmail + * is the email address of the contact of the site. + * @param contactPhone + * is the phone number of the contact. + * @param organization + * is the organization of the site. + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault + */ + public void registerSite(java.lang.String application,java.lang.String applicationURL,java.lang.String applicationVersion,java.lang.String contactName,java.lang.String contactEmail,java.lang.String contactPhone,java.lang.String organization) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + + LOG.info("registerSite: USER=========[" + SecurityManager.getManager().getCaller() + "]"); + try { + SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); + namingAuthority.registerSite(secInfo, application, applicationURL, applicationVersion, contactName, + contactEmail, contactPhone, organization); + } + catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (InvalidIdentifierException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (NamingAuthoritySecurityException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.toString()); + } + + } + + /************************************************** + * This method checks if the identifier exists in the database or not. if + * identifier does not exists returns true else false. This is a non + * authentication oriented operation. + * + * @param identifier + * @return + * @throws RemoteException + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault + * @throws gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault + */ + public boolean validateIdentifier(java.lang.String identifier) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault { + try { + LOG.info("getChildHierarchy: USER=========[" + SecurityManager.getManager().getCaller() + "]"); + SecurityInfo secInfo = new SecurityInfoImpl(SecurityManager.getManager().getCaller()); + boolean flag = namingAuthority.validateIdentifier(secInfo, identifier); + return flag; + } + catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (InvalidIdentifierException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (NamingAuthoritySecurityException e) { + e.printStackTrace(); + throw IdentifiersNAUtil.map(e); + } + catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.toString()); + } + } + + private namingauthority.Tree convert(Tree tree) { + namingauthority.Tree temp = null; + if (tree != null) { + String identifier = tree.getIdentifier(); + namingauthority.Tree[] mytrees = null; + if (tree.getChildren() != null && tree.getChildren().size() > 0) { + mytrees = new namingauthority.Tree[tree.getChildren().size()]; + for (int i = 0; i < mytrees.length; i++) { + mytrees[i] = convert(tree.getChildren().get(i)); + } + } + temp = new namingauthority.Tree(identifier, mytrees); + } + return temp; + } + +} diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceImplBase.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceImplBase.java index e770af6..4c12046 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceImplBase.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/IdentifiersNAServiceImplBase.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.service; import gov.nih.nci.cagrid.identifiers.service.globus.resource.IdentifiersNAServiceResource; diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/IdentifiersNAServiceAuthorization.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/IdentifiersNAServiceAuthorization.java index a1b6f86..bc58cff 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/IdentifiersNAServiceAuthorization.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/IdentifiersNAServiceAuthorization.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.service.globus; diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/IdentifiersNAServiceProviderImpl.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/IdentifiersNAServiceProviderImpl.java index 552cc4e..22d359b 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/IdentifiersNAServiceProviderImpl.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/IdentifiersNAServiceProviderImpl.java @@ -1,77 +1,86 @@ -package gov.nih.nci.cagrid.identifiers.service.globus; - -import gov.nih.nci.cagrid.identifiers.service.IdentifiersNAServiceImpl; - -import java.rmi.RemoteException; - -/** - * DO NOT EDIT: This class is autogenerated! - * - * This class implements each method in the portType of the service. Each method call represented - * in the port type will be then mapped into the unwrapped implementation which the user provides - * in the IdentifiersNAServiceImpl class. This class handles the boxing and unboxing of each method call - * so that it can be correclty mapped in the unboxed interface that the developer has designed and - * has implemented. Authorization callbacks are automatically made for each method based - * on each methods authorization requirements. - * - * @created by Introduce Toolkit version 1.3 - * - */ -public class IdentifiersNAServiceProviderImpl{ - - IdentifiersNAServiceImpl impl; - - public IdentifiersNAServiceProviderImpl() throws RemoteException { - impl = new IdentifiersNAServiceImpl(); - } - - - public gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierResponse resolveIdentifier(gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierResponse(); - boxedResult.setIdentifierData(impl.resolveIdentifier(params.getIdentifier())); - return boxedResult; - } - - public gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDResponse registerGSID(gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDResponse(); - boxedResult.setResponse(impl.registerGSID(params.getSuggestedIdentifier(),params.getParentIdentifiers())); - return boxedResult; - } - - public gov.nih.nci.cagrid.identifiers.stubs.AddSiteResponse addSite(gov.nih.nci.cagrid.identifiers.stubs.AddSiteRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - gov.nih.nci.cagrid.identifiers.stubs.AddSiteResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.AddSiteResponse(); - boxedResult.setIdentifier(impl.addSite(params.getIdentifier())); - return boxedResult; - } - - public gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersResponse generateIdentifiers(gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersResponse(); - boxedResult.setResponse(impl.generateIdentifiers(params.getNumOfIdentifiers())); - return boxedResult; - } - - public gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyResponse getParentHierarchy(gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault { - gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyResponse(); - boxedResult.setTree(impl.getParentHierarchy(params.getIdentifier())); - return boxedResult; - } - - public gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyResponse getChildHierarchy(gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyResponse(); - boxedResult.setTree(impl.getChildHierarchy(params.getIdentifier())); - return boxedResult; - } - - public gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteResponse registerSite(gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { - gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteResponse(); - impl.registerSite(params.getApplication(),params.getApplicationURL(),params.getApplicationVersion(),params.getContactName(),params.getContactEmail(),params.getContactPhone(),params.getOrganization()); - return boxedResult; - } - - public gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierResponse validateIdentifier(gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault { - gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierResponse(); - boxedResult.setResponse(impl.validateIdentifier(params.getIdentifier())); - return boxedResult; - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package gov.nih.nci.cagrid.identifiers.service.globus; + +import gov.nih.nci.cagrid.identifiers.service.IdentifiersNAServiceImpl; + +import java.rmi.RemoteException; + +/** + * DO NOT EDIT: This class is autogenerated! + * + * This class implements each method in the portType of the service. Each method call represented + * in the port type will be then mapped into the unwrapped implementation which the user provides + * in the IdentifiersNAServiceImpl class. This class handles the boxing and unboxing of each method call + * so that it can be correclty mapped in the unboxed interface that the developer has designed and + * has implemented. Authorization callbacks are automatically made for each method based + * on each methods authorization requirements. + * + * @created by Introduce Toolkit version 1.3 + * + */ +public class IdentifiersNAServiceProviderImpl{ + + IdentifiersNAServiceImpl impl; + + public IdentifiersNAServiceProviderImpl() throws RemoteException { + impl = new IdentifiersNAServiceImpl(); + } + + + public gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierResponse resolveIdentifier(gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.ResolveIdentifierResponse(); + boxedResult.setIdentifierData(impl.resolveIdentifier(params.getIdentifier())); + return boxedResult; + } + + public gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDResponse registerGSID(gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.RegisterGSIDResponse(); + boxedResult.setResponse(impl.registerGSID(params.getSuggestedIdentifier(),params.getParentIdentifiers())); + return boxedResult; + } + + public gov.nih.nci.cagrid.identifiers.stubs.AddSiteResponse addSite(gov.nih.nci.cagrid.identifiers.stubs.AddSiteRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + gov.nih.nci.cagrid.identifiers.stubs.AddSiteResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.AddSiteResponse(); + boxedResult.setIdentifier(impl.addSite(params.getIdentifier())); + return boxedResult; + } + + public gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersResponse generateIdentifiers(gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.GenerateIdentifiersResponse(); + boxedResult.setResponse(impl.generateIdentifiers(params.getNumOfIdentifiers())); + return boxedResult; + } + + public gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyResponse getParentHierarchy(gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault { + gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.GetParentHierarchyResponse(); + boxedResult.setTree(impl.getParentHierarchy(params.getIdentifier())); + return boxedResult; + } + + public gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyResponse getChildHierarchy(gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.GetChildHierarchyResponse(); + boxedResult.setTree(impl.getChildHierarchy(params.getIdentifier())); + return boxedResult; + } + + public gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteResponse registerSite(gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthoritySecurityFault { + gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.RegisterSiteResponse(); + impl.registerSite(params.getApplication(),params.getApplicationURL(),params.getApplicationVersion(),params.getContactName(),params.getContactEmail(),params.getContactPhone(),params.getOrganization()); + return boxedResult; + } + + public gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierResponse validateIdentifier(gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierRequest params) throws RemoteException, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierFault, gov.nih.nci.cagrid.identifiers.stubs.types.InvalidIdentifierValuesFault, gov.nih.nci.cagrid.identifiers.stubs.types.NamingAuthorityConfigurationFault { + gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierResponse boxedResult = new gov.nih.nci.cagrid.identifiers.stubs.ValidateIdentifierResponse(); + boxedResult.setResponse(impl.validateIdentifier(params.getIdentifier())); + return boxedResult; + } + +} diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResource.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResource.java index 04ae193..a146acd 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResource.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResource.java @@ -1,17 +1,26 @@ -package gov.nih.nci.cagrid.identifiers.service.globus.resource; - -import org.globus.wsrf.InvalidResourceKeyException; -import org.globus.wsrf.NoSuchResourceException; -import org.globus.wsrf.ResourceException; -import org.globus.wsrf.ResourceKey; - - -/** - * The implementation of this IdentifiersNAServiceResource type. - * - * @created by Introduce Toolkit version 1.3 - * - */ -public class IdentifiersNAServiceResource extends IdentifiersNAServiceResourceBase { - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package gov.nih.nci.cagrid.identifiers.service.globus.resource; + +import org.globus.wsrf.InvalidResourceKeyException; +import org.globus.wsrf.NoSuchResourceException; +import org.globus.wsrf.ResourceException; +import org.globus.wsrf.ResourceKey; + + +/** + * The implementation of this IdentifiersNAServiceResource type. + * + * @created by Introduce Toolkit version 1.3 + * + */ +public class IdentifiersNAServiceResource extends IdentifiersNAServiceResourceBase { + +} diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceBase.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceBase.java index a94bbb9..e5f939b 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceBase.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceBase.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.service.globus.resource; import gov.nih.nci.cagrid.common.Utils; diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceConfiguration.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceConfiguration.java index 0a82943..2b50948 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceConfiguration.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceConfiguration.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.service.globus.resource; @@ -14,7 +23,7 @@ public class IdentifiersNAServiceResourceConfiguration { private String registrationTemplateFile; private boolean performRegistration; - private String serviceMetadataFile; + private String serviceMetadataFile; diff --git a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceHome.java b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceHome.java index 3d554fc..7dd0c79 100644 --- a/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceHome.java +++ b/identifiers-namingauthority-gridsvc/src/gov/nih/nci/cagrid/identifiers/service/globus/resource/IdentifiersNAServiceResourceHome.java @@ -1,87 +1,96 @@ -package gov.nih.nci.cagrid.identifiers.service.globus.resource; - -import gov.nih.nci.cagrid.identifiers.common.IdentifiersNAServiceConstants; -import gov.nih.nci.cagrid.identifiers.stubs.IdentifiersNAServiceResourceProperties; - -import org.apache.axis.components.uuid.UUIDGen; -import org.apache.axis.components.uuid.UUIDGenFactory; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.globus.wsrf.InvalidResourceKeyException; -import org.globus.wsrf.PersistenceCallback; -import org.globus.wsrf.Resource; -import org.globus.wsrf.ResourceException; -import org.globus.wsrf.ResourceKey; -import org.globus.wsrf.ResourceContext; -import gov.nih.nci.cagrid.introduce.servicetools.SingletonResourceHomeImpl; -import org.globus.wsrf.jndi.Initializable; - - -/** - * DO NOT EDIT: This class is autogenerated! - * - * This class implements the resource home for the resource type represented - * by this service. - * - * @created by Introduce Toolkit version 1.3 - * - */ -public class IdentifiersNAServiceResourceHome extends SingletonResourceHomeImpl implements Initializable { - - static final Log logger = LogFactory.getLog(IdentifiersNAServiceResourceHome.class); - private static final UUIDGen UUIDGEN = UUIDGenFactory.getUUIDGen(); - - public Resource createSingleton() { - logger.info("Creating a single resource."); - try { - IdentifiersNAServiceResourceProperties props = new IdentifiersNAServiceResourceProperties(); - IdentifiersNAServiceResource resource = new IdentifiersNAServiceResource(); - if (resource instanceof PersistenceCallback) { - //try to load the resource if it was persisted - try{ - ((PersistenceCallback) resource).load(null); - } catch (InvalidResourceKeyException ex){ - //persisted singleton resource was not found so we will just create a new one - resource.initialize(props, IdentifiersNAServiceConstants.RESOURCE_PROPERTY_SET, UUIDGEN.nextUUID()); - } - } else { - resource.initialize(props, IdentifiersNAServiceConstants.RESOURCE_PROPERTY_SET, UUIDGEN.nextUUID()); - } - - return resource; - } catch (Exception e) { - logger.error("Exception when creating the resource",e); - return null; - } - } - - - public Resource find(ResourceKey key) throws ResourceException { - IdentifiersNAServiceResource resource = (IdentifiersNAServiceResource) super.find(key); - return resource; - } - - - /** - * Initialze the singleton resource, when the home is initialized. - */ - public void initialize() throws Exception { - logger.info("Attempting to initialize resource."); - Resource resource = find(null); - if (resource == null) { - logger.error("Unable to initialize resource!"); - } else { - logger.info("Successfully initialized resource."); - } - } - - /** - * Get the resouce that is being addressed in this current context - */ - public IdentifiersNAServiceResource getAddressedResource() throws Exception { - IdentifiersNAServiceResource thisResource; - thisResource = (IdentifiersNAServiceResource) ResourceContext.getResourceContext().getResource(); - return thisResource; - } +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package gov.nih.nci.cagrid.identifiers.service.globus.resource; + +import gov.nih.nci.cagrid.identifiers.common.IdentifiersNAServiceConstants; +import gov.nih.nci.cagrid.identifiers.stubs.IdentifiersNAServiceResourceProperties; + +import org.apache.axis.components.uuid.UUIDGen; +import org.apache.axis.components.uuid.UUIDGenFactory; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.globus.wsrf.InvalidResourceKeyException; +import org.globus.wsrf.PersistenceCallback; +import org.globus.wsrf.Resource; +import org.globus.wsrf.ResourceException; +import org.globus.wsrf.ResourceKey; +import org.globus.wsrf.ResourceContext; +import gov.nih.nci.cagrid.introduce.servicetools.SingletonResourceHomeImpl; +import org.globus.wsrf.jndi.Initializable; + + +/** + * DO NOT EDIT: This class is autogenerated! + * + * This class implements the resource home for the resource type represented + * by this service. + * + * @created by Introduce Toolkit version 1.3 + * + */ +public class IdentifiersNAServiceResourceHome extends SingletonResourceHomeImpl implements Initializable { + + static final Log logger = LogFactory.getLog(IdentifiersNAServiceResourceHome.class); + private static final UUIDGen UUIDGEN = UUIDGenFactory.getUUIDGen(); + + public Resource createSingleton() { + logger.info("Creating a single resource."); + try { + IdentifiersNAServiceResourceProperties props = new IdentifiersNAServiceResourceProperties(); + IdentifiersNAServiceResource resource = new IdentifiersNAServiceResource(); + if (resource instanceof PersistenceCallback) { + //try to load the resource if it was persisted + try{ + ((PersistenceCallback) resource).load(null); + } catch (InvalidResourceKeyException ex){ + //persisted singleton resource was not found so we will just create a new one + resource.initialize(props, IdentifiersNAServiceConstants.RESOURCE_PROPERTY_SET, UUIDGEN.nextUUID()); + } + } else { + resource.initialize(props, IdentifiersNAServiceConstants.RESOURCE_PROPERTY_SET, UUIDGEN.nextUUID()); + } + + return resource; + } catch (Exception e) { + logger.error("Exception when creating the resource",e); + return null; + } + } + + + public Resource find(ResourceKey key) throws ResourceException { + IdentifiersNAServiceResource resource = (IdentifiersNAServiceResource) super.find(key); + return resource; + } + + + /** + * Initialze the singleton resource, when the home is initialized. + */ + public void initialize() throws Exception { + logger.info("Attempting to initialize resource."); + Resource resource = find(null); + if (resource == null) { + logger.error("Unable to initialize resource!"); + } else { + logger.info("Successfully initialized resource."); + } + } + + /** + * Get the resouce that is being addressed in this current context + */ + public IdentifiersNAServiceResource getAddressedResource() throws Exception { + IdentifiersNAServiceResource thisResource; + thisResource = (IdentifiersNAServiceResource) ResourceContext.getResourceContext().getResource(); + return thisResource; + } } \ No newline at end of file diff --git a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS-security-desc.xml b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS-security-desc.xml index e29b3ff..7874ee8 100644 --- a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS-security-desc.xml +++ b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS-security-desc.xml @@ -1,4 +1,14 @@ + + + diff --git a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS-security-metadata.xml b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS-security-metadata.xml index 1369e23..6abcff0 100644 --- a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS-security-metadata.xml +++ b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS-security-metadata.xml @@ -1,27 +1,36 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS_registration.xml b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS_registration.xml index 0b98309..9aca4e7 100644 --- a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS_registration.xml +++ b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/SyncGTS_registration.xml @@ -1,30 +1,40 @@ - - - - - http://cagrid-index-stage.nci.nih.gov:8080/wsrf/services/DefaultIndexService - - - 300 - - - - - 3600000 - - - - - - + + + + + + + + http://cagrid-index-stage.nci.nih.gov:8080/wsrf/services/DefaultIndexService + + + 300 + + + + + 3600000 + + + + + + diff --git a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/introduceDeployment.xml b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/introduceDeployment.xml index c106472..3fb7732 100644 --- a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/introduceDeployment.xml +++ b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/introduceDeployment.xml @@ -1,4 +1,14 @@ + + + diff --git a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/jndi-config.xml b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/jndi-config.xml index 729ff6b..2feda7a 100644 --- a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/jndi-config.xml +++ b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/jndi-config.xml @@ -1,4 +1,14 @@ + + + diff --git a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/sync-description.xml b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/sync-description.xml index bec826b..33872dd 100644 --- a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/sync-description.xml +++ b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/etc/cagrid_SyncGTS/sync-description.xml @@ -1,3 +1,12 @@ + + @gtsServiceURI@ diff --git a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/lib/ivy-1.4.xml b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/lib/ivy-1.4.xml index 7159dec..3936104 100644 --- a/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/lib/ivy-1.4.xml +++ b/identifiers-namingauthority-gridsvc/syncgts/WEB-INF/lib/ivy-1.4.xml @@ -1,72 +1,81 @@ - - - - - caGrid SyncGTS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + caGrid SyncGTS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority-gridsvc/test/logs/junit/TEST-gov.nih.nci.cagrid.identifiers.test.NATestCase.xml b/identifiers-namingauthority-gridsvc/test/logs/junit/TEST-gov.nih.nci.cagrid.identifiers.test.NATestCase.xml index df82065..b4bcb7d 100644 --- a/identifiers-namingauthority-gridsvc/test/logs/junit/TEST-gov.nih.nci.cagrid.identifiers.test.NATestCase.xml +++ b/identifiers-namingauthority-gridsvc/test/logs/junit/TEST-gov.nih.nci.cagrid.identifiers.test.NATestCase.xml @@ -1,4 +1,14 @@ - + + + + @@ -205,10 +215,10 @@ at java.lang.Class.forName(Class.java:169) diff --git a/identifiers-namingauthority-gridsvc/test/logs/junit/TEST-gov.nih.nci.cagrid.identifiers.test.StressTestCase.xml b/identifiers-namingauthority-gridsvc/test/logs/junit/TEST-gov.nih.nci.cagrid.identifiers.test.StressTestCase.xml index cdbc201..a2087a3 100644 --- a/identifiers-namingauthority-gridsvc/test/logs/junit/TEST-gov.nih.nci.cagrid.identifiers.test.StressTestCase.xml +++ b/identifiers-namingauthority-gridsvc/test/logs/junit/TEST-gov.nih.nci.cagrid.identifiers.test.StressTestCase.xml @@ -1,4 +1,14 @@ - + + + + diff --git a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/NATestCase.java b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/NATestCase.java index b594696..ad0a0a5 100644 --- a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/NATestCase.java +++ b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/NATestCase.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.test; import gov.nih.nci.cacoresdk.util.GridAuthenticationClient; diff --git a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/Pair.java b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/Pair.java index e5dd4cd..c4690bb 100644 --- a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/Pair.java +++ b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/Pair.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.test; public class Pair diff --git a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/StressTestCase.java b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/StressTestCase.java index ab6e7e9..f3ad758 100644 --- a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/StressTestCase.java +++ b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/StressTestCase.java @@ -1,170 +1,179 @@ -package gov.nih.nci.cagrid.identifiers.test; - -import gov.nih.nci.cacoresdk.util.GridAuthenticationClient; -import gov.nih.nci.cagrid.identifiers.client.IdentifiersNAServiceClient; - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.rmi.RemoteException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import junit.framework.TestCase; - -import org.apache.axis.types.URI.MalformedURIException; -import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; -import org.globus.gsi.GlobusCredential; - -public class StressTestCase extends TestCase -{ - - private static final String CLIENT_PROPERTIES = "etc/client.properties"; - private static final String SYNC_DESCRIPTION = "sync.description"; - - protected static Properties props = null; - static - { - props = readProperties(); - } - - private static Properties readProperties() - { - Properties properties = new Properties(); - try - { - properties.load(new FileInputStream(CLIENT_PROPERTIES)); - } - catch (Exception e) - { - // TODO: Display appropriate client error - System.out.println("Exception while accessing " + CLIENT_PROPERTIES + " : " + e.getMessage()); - System.exit(-1); - } - - return properties; - } - - private static String readFromFile(String fileName) throws IOException - { - FileReader fileReader = new FileReader(fileName); - BufferedReader bfReader = new BufferedReader(fileReader); - String idStr = ""; - String str = ""; - while ((str = bfReader.readLine()) != null) - { - idStr += str; - } - bfReader.close(); - return idStr; - } - - public void testStress1() - { - return; - } - private void testStress() - { - - GlobusCredential creds = null; - try - { - syncTrust(); - String userId = ""; - String password = ""; - String authenticationServiceURL = "https://dorian.training.cagrid.org:8443/wsrf/services/cagrid/Dorian"; - String dorianURL = "https://dorian.training.cagrid.org:8443/wsrf/services/cagrid/Dorian"; - creds = GridAuthenticationClient.authenticate(dorianURL, authenticationServiceURL, userId, password); - System.out.println("Using proxy with id= " + creds.getIdentity() + " and lifetime " + creds.getTimeLeft()); - } - catch (Exception e1) - { - System.out.println("No proxy file loaded so running with no credentials\n" + e1.getMessage()); - e1.getStackTrace(); - } - - try - { - IdentifiersNAServiceClient client = new IdentifiersNAServiceClient( - "https://localhost:8443/wsrf/services/cagrid/IdentifiersNAService", creds); - //client.registerSite("site", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", "443-481-7555", "sb"); - - long numberOfTests = 100l; - int numberOfThreads = 1; - int threadPool = 5; - double average=0; - long total=0; - TestName testName=TestName.ALL; - // this.NamingAuthority.registerSite(client, "site", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com","443-481-7555", "sb"); - ExecutorService executor = Executors.newFixedThreadPool(threadPool); - List> futures = new ArrayList>(); - for (int i = 0; i < numberOfThreads; i++) - { - String threadName = "t" + i; - StressTestUtil thread = new StressTestUtil(threadName, numberOfTests,testName, client); - Future future = executor.submit(thread, thread); - futures.add(future); - } - for (Future future : futures) - { - try - { - StressTestUtil e = future.get(); - } - catch (InterruptedException e) - { - System.out.println("Interrupted Exception occured "+e.getMessage()); - } - catch (ExecutionException e) - { - System.out.println("Execution Exception occured "+e.getMessage()); - } - } - Map> threadTime=StressTestUtil.getThreadTime(); - System.out.println("##############################################################"); - System.out.println("Number of tests "+numberOfTests); - for(String key:threadTime.keySet()) - { - - System.out.println("Thread: "+key); - Pair currentThreadPair=threadTime.get(key); - System.out.println("Start Time: "+currentThreadPair.start); - System.out.println("End Time: "+currentThreadPair.finish); - long diff=currentThreadPair.finish-currentThreadPair.start; - System.out.println("Duration: "+diff); - - total+=diff; - } - average=(double)total/((double)numberOfTests*(double)numberOfThreads*1000.0); - System.out.println("The average time is "+average); - System.out.println("##############################################################"); - executor.shutdown(); - - - } - catch (MalformedURIException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - catch (RemoteException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - private static void syncTrust() - { - System.out.println("Synchronize Once..."); - GridAuthenticationClient.synchronizeOnce(props.getProperty(SYNC_DESCRIPTION)); - System.out.println("Synchronize Complete."); - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package gov.nih.nci.cagrid.identifiers.test; + +import gov.nih.nci.cacoresdk.util.GridAuthenticationClient; +import gov.nih.nci.cagrid.identifiers.client.IdentifiersNAServiceClient; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import junit.framework.TestCase; + +import org.apache.axis.types.URI.MalformedURIException; +import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; +import org.globus.gsi.GlobusCredential; + +public class StressTestCase extends TestCase +{ + + private static final String CLIENT_PROPERTIES = "etc/client.properties"; + private static final String SYNC_DESCRIPTION = "sync.description"; + + protected static Properties props = null; + static + { + props = readProperties(); + } + + private static Properties readProperties() + { + Properties properties = new Properties(); + try + { + properties.load(new FileInputStream(CLIENT_PROPERTIES)); + } + catch (Exception e) + { + // TODO: Display appropriate client error + System.out.println("Exception while accessing " + CLIENT_PROPERTIES + " : " + e.getMessage()); + System.exit(-1); + } + + return properties; + } + + private static String readFromFile(String fileName) throws IOException + { + FileReader fileReader = new FileReader(fileName); + BufferedReader bfReader = new BufferedReader(fileReader); + String idStr = ""; + String str = ""; + while ((str = bfReader.readLine()) != null) + { + idStr += str; + } + bfReader.close(); + return idStr; + } + + public void testStress1() + { + return; + } + private void testStress() + { + + GlobusCredential creds = null; + try + { + syncTrust(); + String userId = ""; + String password = ""; + String authenticationServiceURL = "https://dorian.training.cagrid.org:8443/wsrf/services/cagrid/Dorian"; + String dorianURL = "https://dorian.training.cagrid.org:8443/wsrf/services/cagrid/Dorian"; + creds = GridAuthenticationClient.authenticate(dorianURL, authenticationServiceURL, userId, password); + System.out.println("Using proxy with id= " + creds.getIdentity() + " and lifetime " + creds.getTimeLeft()); + } + catch (Exception e1) + { + System.out.println("No proxy file loaded so running with no credentials\n" + e1.getMessage()); + e1.getStackTrace(); + } + + try + { + IdentifiersNAServiceClient client = new IdentifiersNAServiceClient( + "https://localhost:8443/wsrf/services/cagrid/IdentifiersNAService", creds); + //client.registerSite("site", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", "443-481-7555", "sb"); + + long numberOfTests = 100l; + int numberOfThreads = 1; + int threadPool = 5; + double average=0; + long total=0; + TestName testName=TestName.ALL; + // this.NamingAuthority.registerSite(client, "site", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com","443-481-7555", "sb"); + ExecutorService executor = Executors.newFixedThreadPool(threadPool); + List> futures = new ArrayList>(); + for (int i = 0; i < numberOfThreads; i++) + { + String threadName = "t" + i; + StressTestUtil thread = new StressTestUtil(threadName, numberOfTests,testName, client); + Future future = executor.submit(thread, thread); + futures.add(future); + } + for (Future future : futures) + { + try + { + StressTestUtil e = future.get(); + } + catch (InterruptedException e) + { + System.out.println("Interrupted Exception occured "+e.getMessage()); + } + catch (ExecutionException e) + { + System.out.println("Execution Exception occured "+e.getMessage()); + } + } + Map> threadTime=StressTestUtil.getThreadTime(); + System.out.println("##############################################################"); + System.out.println("Number of tests "+numberOfTests); + for(String key:threadTime.keySet()) + { + + System.out.println("Thread: "+key); + Pair currentThreadPair=threadTime.get(key); + System.out.println("Start Time: "+currentThreadPair.start); + System.out.println("End Time: "+currentThreadPair.finish); + long diff=currentThreadPair.finish-currentThreadPair.start; + System.out.println("Duration: "+diff); + + total+=diff; + } + average=(double)total/((double)numberOfTests*(double)numberOfThreads*1000.0); + System.out.println("The average time is "+average); + System.out.println("##############################################################"); + executor.shutdown(); + + + } + catch (MalformedURIException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (RemoteException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private static void syncTrust() + { + System.out.println("Synchronize Once..."); + GridAuthenticationClient.synchronizeOnce(props.getProperty(SYNC_DESCRIPTION)); + System.out.println("Synchronize Complete."); + } +} diff --git a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/StressTestUtil.java b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/StressTestUtil.java index 81a9757..d0656c1 100644 --- a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/StressTestUtil.java +++ b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/StressTestUtil.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.test; import gov.nih.nci.cagrid.identifiers.client.IdentifiersNAServiceClient; diff --git a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/TestName.java b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/TestName.java index 667532f..a24398f 100644 --- a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/TestName.java +++ b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/TestName.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.test; public enum TestName diff --git a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/TestUtil.java b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/TestUtil.java index b447c1b..4daef8d 100644 --- a/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/TestUtil.java +++ b/identifiers-namingauthority-gridsvc/test/src/gov/nih/nci/cagrid/identifiers/test/TestUtil.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package gov.nih.nci.cagrid.identifiers.test; import gov.nih.nci.cagrid.identifiers.client.IdentifiersNAServiceClient; diff --git a/identifiers-namingauthority-gridsvc/test/test.xml b/identifiers-namingauthority-gridsvc/test/test.xml index e11d2d4..c82ae8c 100644 --- a/identifiers-namingauthority-gridsvc/test/test.xml +++ b/identifiers-namingauthority-gridsvc/test/test.xml @@ -1,94 +1,103 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/identifiers-namingauthority-gridsvc/tools/deploymentValidator.xml b/identifiers-namingauthority-gridsvc/tools/deploymentValidator.xml index c92b35a..7ecaf62 100644 --- a/identifiers-namingauthority-gridsvc/tools/deploymentValidator.xml +++ b/identifiers-namingauthority-gridsvc/tools/deploymentValidator.xml @@ -1,3 +1,12 @@ - - - + + + + + diff --git a/identifiers-namingauthority/WebContent/WEB-INF/applicationContext-na.xml b/identifiers-namingauthority/WebContent/WEB-INF/applicationContext-na.xml index e37ffdd..7fbbd20 100644 --- a/identifiers-namingauthority/WebContent/WEB-INF/applicationContext-na.xml +++ b/identifiers-namingauthority/WebContent/WEB-INF/applicationContext-na.xml @@ -1,4 +1,14 @@ + + + + + + - - Identifiers NamingAuthority Web App - - - contextConfigLocation - - /WEB-INF/applicationContext-properties.xml - /WEB-INF/applicationContext-na.xml - - - - - org.springframework.web.context.ContextLoaderListener - - - - This servlet starts up the naming authority - NamingAuthorityService - NamingAuthorityService - org.cagrid.identifiers.namingauthority.impl.NamingAuthorityService - 1 - - - NamingAuthorityService - /NamingAuthorityService/* - - - - index.html - index.htm - index.jsp - default.html - default.htm - default.jsp - - - + + + + + + Identifiers NamingAuthority Web App + + + contextConfigLocation + + /WEB-INF/applicationContext-properties.xml + /WEB-INF/applicationContext-na.xml + + + + + org.springframework.web.context.ContextLoaderListener + + + + This servlet starts up the naming authority + NamingAuthorityService + NamingAuthorityService + org.cagrid.identifiers.namingauthority.impl.NamingAuthorityService + 1 + + + NamingAuthorityService + /NamingAuthorityService/* + + + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + + diff --git a/identifiers-namingauthority/build.xml b/identifiers-namingauthority/build.xml index 803d39b..d8cc91c 100644 --- a/identifiers-namingauthority/build.xml +++ b/identifiers-namingauthority/build.xml @@ -1,4 +1,14 @@ + + + diff --git a/identifiers-namingauthority/checkstyle/resources/sun_checks.xml b/identifiers-namingauthority/checkstyle/resources/sun_checks.xml index ff0eb85..efee294 100644 --- a/identifiers-namingauthority/checkstyle/resources/sun_checks.xml +++ b/identifiers-namingauthority/checkstyle/resources/sun_checks.xml @@ -1,4 +1,14 @@ + + + diff --git a/identifiers-namingauthority/dependencies-build.xml b/identifiers-namingauthority/dependencies-build.xml index 0dee701..26ee1a4 100644 --- a/identifiers-namingauthority/dependencies-build.xml +++ b/identifiers-namingauthority/dependencies-build.xml @@ -1,23 +1,32 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/IdentifierData.java b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/IdentifierData.java index c05b94b..c5ae0bd 100644 --- a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/IdentifierData.java +++ b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/IdentifierData.java @@ -1,73 +1,82 @@ -package org.cagrid.identifiers.namingauthority.domain; - -import java.util.HashMap; -import java.util.Map; - -public class IdentifierData implements java.io.Serializable { - - private Map data = new HashMap(); - - public Map getData() { - return this.data; - } - - public KeyData getValues(String key) { - return data.get(key); - } - - public void setValues(Map data) { - this.data = data; - } - - public String[] getKeys() { - return data.keySet().toArray(new String[data.keySet().size()]); - } - - public void put(String keyName, KeyData data) { - this.data.put(keyName, data); - } - - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - IdentifierData other = (IdentifierData) obj; - - if (!this.data.keySet().equals(other.getData().keySet())) { - return false; - } - - // keys (types) are the same, compare values now - - for (String type : this.getKeys()) { - if (!this.getValues(type).equals( - other.getValues(type))) { - return false; - } - } - return true; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - - for (String key : getKeys()) { - KeyData data = getValues(key); - sb.append("=====================================================================\n"); - sb.append("KEY [" + key + "]\n"); - sb.append(" POLICY IDENTIFIER [" + data.getPolicyIdentifier() + "]\n"); - if (data.getValues() != null) { - for (String value : data.getValues()) { - sb.append(" VALUE [" + value + "]\n"); - } - } - } - sb.append("\n"); - - return sb.toString(); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.domain; + +import java.util.HashMap; +import java.util.Map; + +public class IdentifierData implements java.io.Serializable { + + private Map data = new HashMap(); + + public Map getData() { + return this.data; + } + + public KeyData getValues(String key) { + return data.get(key); + } + + public void setValues(Map data) { + this.data = data; + } + + public String[] getKeys() { + return data.keySet().toArray(new String[data.keySet().size()]); + } + + public void put(String keyName, KeyData data) { + this.data.put(keyName, data); + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IdentifierData other = (IdentifierData) obj; + + if (!this.data.keySet().equals(other.getData().keySet())) { + return false; + } + + // keys (types) are the same, compare values now + + for (String type : this.getKeys()) { + if (!this.getValues(type).equals( + other.getValues(type))) { + return false; + } + } + return true; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + + for (String key : getKeys()) { + KeyData data = getValues(key); + sb.append("=====================================================================\n"); + sb.append("KEY [" + key + "]\n"); + sb.append(" POLICY IDENTIFIER [" + data.getPolicyIdentifier() + "]\n"); + if (data.getValues() != null) { + for (String value : data.getValues()) { + sb.append(" VALUE [" + value + "]\n"); + } + } + } + sb.append("\n"); + + return sb.toString(); + } + +} diff --git a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/IdentifierValues.java b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/IdentifierValues.java index b01684f..a797512 100644 --- a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/IdentifierValues.java +++ b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/IdentifierValues.java @@ -1,74 +1,83 @@ -package org.cagrid.identifiers.namingauthority.domain; - -import java.util.HashMap; -import java.util.Map; - -public class IdentifierValues implements java.io.Serializable { - private Map values = new HashMap(); - - - public Map getValues() { - return this.values; - } - - - public KeyValues getValues(String key) { - return values.get(key); - } - - - public void setValues(Map values) { - this.values = values; - } - - - public String[] getKeys() { - return values.keySet().toArray(new String[values.keySet().size()]); - } - - - public void put(String keyName, KeyValues data) { - this.values.put(keyName, data); - } - - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - IdentifierValues other = (IdentifierValues) obj; - - if (!this.values.keySet().equals(other.getValues().keySet())) { - return false; - } - - // keys (types) are the same, compare values now - - for (String type : this.getKeys()) { - if (!this.getValues(type).equals( - other.getValues(type))) { - return false; - } - } - return true; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - - for (String key : getKeys()) { - KeyValues data = getValues(key); - sb.append("=====================================================================\n"); - sb.append("KEY [" + key + "]\n"); - for (String value : data.getValues()) { - sb.append(" VALUE [" + value + "]\n"); - } - } - sb.append("\n"); - - return sb.toString(); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.domain; + +import java.util.HashMap; +import java.util.Map; + +public class IdentifierValues implements java.io.Serializable { + private Map values = new HashMap(); + + + public Map getValues() { + return this.values; + } + + + public KeyValues getValues(String key) { + return values.get(key); + } + + + public void setValues(Map values) { + this.values = values; + } + + + public String[] getKeys() { + return values.keySet().toArray(new String[values.keySet().size()]); + } + + + public void put(String keyName, KeyValues data) { + this.values.put(keyName, data); + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IdentifierValues other = (IdentifierValues) obj; + + if (!this.values.keySet().equals(other.getValues().keySet())) { + return false; + } + + // keys (types) are the same, compare values now + + for (String type : this.getKeys()) { + if (!this.getValues(type).equals( + other.getValues(type))) { + return false; + } + } + return true; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + + for (String key : getKeys()) { + KeyValues data = getValues(key); + sb.append("=====================================================================\n"); + sb.append("KEY [" + key + "]\n"); + for (String value : data.getValues()) { + sb.append(" VALUE [" + value + "]\n"); + } + } + sb.append("\n"); + + return sb.toString(); + } + +} diff --git a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/KeyData.java b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/KeyData.java index 7f81d2f..4cf840f 100644 --- a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/KeyData.java +++ b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/KeyData.java @@ -1,64 +1,73 @@ -package org.cagrid.identifiers.namingauthority.domain; - -import java.net.URI; -import java.util.List; - - -public class KeyData extends KeyValues implements java.io.Serializable { - - private URI policyIdentifier; - - public KeyData(){} - - public KeyData(URI identifier, String[] values) { - super(values); - this.policyIdentifier = identifier; - } - - public KeyData( URI identifier, List values) { - super(values); - this.policyIdentifier = identifier; - } - - public URI getPolicyIdentifier() { - return this.policyIdentifier; - } - - public void setPolicyIdentifier(URI identifier) { - this.policyIdentifier = identifier; - } - - private boolean comparePolicyReference(KeyData other) { - if (this.policyIdentifier == null) { - if (other.policyIdentifier != null) { - return false; - } - // both null - proceed - return true; - } else { - if (other.policyIdentifier == null) { - return false; - } - //both not null - return this.policyIdentifier.normalize().toString().equals( - other.policyIdentifier.normalize().toString()); - } - } - - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - - KeyData other = (KeyData) obj; - - if (!comparePolicyReference(other)) { - return false; - } - - return super.equals(obj); - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.domain; + +import java.net.URI; +import java.util.List; + + +public class KeyData extends KeyValues implements java.io.Serializable { + + private URI policyIdentifier; + + public KeyData(){} + + public KeyData(URI identifier, String[] values) { + super(values); + this.policyIdentifier = identifier; + } + + public KeyData( URI identifier, List values) { + super(values); + this.policyIdentifier = identifier; + } + + public URI getPolicyIdentifier() { + return this.policyIdentifier; + } + + public void setPolicyIdentifier(URI identifier) { + this.policyIdentifier = identifier; + } + + private boolean comparePolicyReference(KeyData other) { + if (this.policyIdentifier == null) { + if (other.policyIdentifier != null) { + return false; + } + // both null - proceed + return true; + } else { + if (other.policyIdentifier == null) { + return false; + } + //both not null + return this.policyIdentifier.normalize().toString().equals( + other.policyIdentifier.normalize().toString()); + } + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + + KeyData other = (KeyData) obj; + + if (!comparePolicyReference(other)) { + return false; + } + + return super.equals(obj); + } +} diff --git a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/KeyValues.java b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/KeyValues.java index 61d182e..0624980 100644 --- a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/KeyValues.java +++ b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/KeyValues.java @@ -1,83 +1,92 @@ -package org.cagrid.identifiers.namingauthority.domain; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class KeyValues implements java.io.Serializable { - - private List values; - - public KeyValues(){} - - public KeyValues( List values) { - init(values); - } - - public KeyValues( String[] values) { - if (values != null) { - init(Arrays.asList(values)); - } else { - init(null); - } - } - - protected void init(List values) { - this.values = values; - } - - public List getValues() { - return this.values; - } - - public void setValues(List values) { - this.values = values; - } - - public void addValue(String value) { - if (this.values == null) { - this.values = new ArrayList(); - } - this.values.add(value); - } - - public String[] getValuesAsArray() { - return this.values.toArray(new String[this.values.size()]); - } - - protected boolean compareValues(KeyValues other) { - if (this.values == null) { - if (other != null) { - return false; - } - // both null - proceed - return true; - } else { - if (other == null) { - return false; - } - } - - String[] thisValues = this.getValuesAsArray(); - String[] otherValues = other.getValuesAsArray(); - - Arrays.sort(thisValues); - Arrays.sort(otherValues); - - return Arrays.equals(thisValues, otherValues); - } - - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - - KeyValues other = (KeyValues) obj; - - return compareValues(other); - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.domain; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class KeyValues implements java.io.Serializable { + + private List values; + + public KeyValues(){} + + public KeyValues( List values) { + init(values); + } + + public KeyValues( String[] values) { + if (values != null) { + init(Arrays.asList(values)); + } else { + init(null); + } + } + + protected void init(List values) { + this.values = values; + } + + public List getValues() { + return this.values; + } + + public void setValues(List values) { + this.values = values; + } + + public void addValue(String value) { + if (this.values == null) { + this.values = new ArrayList(); + } + this.values.add(value); + } + + public String[] getValuesAsArray() { + return this.values.toArray(new String[this.values.size()]); + } + + protected boolean compareValues(KeyValues other) { + if (this.values == null) { + if (other != null) { + return false; + } + // both null - proceed + return true; + } else { + if (other == null) { + return false; + } + } + + String[] thisValues = this.getValuesAsArray(); + String[] otherValues = other.getValuesAsArray(); + + Arrays.sort(thisValues); + Arrays.sort(otherValues); + + return Arrays.equals(thisValues, otherValues); + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + + KeyValues other = (KeyValues) obj; + + return compareValues(other); + } +} diff --git a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/NamingAuthorityConfig.java b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/NamingAuthorityConfig.java index 5b9c346..54258b4 100644 --- a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/NamingAuthorityConfig.java +++ b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/domain/NamingAuthorityConfig.java @@ -1,35 +1,44 @@ -package org.cagrid.identifiers.namingauthority.domain; - -import java.net.URI; - -public class NamingAuthorityConfig implements java.io.Serializable { - - private URI naGridSvcURI; - private URI naPrefixURI; - private URI naBaseURI; - - public void setNaGridSvcURI( URI gridSvcURI ) { - this.naGridSvcURI = gridSvcURI; - } - - public URI getNaGridSvcURI() { - return this.naGridSvcURI; - } - - public void setNaPrefixURI( URI naPrefixURI ) { - this.naPrefixURI = naPrefixURI; - } - - public URI getNaPrefixURI() { - return this.naPrefixURI; - } - - public void setNaBaseURI( URI baseURI ) { - this.naBaseURI = baseURI; - } - - public URI getNaBaseURI() { - return this.naBaseURI; - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.domain; + +import java.net.URI; + +public class NamingAuthorityConfig implements java.io.Serializable { + + private URI naGridSvcURI; + private URI naPrefixURI; + private URI naBaseURI; + + public void setNaGridSvcURI( URI gridSvcURI ) { + this.naGridSvcURI = gridSvcURI; + } + + public URI getNaGridSvcURI() { + return this.naGridSvcURI; + } + + public void setNaPrefixURI( URI naPrefixURI ) { + this.naPrefixURI = naPrefixURI; + } + + public URI getNaPrefixURI() { + return this.naPrefixURI; + } + + public void setNaBaseURI( URI baseURI ) { + this.naBaseURI = baseURI; + } + + public URI getNaBaseURI() { + return this.naBaseURI; + } + +} diff --git a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/na-castor-mapping.xml b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/na-castor-mapping.xml index a415b34..bacb515 100644 --- a/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/na-castor-mapping.xml +++ b/identifiers-namingauthority/domain/src/org/cagrid/identifiers/namingauthority/na-castor-mapping.xml @@ -1,64 +1,74 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/identifiers-namingauthority/ivy.xml b/identifiers-namingauthority/ivy.xml index f33a081..7d6dc5a 100644 --- a/identifiers-namingauthority/ivy.xml +++ b/identifiers-namingauthority/ivy.xml @@ -1,54 +1,63 @@ - - - - - - - Identifiers Naming Authority - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + Identifiers Naming Authority + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority/ivysettings.xml b/identifiers-namingauthority/ivysettings.xml index 07738de..9347dd1 100644 --- a/identifiers-namingauthority/ivysettings.xml +++ b/identifiers-namingauthority/ivysettings.xml @@ -1,51 +1,61 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers-namingauthority/project.properties b/identifiers-namingauthority/project.properties index fc9e451..ddfcedb 100644 --- a/identifiers-namingauthority/project.properties +++ b/identifiers-namingauthority/project.properties @@ -1,2 +1,11 @@ +#L +# Copyright Washington University in St. Louis +# Copyright SemanticBits +# Copyright Persistent Systems +# +# Distributed under the OSI-approved BSD 3-Clause License. +# See http://ncip.github.com/gsid/LICENSE.txt for details. +#L + #Mon Jul 26 23:43:03 EDT 2010 project.version=1.4 diff --git a/identifiers-namingauthority/sql/Schema.sql b/identifiers-namingauthority/sql/Schema.sql index e94075e..087d6ea 100644 --- a/identifiers-namingauthority/sql/Schema.sql +++ b/identifiers-namingauthority/sql/Schema.sql @@ -1,3 +1,11 @@ +/*L + Copyright Washington University in St. Louis + Copyright SemanticBits + Copyright Persistent Systems + + Distributed under the OSI-approved BSD 3-Clause License. + See http://ncip.github.com/gsid/LICENSE.txt for details. +L*/ DROP TABLE IF EXISTS `identifier_key_values`; DROP TABLE IF EXISTS `identifier_keys`; diff --git a/identifiers-namingauthority/sql/SchemaTest.sql b/identifiers-namingauthority/sql/SchemaTest.sql index 31b7a7d..1304cf1 100644 --- a/identifiers-namingauthority/sql/SchemaTest.sql +++ b/identifiers-namingauthority/sql/SchemaTest.sql @@ -1,3 +1,11 @@ +/*L + Copyright Washington University in St. Louis + Copyright SemanticBits + Copyright Persistent Systems + + Distributed under the OSI-approved BSD 3-Clause License. + See http://ncip.github.com/gsid/LICENSE.txt for details. +L*/ -- -- Table structure for table `identifiers` diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/HttpProcessor.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/HttpProcessor.java index ce05f93..a8da744 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/HttpProcessor.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/HttpProcessor.java @@ -1,12 +1,21 @@ -package org.cagrid.identifiers.namingauthority; - -import java.io.IOException; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public interface HttpProcessor { - void setNamingAuthority( NamingAuthority na ); - NamingAuthority getNamingAuthority(); - void process(HttpServletRequest request, HttpServletResponse response) throws IOException; -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public interface HttpProcessor { + void setNamingAuthority( NamingAuthority na ); + NamingAuthority getNamingAuthority(); + void process(HttpServletRequest request, HttpServletResponse response) throws IOException; +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/IdentifierGenerator.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/IdentifierGenerator.java index f693008..bb9563a 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/IdentifierGenerator.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/IdentifierGenerator.java @@ -1,9 +1,18 @@ -package org.cagrid.identifiers.namingauthority; - -import java.net.URI; - -import org.cagrid.identifiers.namingauthority.domain.NamingAuthorityConfig; - -public interface IdentifierGenerator { - URI generate( NamingAuthorityConfig config ); -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority; + +import java.net.URI; + +import org.cagrid.identifiers.namingauthority.domain.NamingAuthorityConfig; + +public interface IdentifierGenerator { + URI generate( NamingAuthorityConfig config ); +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/InvalidIdentifierException.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/InvalidIdentifierException.java index 1dd5d61..dc7c44a 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/InvalidIdentifierException.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/InvalidIdentifierException.java @@ -1,30 +1,39 @@ -package org.cagrid.identifiers.namingauthority; - -public class InvalidIdentifierException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - - public InvalidIdentifierException() { - super(); - } - - - public InvalidIdentifierException(String message, Throwable cause) { - super(message, cause); - } - - - public InvalidIdentifierException(String message) { - super(message); - } - - - public InvalidIdentifierException(Throwable cause) { - super(cause); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority; + +public class InvalidIdentifierException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + + public InvalidIdentifierException() { + super(); + } + + + public InvalidIdentifierException(String message, Throwable cause) { + super(message, cause); + } + + + public InvalidIdentifierException(String message) { + super(message); + } + + + public InvalidIdentifierException(Throwable cause) { + super(cause); + } + +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/InvalidIdentifierValuesException.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/InvalidIdentifierValuesException.java index 540b220..70b788b 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/InvalidIdentifierValuesException.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/InvalidIdentifierValuesException.java @@ -1,29 +1,38 @@ -package org.cagrid.identifiers.namingauthority; - -public class InvalidIdentifierValuesException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - - public InvalidIdentifierValuesException() { - } - - - public InvalidIdentifierValuesException(String message) { - super(message); - } - - - public InvalidIdentifierValuesException(Throwable cause) { - super(cause); - } - - - public InvalidIdentifierValuesException(String message, Throwable cause) { - super(message, cause); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority; + +public class InvalidIdentifierValuesException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + + public InvalidIdentifierValuesException() { + } + + + public InvalidIdentifierValuesException(String message) { + super(message); + } + + + public InvalidIdentifierValuesException(Throwable cause) { + super(cause); + } + + + public InvalidIdentifierValuesException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/MaintainerNamingAuthority.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/MaintainerNamingAuthority.java index b43d00f..55276e5 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/MaintainerNamingAuthority.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/MaintainerNamingAuthority.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority; import java.net.URI; diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthority.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthority.java index 85e283f..2f39e7e 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthority.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthority.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority; import java.net.URI; diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthorityConfigurationException.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthorityConfigurationException.java index 5119eb2..f4ed987 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthorityConfigurationException.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthorityConfigurationException.java @@ -1,26 +1,35 @@ -package org.cagrid.identifiers.namingauthority; - -public class NamingAuthorityConfigurationException extends Exception { - - private static final long serialVersionUID = 1L; - - - public NamingAuthorityConfigurationException() { - } - - - public NamingAuthorityConfigurationException(String message) { - super(message); - } - - - public NamingAuthorityConfigurationException(Throwable cause) { - super(cause); - } - - - public NamingAuthorityConfigurationException(String message, Throwable cause) { - super(message, cause); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority; + +public class NamingAuthorityConfigurationException extends Exception { + + private static final long serialVersionUID = 1L; + + + public NamingAuthorityConfigurationException() { + } + + + public NamingAuthorityConfigurationException(String message) { + super(message); + } + + + public NamingAuthorityConfigurationException(Throwable cause) { + super(cause); + } + + + public NamingAuthorityConfigurationException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthoritySecurityException.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthoritySecurityException.java index ddf2191..e36a350 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthoritySecurityException.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/NamingAuthoritySecurityException.java @@ -1,26 +1,35 @@ -package org.cagrid.identifiers.namingauthority; - -public class NamingAuthoritySecurityException extends Exception { - - private static final long serialVersionUID = 1L; - - - public NamingAuthoritySecurityException() { - } - - - public NamingAuthoritySecurityException(String message) { - super(message); - } - - - public NamingAuthoritySecurityException(Throwable cause) { - super(cause); - } - - - public NamingAuthoritySecurityException(String message, Throwable cause) { - super(message, cause); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority; + +public class NamingAuthoritySecurityException extends Exception { + + private static final long serialVersionUID = 1L; + + + public NamingAuthoritySecurityException() { + } + + + public NamingAuthoritySecurityException(String message) { + super(message); + } + + + public NamingAuthoritySecurityException(Throwable cause) { + super(cause); + } + + + public NamingAuthoritySecurityException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/SecurityInfo.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/SecurityInfo.java index 15d63d2..233f050 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/SecurityInfo.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/SecurityInfo.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority; public interface SecurityInfo { diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/UnexpectedIdentifiersException.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/UnexpectedIdentifiersException.java index b5e833f..3e4a584 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/UnexpectedIdentifiersException.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/UnexpectedIdentifiersException.java @@ -1,26 +1,35 @@ -package org.cagrid.identifiers.namingauthority; - -public class UnexpectedIdentifiersException extends Exception { - - private static final long serialVersionUID = 1L; - - - public UnexpectedIdentifiersException() { - } - - - public UnexpectedIdentifiersException(String message) { - super(message); - } - - - public UnexpectedIdentifiersException(Throwable cause) { - super(cause); - } - - - public UnexpectedIdentifiersException(String message, Throwable cause) { - super(message, cause); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority; + +public class UnexpectedIdentifiersException extends Exception { + + private static final long serialVersionUID = 1L; + + + public UnexpectedIdentifiersException() { + } + + + public UnexpectedIdentifiersException(String message) { + super(message); + } + + + public UnexpectedIdentifiersException(Throwable cause) { + super(cause); + } + + + public UnexpectedIdentifiersException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/dao/AbstractDao.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/dao/AbstractDao.java index f730018..f7e019d 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/dao/AbstractDao.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/dao/AbstractDao.java @@ -1,90 +1,99 @@ -package org.cagrid.identifiers.namingauthority.dao; - -import java.sql.SQLException; -import java.util.Collection; -import java.util.List; - -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.hibernate.criterion.Example; -import org.hibernate.criterion.MatchMode; -import org.springframework.orm.hibernate3.HibernateCallback; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; -import javax.persistence.NonUniqueResultException; - - - -public abstract class AbstractDao extends HibernateDaoSupport { - - public abstract Class domainClass(); - - - public T getByExample(final T sample) { - T result = null; - List results = searchByExample(sample, false); - if (results.size() > 1) { - throw new NonUniqueResultException("Found " + results.size() + " " + sample.getClass().getName() - + " objects."); - } else if (results.size() == 1) { - result = results.get(0); - } - return result; - } - - - @SuppressWarnings("unchecked") - public T getById(int id) { - return (T) getHibernateTemplate().get(domainClass(), id); - } - - - @SuppressWarnings("unchecked") - public List searchByExample(final T sample, final boolean inexactMatches) { - return (List) getHibernateTemplate().execute(new HibernateCallback() { - public Object doInHibernate(Session session) throws HibernateException, SQLException { - Example example = Example.create(sample).excludeZeroes(); - if (inexactMatches) { - example.ignoreCase().enableLike(MatchMode.ANYWHERE); - } - - return session.createCriteria(domainClass()).add(example).list(); - } - }); - } - - - public List searchByExample(T example) { - return searchByExample(example, true); - } - - - public void save(Collection domainObjects) { - getHibernateTemplate().saveOrUpdateAll(domainObjects); - } - - - public void save(T domainObject) { - getHibernateTemplate().saveOrUpdate(domainObject); - } - - - public void update(T domainObject) { - getHibernateTemplate().update(domainObject); - } - - - public void delete(T domainObject) { - getHibernateTemplate().delete(domainObject); - } - - - public void delete(Collection domainObjects) { - getHibernateTemplate().deleteAll(domainObjects); - } - - - public List getAll() { - return getHibernateTemplate().find("from " + domainClass().getSimpleName()); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.dao; + +import java.sql.SQLException; +import java.util.Collection; +import java.util.List; + +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.criterion.Example; +import org.hibernate.criterion.MatchMode; +import org.springframework.orm.hibernate3.HibernateCallback; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; +import javax.persistence.NonUniqueResultException; + + + +public abstract class AbstractDao extends HibernateDaoSupport { + + public abstract Class domainClass(); + + + public T getByExample(final T sample) { + T result = null; + List results = searchByExample(sample, false); + if (results.size() > 1) { + throw new NonUniqueResultException("Found " + results.size() + " " + sample.getClass().getName() + + " objects."); + } else if (results.size() == 1) { + result = results.get(0); + } + return result; + } + + + @SuppressWarnings("unchecked") + public T getById(int id) { + return (T) getHibernateTemplate().get(domainClass(), id); + } + + + @SuppressWarnings("unchecked") + public List searchByExample(final T sample, final boolean inexactMatches) { + return (List) getHibernateTemplate().execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException, SQLException { + Example example = Example.create(sample).excludeZeroes(); + if (inexactMatches) { + example.ignoreCase().enableLike(MatchMode.ANYWHERE); + } + + return session.createCriteria(domainClass()).add(example).list(); + } + }); + } + + + public List searchByExample(T example) { + return searchByExample(example, true); + } + + + public void save(Collection domainObjects) { + getHibernateTemplate().saveOrUpdateAll(domainObjects); + } + + + public void save(T domainObject) { + getHibernateTemplate().saveOrUpdate(domainObject); + } + + + public void update(T domainObject) { + getHibernateTemplate().update(domainObject); + } + + + public void delete(T domainObject) { + getHibernateTemplate().delete(domainObject); + } + + + public void delete(Collection domainObjects) { + getHibernateTemplate().deleteAll(domainObjects); + } + + + public List getAll() { + return getHibernateTemplate().find("from " + domainClass().getSimpleName()); + } + +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/dao/IdentifierMetadataDao.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/dao/IdentifierMetadataDao.java index b060a59..64285bd 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/dao/IdentifierMetadataDao.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/dao/IdentifierMetadataDao.java @@ -1,1621 +1,1630 @@ -package org.cagrid.identifiers.namingauthority.dao; - -import edu.internet2.middleware.grouper.GroupNotFoundException; -import gov.nih.nci.cagrid.gridgrouper.client.GridGrouper; -import gov.nih.nci.cagrid.gridgrouper.grouper.GrouperI; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.UUID; - -import javax.persistence.NonUniqueResultException; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; -import org.cagrid.identifiers.namingauthority.InvalidIdentifierValuesException; -import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; -import org.cagrid.identifiers.namingauthority.NamingAuthoritySecurityException; -import org.cagrid.identifiers.namingauthority.SecurityInfo; -import org.cagrid.identifiers.namingauthority.domain.IdentifierData; -import org.cagrid.identifiers.namingauthority.domain.IdentifierValues; -import org.cagrid.identifiers.namingauthority.domain.KeyData; -import org.cagrid.identifiers.namingauthority.domain.KeyValues; -import org.cagrid.identifiers.namingauthority.hibernate.IdentifierMetadata; -import org.cagrid.identifiers.namingauthority.hibernate.IdentifierValueKey; -import org.cagrid.identifiers.namingauthority.impl.IdentifierGeneratorImpl; -import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; -import org.cagrid.identifiers.namingauthority.util.Constant; -import org.cagrid.identifiers.namingauthority.util.IdentifierUtil; -import org.cagrid.identifiers.namingauthority.util.Keys; -import org.cagrid.identifiers.namingauthority.util.SecurityUtil; -import org.cagrid.identifiers.namingauthority.util.SecurityUtil.Access; -import org.cagrid.identifiers.namingauthority.util.Tree; - -public class IdentifierMetadataDao extends AbstractDao { - - protected final static Log LOG = LogFactory.getLog(IdentifierMetadataDao.class.getName()); - public static final String PUBLISHER = "PUBLISHER"; - public static final String TYPE = "TYPE"; - public static final String GSID = "GSID"; - public static final String SITE = "SITE"; - public static final String SITE_DATA = "SITEDATA"; - private IdentifierMetadata systemValues; - private URI prefix; - private String grouperURL; - private String groupName; - - public String getGrouperURL() { - return grouperURL; - } - - public void setGrouperURL(String grouperURL) { - this.grouperURL = grouperURL; - } - - public String getGroupName() { - return groupName; - } - - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - @Override - public Class domainClass() { - return IdentifierMetadata.class; - } - - /****** - * initializer. - * - * @param prefix - * prefix to be used for the representing data. - * @throws NamingAuthorityConfigurationException - */ - public synchronized void initialize(URI prefix) throws NamingAuthorityConfigurationException { - this.prefix = prefix; - try { - systemValues = loadLocalIdentifier(SecurityUtil.LOCAL_SYSTEM_IDENTIFIER); - } - catch (InvalidIdentifierException e) { - LOG.debug("No system identifier defined"); - createSystemIdentifier(); - } - } - - /****** - * This method is used to load the data of an identifier without prefix. - * - * @param identifier - * unprefixed identifier for which the data has to be loaded. - * @return identifier data in the form of IdentifierMetaData. - * @throws InvalidIdentifierException - * @throws NamingAuthorityConfigurationException - */ - public IdentifierMetadata loadLocalIdentifier(final URI localIdentifier) throws InvalidIdentifierException, - NamingAuthorityConfigurationException { - LOG.debug("The local identifier is " + localIdentifier); - List results = getHibernateTemplate().find( - "SELECT md FROM " + domainClass().getName() + " md WHERE md.localIdentifier = ?", - new Object[] { localIdentifier }); - IdentifierMetadata result = null; - if (results.size() > 1) { - throw new NonUniqueResultException("Found " + results.size() + " " + domainClass().getName() + " objects."); - } - else if (results.size() == 1) { - result = results.get(0); - } - if (result == null) { - throw new InvalidIdentifierException("Local identifier (" + localIdentifier + ") does not exist"); - } - return result; - } - - /****** - * This method is used to load the data of an identifier with prefix. - * - * @param identifier - * prefixed identifier for which the data has to be loaded. - * @return identifier data in the form of IdentifierMetaData. - * @throws InvalidIdentifierException - * @throws NamingAuthorityConfigurationException - */ - public IdentifierMetadata loadIdentifier(URI identifier) throws InvalidIdentifierException, - NamingAuthorityConfigurationException { - return loadLocalIdentifier(IdentifierUtil.getLocalName(prefix, identifier)); - } - - /****** - * This method is get the site data from its identifier. note: Site is used - * to store the user information. - * - * @param localIdentifier - * @return IdentifierMetaData instance containing site data. - * @throws InvalidIdentifierException - * @throws NamingAuthorityConfigurationException - */ - public List getSiteData(URI localIdentifier) throws InvalidIdentifierException, - NamingAuthorityConfigurationException { - LOG.debug("The local identifier is " + localIdentifier); - List results = getHibernateTemplate() - .find("SELECT md FROM " - + domainClass().getName() - + " as md INNER JOIN md.values as value INNER JOIN value.values as val WHERE value.key='GSID' and val=?", - new Object[] { localIdentifier.toString() }); - return results; - } - - /**** - * Returns keys associated with the given identifier - */ - public String[] getKeyNames(SecurityInfo secInfo, java.net.URI identifier) throws InvalidIdentifierException, - NamingAuthoritySecurityException, NamingAuthorityConfigurationException { - IdentifierData values = null; - try { - values = getIdentifierData(secInfo, identifier, null); - } - catch (InvalidIdentifierValuesException e) { - throw new NamingAuthorityConfigurationException(e); - } - if (values != null) { - return values.getKeys(); - } - return null; - } - - /**** - * Returns values associated with a key in the given identifier - */ - public KeyData getKeyData(SecurityInfo secInfo, URI identifier, String key) throws InvalidIdentifierException, - NamingAuthoritySecurityException, NamingAuthorityConfigurationException, InvalidIdentifierValuesException { - IdentifierData values = getIdentifierData(secInfo, identifier, key); - if (values != null && values.getValues(key) != null) { - return values.getValues(key); - } - return null; - } - - /**** - * Resolves an identifier to its associated meta-data - */ - public IdentifierData resolveIdentifier(SecurityInfo secInfo, java.net.URI identifier) - throws InvalidIdentifierException, NamingAuthoritySecurityException, NamingAuthorityConfigurationException { - if (identifier == null) { - throw new InvalidIdentifierException("Identifier cannot be null."); - } - try { - if (!identifier.toString().startsWith(prefix.toString())) { - try { - identifier = IdentifierUtil.build(prefix, identifier); - } - catch (Exception e) { - LOG.debug(identifier + " is not a prefixed URI."); - } - } - LOG.debug("the identifier is " + identifier); - IdentifierData completeData = getIdentifierData(secInfo, identifier, null); - identifier = IdentifierUtil.getLocalName(prefix, identifier); - List siteData = getSiteData(identifier); - if (CollectionUtils.isNotEmpty(siteData)) { - LOG.debug("site data size is " + siteData.size()); - int counter = 0; - for (IdentifierMetadata metaData : siteData) { - IdentifierData currentData = IdentifierUtil.convert(metaData.getValues()); - for (String key : currentData.getKeys()) { - if (PUBLISHER.equalsIgnoreCase(key)) { - KeyData data = currentData.getValues(key); - String publisherIdentifier = data.getValues().get(0); - try { - URI publisherURI = new URI(prefix + publisherIdentifier); - IdentifierData siteIdentifier = getIdentifierData(secInfo, publisherURI, null); - if (siteIdentifier != null) { - for (String key1 : siteIdentifier.getKeys()) { - LOG.debug("the key1 is " + key1); - if (!TYPE.equalsIgnoreCase(key1)) { - completeData.put(counter + ":" + key1, siteIdentifier.getValues(key1)); - } - } - } - } - catch (Exception e) { - throw new InvalidIdentifierException(); - } - } - else if (!GSID.equalsIgnoreCase(key) && !TYPE.equalsIgnoreCase(key)) { - LOG.debug("the key is " + key); - completeData.put(counter + ":" + key, currentData.getValues(key)); - } - } - counter++; - } - } - return completeData; - } - catch (InvalidIdentifierValuesException e) { - throw new NamingAuthorityConfigurationException(e); - } - } - - /**** - * A user can read a key from an identifier if any one of the below - * conditions are met: - * - * (a) User is identifier's administrator - User is listed by ADMIN_USERS - * key, or - User is listed by ADMIN_IDENTIFIERS's ADMIN_USERS key, or - - * User is listed by root identifier's ADMIN_USERS key - * - * (b) User is listed by the key's READWRITE_IDENTIFIER's READ_USERS list - * (c) Key has no READWRITE_IDENTIFIER.READ_USERS and user is listed by - * identifier's READ_USERS (d) Key has no READWRITE_IDENTIFIER.READ_USERS - * and user is listed by identifier's READWRITE_IDENTIFIERS.READ_USERS (e) - * No READ_USERS keys at any level (key & identifier) - * - * A security exception is thrown if the identifier has keys and none are - * returned due to permission checks. - */ - public IdentifierData getIdentifierData(SecurityInfo secInfo, java.net.URI identifier, String keyName) - throws InvalidIdentifierException, NamingAuthoritySecurityException, NamingAuthorityConfigurationException, - InvalidIdentifierValuesException { - secInfo = validateSecurityInfo(secInfo); - IdentifierMetadata tmpValues = loadIdentifier(identifier); - if (tmpValues == null) { - return null; - } - if (hasIdentifierAdminUserAccess(secInfo, tmpValues)) { - // - // User is ADMIN_USER - // - return IdentifierUtil.convert(tmpValues.getValues()); - } - Collection valueCol = tmpValues.getValues(); - if (CollectionUtils.isEmpty(valueCol)) { - return null; - } - if (keyName != null) { - IdentifierValueKey searchKey = new IdentifierValueKey(); - searchKey.setKey(keyName); - if (!valueCol.contains(searchKey)) { - throw new InvalidIdentifierValuesException("Key [" + keyName + "] does not exist"); - } - } - Access identifierReadAccess = null; - IdentifierData newValues = new IdentifierData(); - for (IdentifierValueKey ivk : valueCol) { - if (keyName != null && !keyName.equals(ivk.getKey())) { - continue; - } - Access keyAccess = getKeyReadAccess(secInfo, ivk.getPolicyIdentifier()); - if (keyAccess == Access.GRANTED) { - LOG.debug("SECURITY: User [" + secInfo.getUser() + "] can access key [" + ivk.getKey() + "]"); - newValues.put(ivk.getKey(), IdentifierUtil.convert(ivk)); - } - else if (keyAccess == Access.DENIED) { - LOG.debug("SECURITY: User [" + secInfo.getUser() + "] can't access key [" + ivk.getKey() + "]"); - } - else if (keyAccess == Access.NOSECURITY) { - LOG.debug("SECURITY: No key security for [" + ivk.getKey() + "]. Checking identifier security..."); - // Apply identifier level security - if (identifierReadAccess == null) { - List identifierReadUsers = getAllReadUsers(tmpValues); - identifierReadAccess = userAccess(secInfo.getUser(), identifierReadUsers); - } - if (identifierReadAccess == Access.DENIED) { - LOG.debug("SECURITY: User [" + secInfo.getUser() + "] is NOT authorized to read key [" - + ivk.getKey() + "] by identifier"); - } - else { - LOG.debug("SECURITY: User [" + secInfo.getUser() + "] is authorized to read [" + ivk.getKey() - + "] by identifier"); - newValues.put(ivk.getKey(), IdentifierUtil.convert(ivk)); - } - } - } - // Is this the only case when we bark? - if (newValues.getKeys() == null || newValues.getKeys().length == 0) { - String msg; - if (keyName != null) { - msg = "resolve identifier key [" + keyName + "]"; - } - else { - msg = "resolve identifier"; - } - throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, msg)); - } - return newValues; - } - - /**** - * Persists the provided identifier with the given values - */ - public void createIdentifier(SecurityInfo secInfo, URI localIdentifier, IdentifierData ivalues) - throws InvalidIdentifierException, NamingAuthorityConfigurationException, NamingAuthoritySecurityException { - LOG.debug("The value of localIdentifier is " + localIdentifier); - secInfo = validateSecurityInfo(secInfo); - createIdentifierSecurityChecks(secInfo); - save(IdentifierUtil.convert(localIdentifier, ivalues)); - } - - /**** - * Adds the provided keys to the given identifier. - * - * An exception is thrown if any of the provided keys already exists. - * - * Permissions: - * - * Case 1) Creating security-type keys as defined by Keys.isAdminKey() A - * user can create security-type keys if s/he is explicitly listed as an - * ADMIN_USER by either the identifier, or the system (root) identifier. - * - * Case 2) Creating other keys A user can create other keys if s/he is - * listed as a WRITE_USER by the identifier, or if a WRITE_USERS key is not - * configured by the identifier. - * - * Identifier's ADMIN_USERS can create keys of any type. It is unnecessary - * to list them as WRITE_USERS. - */ - public void createKeys(SecurityInfo secInfo, URI identifier, IdentifierData values) - throws InvalidIdentifierException, NamingAuthoritySecurityException, InvalidIdentifierValuesException, - NamingAuthorityConfigurationException { - Boolean writerAccess = null; - Boolean adminAccess = null; - if (values == null || values.getKeys() == null || values.getKeys().length == 0) { - throw new InvalidIdentifierValuesException("No keys were provided"); - } - secInfo = validateSecurityInfo(secInfo); - URI localIdentifier = IdentifierUtil.getLocalName(prefix, identifier); - IdentifierMetadata resolvedValues = loadLocalIdentifier(localIdentifier); - Collection valueKeys = resolvedValues.getValues(); - for (String key : values.getKeys()) { - // Start of security checks - if (Keys.isAdminKey(key)) { - if (adminAccess == null) { - adminAccess = hasIdentifierAdminUserAccess(secInfo, resolvedValues); - } - if (!adminAccess) { - throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, "create key [" + key - + "]. Not an ADMIN_USER")); - } - } - else { - if (writerAccess == null) { - writerAccess = hasWriteUserAccess(secInfo, resolvedValues); - } - if (!writerAccess) { - // - // Check if user is administrator - // - if (adminAccess == null) { - adminAccess = hasIdentifierAdminUserAccess(secInfo, resolvedValues); - } - if (!adminAccess) { - throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, - "create keys. Neither WRITE_USER nor ADMIN_USER")); - } - } - } - // End of security checks - IdentifierValueKey ivk = IdentifierUtil.convert(key, values.getValues(key)); - if (valueKeys.contains(ivk)) { - throw new InvalidIdentifierValuesException("Key [" + key + "] already exists for identifier [" - + identifier.normalize().toString() + "]"); - } - valueKeys.add(ivk); - } - save(resolvedValues); - if (SecurityUtil.isSystemIdentifier(localIdentifier)) { - replaceSystemValues(secInfo, resolvedValues); - } - } - - /**** - * Deletes the provided keys from the given identifier. - * - * An exception is thrown if any of the provided keys does not exist. - * - * Permissions: - * - * Case 1) Deleting security-type keys as defined by Keys.isAdminKey() A - * user can delete security-type keys if s/he is explicitly listed as an - * ADMIN_USER by either the identifier, or the system (root) identifier. - * - * Case 2) Deleting other keys A user can delete other keys if s/he is - * listed as a WRITE_USER by the identifier, or if a WRITE_USERS key is not - * configured by the identifier. - * - * Identifier's ADMIN_USERS can delete keys of any type. It is unnecessary - * to list them as WRITE_USERS. - */ - public void deleteKeys(SecurityInfo secInfo, URI identifier, String[] keyList) throws InvalidIdentifierException, - NamingAuthoritySecurityException, InvalidIdentifierValuesException, NamingAuthorityConfigurationException { - if (keyList == null || keyList.length == 0) { - throw new InvalidIdentifierValuesException("No keys were provided"); - } - secInfo = validateSecurityInfo(secInfo); - Boolean writerAccess = null; - Boolean adminAccess = null; - URI localIdentifier = IdentifierUtil.getLocalName(prefix, identifier); - IdentifierMetadata resolvedValues = loadLocalIdentifier(localIdentifier); - if (resolvedValues.getValues() == null || resolvedValues.getValues().isEmpty()) { - throw new InvalidIdentifierValuesException("Identifier [" + identifier + "] has no keys"); - } - LOG.debug("User [" + secInfo.getUser() + "] deleting some keys for identifier [" + identifier.toString() + "]"); - List keysToDelete = new ArrayList(); - ArrayList keyNames = new ArrayList(Arrays.asList(keyList)); - for (IdentifierValueKey ivk : resolvedValues.getValues()) { - if (!keyNames.contains(ivk.getKey())) { - continue; - } - // Start of security checks - if (Keys.isAdminKey(ivk.getKey())) { - if (adminAccess == null) { - adminAccess = hasIdentifierAdminUserAccess(secInfo, resolvedValues); - } - if (!adminAccess) { - throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, - "delete key [" + ivk.getKey() + "]. Not an ADMIN_USER")); - } - } - else { - if (writerAccess == null) { - writerAccess = hasWriteUserAccess(secInfo, resolvedValues); - } - if (!writerAccess) { - // - // Check if user is administrator - // - if (adminAccess == null) { - adminAccess = hasIdentifierAdminUserAccess(secInfo, resolvedValues); - } - if (!adminAccess) { - throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, - "delete keys. Neither WRITE_USER nor ADMIN_USER")); - } - } - } - // End of security checks - LOG.debug("Removing key [" + ivk.getKey() + "]"); - keysToDelete.add(ivk); - } - if (keysToDelete.size() != keyNames.size()) { - // Unrecognized key. Should we actually fail this? - String missingKeys = ""; - for (String key : keyNames) { - if (!keysToDelete.contains(key)) { - if (missingKeys.equals("")) - missingKeys += key; - else - missingKeys += ", " + key; - } - } - throw new InvalidIdentifierValuesException("Unexpected keys found in the request [" + missingKeys + "]"); - } - if (keysToDelete.size() > 0) { - getHibernateTemplate().deleteAll(keysToDelete); - resolvedValues.getValues().removeAll(keysToDelete); - } - save(resolvedValues); - if (SecurityUtil.isSystemIdentifier(localIdentifier)) { - replaceSystemValues(secInfo, resolvedValues); - } - } - - /**** - * Replaces the values associated with existing keys with the new provided - * values. - * - * An exception is thrown if any of the provided keys does not exist - * - * Permissions: - * - * Identifier's ADMIN_USERS can replace any key values - * - * Security-type key values can only be replaced by ADMIN_USERS - * - * Regular users can replace the values for a key if s/he is listed as a - * WRITE_USER for that key. - * - * When no WRITE_USERS key is defined at the key level, the user must be - * listed as a WRITE_USER for the identifier. - * - * When no WRITE_USERS key is defined for either the key or the identifier, - * any user can replace the values. - */ - public void replaceKeyValues(SecurityInfo secInfo, URI identifier, IdentifierValues newValues) - throws InvalidIdentifierException, NamingAuthoritySecurityException, InvalidIdentifierValuesException, - NamingAuthorityConfigurationException { - if (newValues == null || newValues.getKeys() == null || newValues.getKeys().length == 0) { - throw new InvalidIdentifierValuesException(Constant.NO_KEY_VALUES); - } - secInfo = validateSecurityInfo(secInfo); - URI localIdentifier = IdentifierUtil.getLocalName(prefix, identifier); - IdentifierMetadata resolvedValues = loadLocalIdentifier(localIdentifier); - if (resolvedValues.getValues() == null || resolvedValues.getValues().isEmpty()) { - throw new InvalidIdentifierValuesException("Identifier [" + identifier + "] has no keys"); - } - Boolean identifierAdminAccess = hasIdentifierAdminUserAccess(secInfo, resolvedValues); - Boolean identifierWriteAccess = null; - ArrayList keysToReplace = new ArrayList(Arrays.asList(newValues.getKeys())); - for (IdentifierValueKey ivk : resolvedValues.getValues()) { - if (!keysToReplace.contains(ivk.getKey())) { - continue; - } - if (!identifierAdminAccess) { - if (Keys.isAdminKey(ivk.getKey())) { - String error = SecurityUtil.securityError(secInfo, "replace key [" + ivk.getKey() - + "]. Not an ADMIN_USER"); - LOG.error(error); - throw new NamingAuthoritySecurityException(error); - } - // - // Check key level security using key's read-write identifier - // - Access keyAccess = getKeyWriteAccess(secInfo, ivk.getPolicyIdentifier()); - if (keyAccess == Access.DENIED) { - // - // WRITE_USERS defined for key and this user is not listed - // - String error = SecurityUtil.securityError(secInfo, "replace key [" + ivk.getKey() - + "]. Not a WRITE_USER"); - LOG.error(error); - throw new NamingAuthoritySecurityException(error); - } - if (keyAccess == Access.NOSECURITY) { - // - // Fall back to identifier level security - // - if (identifierWriteAccess == null) { - identifierWriteAccess = hasWriteUserAccess(secInfo, resolvedValues); - } - - if (!identifierWriteAccess) { - // - // WRITE_USERS defined identifier and this user is not - // listed - // - String error = SecurityUtil.securityError(secInfo, "replace key [" + ivk.getKey() - + "]. Not a WRITE_USER"); - LOG.error(error); - throw new NamingAuthoritySecurityException(error); - } - } - } - keysToReplace.remove(ivk.getKey()); - KeyValues kvs = newValues.getValues(ivk.getKey()); - ivk.setValues(kvs.getValues()); - } - - if (keysToReplace.size() > 0) { - throw new InvalidIdentifierValuesException("Key [" + keysToReplace.get(0) - + "] does not exist for identifier [" + identifier.normalize().toString() + "]"); - } - save(resolvedValues); - // Save system identifier if necessary - if (SecurityUtil.isSystemIdentifier(localIdentifier)) { - replaceSystemValues(secInfo, resolvedValues); - } - } - - /**** - * Adds administrator identity to system identifier - */ - public synchronized void createInitialAdministrator(String identity) throws NamingAuthorityConfigurationException { - if (systemValues == null || systemValues.getValues() == null) { - throw new NamingAuthorityConfigurationException("No system values. Please initialize DAO first"); - } - - IdentifierValueKey adminKey = null; - Collection valCol = systemValues.getValues(); - for (IdentifierValueKey ivk : valCol) { - if (ivk.getKey().equals(Keys.ADMIN_USERS)) { - adminKey = ivk; - break; - } - } - if (adminKey == null) { - adminKey = new IdentifierValueKey(); - valCol.add(adminKey); - } - if (adminKey.getValues() != null && adminKey.getValues().size() > 0) { - throw new NamingAuthorityConfigurationException("An administrator already exists"); - } - ArrayList values = new ArrayList(); - values.add(identity); - adminKey.setValues(values); - save(systemValues); - } - - /****** - * This method is used to register an identifier. At the end of this method - * an identifier is generated and saved in the persistent store. If - * suggestedIdentifier is set to null then a new identifier is created and - * is returned. If suggestedIdentifier is not null then system uses this - * identifier only if the identifier does not exists in the persistent store - * otherwise it creates a new identifier, saves it and returns the newly - * created identifier. - * - * @param secInfo - * provides the information about the user. - * @param suggestedIdentifier - * is an identifier that a user would like to register. - * @param parentIdentifiers - * used to represent if current identifier should be child of any - * existing identifiers or not. - * @return an identifier. - * @throws NamingAuthorityConfigurationException - * @throws InvalidIdentifierValuesException - * @throws InvalidIdentifierException - * @throws NamingAuthoritySecurityException - */ - public String registerGSID(SecurityInfo secInfo, String suggestedIdentifier, String[] parentIdentifiers) - throws NamingAuthorityConfigurationException, InvalidIdentifierValuesException, InvalidIdentifierException, - NamingAuthoritySecurityException { - checkSecurity(secInfo, false, true); - String userName = secInfo.getUser(); - String publisherIdentifier = getIdentifierFromUser(userName); - String temp = null; - List keys = new ArrayList(); - List values = new ArrayList(); - if (StringUtils.isNotBlank(suggestedIdentifier)) { - validateIdentifierPattern(suggestedIdentifier); - } - if (parentIdentifiers != null && parentIdentifiers.length > 0) { - for (String parent : parentIdentifiers) - LOG.debug("the parent is " + parent); - String value = ""; - String total_value = ""; - boolean atleastOneParent = false; - for (int i = 0; i < parentIdentifiers.length; i++) { - value = parentIdentifiers[i]; - if (StringUtils.isNotBlank(value)) { - if (StringUtils.isNotBlank(suggestedIdentifier) && StringUtils.isNotBlank(suggestedIdentifier) - && value.equals(suggestedIdentifier)) { - // throw an exception saying that an suggestedIdentifier - // cannot be a parent. - throw new InvalidIdentifierValuesException("Violation: suggested identifier " - + suggestedIdentifier + " is also present in parent identifiers array"); - } - total_value += value + ","; - atleastOneParent = true; - } - } - if (atleastOneParent) { - // remove last comma. - total_value = total_value.substring(0, total_value.length() - 1); - keys.add("parent"); - values.add(total_value); - } - } - keys.add(TYPE); - values.add(GSID); - temp = suggestedIdentifier = createIdentifier(secInfo, suggestedIdentifier, keys, values); - if (suggestedIdentifier != null) { - // second transaction. - keys = new ArrayList(); - values = new ArrayList(); - keys.add(PUBLISHER); - values.add(publisherIdentifier); - keys.add(GSID); - values.add(suggestedIdentifier); - keys.add(TYPE); - values.add(SITE_DATA); - createIdentifier(secInfo, null, keys, values); - } - return temp; - - } - - /****** - * This method is used to register a site for a user. - * - * @param secInfo - * grid credentials for the user. - * @param application - * @param applicationURL - * @param applicationVersion - * @param contactName - * @param contactEmail - * @param contactPhone - * @param organization - * @throws NamingAuthorityConfigurationException - * @throws InvalidIdentifierValuesException - * @throws InvalidIdentifierException - * @throws NamingAuthoritySecurityException - */ - public void registerSite(SecurityInfo secInfo, String application, String applicationURL, - String applicationVersion, String contactName, String contactEmail, String contactPhone, String organization) - throws NamingAuthorityConfigurationException, InvalidIdentifierValuesException, InvalidIdentifierException, - NamingAuthoritySecurityException { - checkSecurity(secInfo, false, false); - List keys = new ArrayList(); - List values = new ArrayList(); - if (StringUtils.isBlank(application)) { - throw new InvalidIdentifierValuesException("application value cannot be null"); - } - else if (StringUtils.isBlank(applicationURL)) { - throw new InvalidIdentifierValuesException("application url value cannot be null"); - } - else if (StringUtils.isBlank(applicationVersion)) { - throw new InvalidIdentifierValuesException("applicaiton version value cannot be null"); - } - else if (StringUtils.isBlank(contactName)) { - throw new InvalidIdentifierValuesException("contact name value cannot be null"); - } - else if (StringUtils.isBlank(contactEmail)) { - throw new InvalidIdentifierValuesException("contact email value cannot be null"); - } - else if (StringUtils.isBlank(contactPhone)) { - throw new InvalidIdentifierValuesException("contact phone value cannot be null"); - } - else if (StringUtils.isBlank(organization)) { - throw new InvalidIdentifierValuesException("organization value cannot be null"); - } - - String[] tempValues = { application, applicationURL, applicationVersion, contactEmail, contactName, - contactPhone, organization, secInfo.getUser() }; - String[] fixedKeys = { "application", "applicationUrl", "applicationVersion", "contactEmail", "contactName", - "contactPhone", "organization", "userName" }; - for (int i = 0; i < fixedKeys.length; i++) { - if (tempValues[i] == null || tempValues[i].trim().length() == 0) { - throw new InvalidIdentifierException(); - } - keys.add(fixedKeys[i]); - values.add(tempValues[i]); - } - keys.add(TYPE); - values.add(SITE); - createIdentifier(secInfo, null, keys, values); - } - - /****** - * This method is used to add a site to existing identifier. - * - * @param secInfo - * security info of the user. - * @param identifier - * identifier to which user would like to add his/her site. - * @throws NamingAuthorityConfigurationException - * @throws InvalidIdentifierValuesException - * @throws InvalidIdentifierException - * @throws NamingAuthoritySecurityException - */ - public void addSite(SecurityInfo secInfo, String identifier) throws NamingAuthorityConfigurationException, - InvalidIdentifierValuesException, InvalidIdentifierException, NamingAuthoritySecurityException { - checkSecurity(secInfo, true, true); - if (StringUtils.isBlank(identifier)) { - throw new InvalidIdentifierException("Identifier cannot be null."); - } - validateIdentifierPattern(identifier); - URI identifierURI = null; - try { - identifierURI = new URI(identifier); - } - catch (URISyntaxException e) { - throw new InvalidIdentifierException("Unable to parse identifier."); - } - IdentifierMetadata imd = loadLocalIdentifier(identifierURI); - if (imd == null) { - throw new InvalidIdentifierException("Identifier does not exists."); - } - String userName = secInfo.getUser(); - String publisherIdentifier = getIdentifierFromUser(userName); - List keys = new ArrayList(); - List values = new ArrayList(); - keys.add(TYPE); - values.add(SITE_DATA); - keys.add(PUBLISHER); - values.add(publisherIdentifier); - keys.add(GSID); - values.add(identifier); - createIdentifier(secInfo, null, keys, values); - } - - /****** - * This method is used to validates the identifier. Validation checks if the - * identifier is in the database or not. if exists returns false else - * returns true. - * - * @param secInfo - * secInfo of the user not a mandatory parameter. - * @param identifier - * identifier for which validation is done. - * @return true if identifier does not exists in the database. - * @throws InvalidIdentifierException - * @throws NamingAuthoritySecurityException - * @throws NamingAuthorityConfigurationException - */ - public boolean validateIdentifier(SecurityInfo secInfo, String identifier) throws InvalidIdentifierException, - NamingAuthoritySecurityException, NamingAuthorityConfigurationException { - if (identifier == null) { - throw new InvalidIdentifierException("Identifier cannot be null."); - } - validateIdentifierPattern(identifier); - try { - URI temp = new URI(identifier); - try { - IdentifierMetadata metaData = loadLocalIdentifier(temp); - if (metaData != null) - return false; - } - catch (Exception e) { - return true; - } - } - catch (URISyntaxException e) { - throw new InvalidIdentifierException("Identifier cannot parsed."); - } - - return true; - } - - /******* - * This method is used to get the parent hierarchy in the form of a tree - * with root node as identifier node. - * - * @param secInfo - * security info of the user can be null. - * @param identifier - * for which the hierarchy to be generated. - * @return Tree representing the parent hierarchy. - * @throws InvalidIdentifierException - * @throws NamingAuthoritySecurityException - * @throws NamingAuthorityConfigurationException - */ - public Tree getParentHierarchy(SecurityInfo secInfo, String identifier) throws InvalidIdentifierException, - NamingAuthoritySecurityException, NamingAuthorityConfigurationException { - if (StringUtils.isBlank(identifier)) { - throw new InvalidIdentifierException("Identifier cannot be null"); - } - validateIdentifierPattern(identifier); - List parents = new ArrayList(); - - Tree currentNode = new Tree(identifier); - Tree rootNode = currentNode; - parents.add(currentNode); - while (parents.size() != 0) { - currentNode = parents.get(0); - String tempIdentifier = (currentNode).getIdentifier(); - parents.remove(0); - IdentifierData currentKeyData = null; - try { - URI uri = null; - try { - uri = new java.net.URI(prefix + tempIdentifier); - } - catch (Exception e) { - } - if (uri != null) { - currentKeyData = getIdentifierData(secInfo, uri, "parent"); - } - } - catch (InvalidIdentifierValuesException e1) { - tempIdentifier = null; - } - if (currentKeyData != null) { - if (currentKeyData.getKeys() != null) { - for (String key : currentKeyData.getKeys()) { - KeyData values = currentKeyData.getValues(key); - // parent should have only one value so get the first - // one. - if (values != null) { - for (String value : values.getValues()) { - String tempURI = null; - try { - if (value != null) { - tempURI = value; - } - else { - LOG.debug("values is null"); - } - } - catch (Exception e) { - e.printStackTrace(); - } - if (tempURI != null) { - Tree tempNode = new Tree(tempURI); - currentNode.addChild(tempNode); - parents.add(tempNode); - } - } - } - else { - LOG.debug("values are null"); - } - } - } - else { - LOG.debug("getKeys is null"); - } - } - else { - LOG.debug("currentkeydata is null"); - } - } - LOG.debug("the tree is " + rootNode.toString(true)); - return rootNode; - } - - /******* - * This method is used to get the child hierarchy in the form of a tree with - * root node as identifier node. - * - * @param secInfo - * security info of the user can be null. - * @param identifier - * for which the hierarchy to be generated. - * @return Tree representing the child hierarchy. - * @throws InvalidIdentifierException - * @throws NamingAuthoritySecurityException - * @throws NamingAuthorityConfigurationException - */ - public Tree getChildHierarchy(SecurityInfo secInfo, String identifier) throws InvalidIdentifierException, - NamingAuthoritySecurityException, InvalidIdentifierValuesException, NamingAuthorityConfigurationException { - if (identifier == null || identifier.length() == 0) { - throw new InvalidIdentifierException("Identifier cannot be null"); - } - validateIdentifierPattern(identifier); - List parents = new ArrayList(); - Tree currentNode = new Tree(identifier); - Tree rootNode = currentNode; - parents.add(currentNode); - while (parents.size() != 0) { - currentNode = parents.get(0); - String tempIdentifier = currentNode.getIdentifier(); - parents.remove(0); - List currentChildren = getChildItems(secInfo, tempIdentifier); - if (currentChildren != null) { - if (currentChildren.size() > 0) { - for (IdentifierMetadata child : currentChildren) { - String key = child.getLocalIdentifier().toString(); - // parent should have only one value so get the first - // one. - if (key != null) { - LOG.debug("the key is " + key); - Tree tempNode = new Tree(key); - currentNode.addChild(tempNode); - parents.add(tempNode); - } - else { - LOG.debug("values are null"); - } - } - } - else { - LOG.debug("current children size is zero"); - } - } - else { - LOG.debug("current child is null"); - } - } - LOG.debug("the tree is " + rootNode.toString(true)); - return rootNode; - } - - /****** - * This method is used to get all the identifiers whose parent is the - * provided identifier. - * - * @param secInfo - * security info of the user can be null. - * @param identifier - * for which the children are found. - * @return list of IdentifierMetadata representing info of each identifier - * which have provided identifier as parent. - * @throws InvalidIdentifierException - * @throws NamingAuthoritySecurityException - * @throws InvalidIdentifierValuesException - * @throws NamingAuthorityConfigurationException - */ - public List getChildItems(SecurityInfo secInfo, String identifier) - throws InvalidIdentifierException, NamingAuthoritySecurityException, InvalidIdentifierValuesException, - NamingAuthorityConfigurationException { - validateSecurityInfo(secInfo); - List results = getHibernateTemplate() - .find("SELECT md FROM " - + domainClass().getName() - + " as md INNER JOIN md.values as value INNER JOIN value.values as val WHERE value.key='parent' and val=?", - new Object[] { identifier }); - LOG.debug("The results Size is " + results.size()); - return results; - } - - /****** - * This method is used to gets the data for all the sites. - * - * @param secInfo - * security info of the user. - * @param naPrefix - * prefix uri. - * @return list of IdentifierData representing the sites. - * @throws InvalidIdentifierException - * @throws NamingAuthoritySecurityException - * @throws InvalidIdentifierValuesException - * @throws NamingAuthorityConfigurationException - */ - public List getSitesData(SecurityInfo secInfo, URI naPrefix) throws InvalidIdentifierException, - NamingAuthoritySecurityException, InvalidIdentifierValuesException, NamingAuthorityConfigurationException { - validateSecurityInfo(secInfo); - List results = getHibernateTemplate() - .find("SELECT md FROM " - + domainClass().getName() - + " as md INNER JOIN md.values as value INNER JOIN value.values as val WHERE value.key='TYPE' and val='SITE'"); - if (results != null) { - LOG.debug("The results Size is " + results.size()); - } - List resultData = new ArrayList(); - if (results != null) { - for (IdentifierMetadata result : results) { - if (result != null) { - IdentifierData tempData = IdentifierUtil.convert(result.getValues()); - if (tempData != null) { - String identifierValue = result.getLocalIdentifier().toString(); - KeyData tempKeyData = new KeyData(tempData.getValues(tempData.getKeys()[0]) - .getPolicyIdentifier(), new String[] { identifierValue }); - tempData.put("IDENTIFIER", tempKeyData); - resultData.add(tempData); - } - } - } - } - return resultData; - } - - /****** - * This method is used to checks if parent identifiers are empty or not. - * - * @param parents - * @return true if parent identifiers are not empty and false otherwise. - */ - private boolean checkIfParentsEmpty(String[] parents) { - boolean flag = false; - if (parents != null && parents.length > 0) { - for (String parent : parents) { - if (StringUtils.isBlank(parent)) { - flag = true; - break; - } - } - } - else { - flag = true; - } - return flag; - } - - /****** - * This method is used to get the identifier of the site associated with the - * user. - * - * @param userName - * string representing user name. - * @return identifier. - */ - public String getIdentifierFromUser(String userName) { - if (StringUtils.isBlank(userName)) - return null; - String temp = null; - List results = getHibernateTemplate() - .find("SELECT md FROM " - + domainClass().getName() - + " as md INNER JOIN md.values as value INNER JOIN value.values as val WHERE value.key='userName' and val=?", - new Object[] { userName.trim() }); - if (results != null && results.size() == 1) { - URI tempGURI = results.get(0).getLocalIdentifier(); - if (tempGURI != null) { - temp = tempGURI.toString(); - } - } - return temp; - } - - /****** - * This method check if the identifier exists in the persistent code. - * - * @param identifier - * @return true if the identifier exists in the persistent and false - * otherwise. - */ - public boolean checkIfIdentifierExists(URI identifier) { - List results = getHibernateTemplate().find( - "SELECT md FROM " + domainClass().getName() + " md WHERE md.localIdentifier = ?", - new Object[] { identifier }); - return results == null || results.isEmpty() ? false : true; - } - - /****** - * This method is used to check the security based on the parameters. - * - * @param secInfo - * info representing the user. - * @param checkOnlyLogin - * if this is true then it checks if user belongs to a group or - * not. - * @param checkHasSite - * if this is true then it check if the user has registered a - * site or not. - * @throws NamingAuthoritySecurityException - */ - public void checkSecurity(SecurityInfo secInfo, boolean checkOnlyLogin, boolean checkHasSite) - throws NamingAuthoritySecurityException { - String caller = secInfo.getUser(); - if (StringUtils.isBlank(caller)) { - throw new NamingAuthoritySecurityException("Please login into the grid to identify yourselves"); - } - if (!checkOnlyLogin) { - // check for a group. - if (!isMember(caller)) { - throw new NamingAuthoritySecurityException("You should be a member of this \"" + groupName - + "\" group before you proceed."); - } - } - String Identifier = getIdentifierFromUser(caller); - if (checkHasSite) { - if (Identifier == null) { - throw new NamingAuthoritySecurityException("Please register a site before you proceed"); - } - } - else { - if (Identifier != null) { - throw new NamingAuthoritySecurityException("You have already registered a site"); - } - } - } - - /****** - * Check whether a user is member of a group or not. - * - * @param userIdentity - * @return - */ - private boolean isMember(String userIdentity) { - if ((StringUtils.isNotEmpty(grouperURL)) && (StringUtils.isNotEmpty(groupName))) { - // Create a Grid Grouper Instance - GrouperI grouper = new GridGrouper(grouperURL); - - try { - // Determine if the user is a member of the group. - boolean isMember = grouper.isMemberOf(userIdentity, groupName); - - if (isMember) { - LOG.debug("The user " + userIdentity + " is a member of " + groupName); - return true; - } - else { - LOG.debug("The user " + userIdentity + " is NOT a member of " + groupName); - return false; - } - } - catch (GroupNotFoundException e) { - LOG.debug("The group " + groupName + " does not exist, therefore the user " + userIdentity - + " is NOT a member."); - return false; - } - } - // returning true if no grouper authentication needed. - return true; - } - - /**** - * Private Stuff - */ - - /****** - * this method save the identifier into the persistent store. - * - */ - private String createIdentifier(SecurityInfo secInfo, String identifier, List keys, List values) - throws InvalidIdentifierException, NamingAuthorityConfigurationException, NamingAuthoritySecurityException { - - String temp = null; - - String[] keyArray = new String[keys.size()]; - String[][] valueArray = new String[keys.size()][]; - for (int i = 0; i < keys.size(); i++) { - keyArray[i] = keys.get(i); - String value = values.get(i); - String[] valueArr; - if (value != null && value.contains(",")) { - valueArr = value.split(","); - } - else { - valueArr = new String[1]; - valueArr[0] = value; - } - if (keys.get(i).contains("parent")) { - LOG.debug("the values are " + valueArr); - for (String valueAr1 : valueArr) { - - // org.apache.axis.types.URI axisUri = getAxisURI(valueAr1, - // builder); - LOG.debug("value Ar1 " + valueAr1); - try { - URI valueAr1URI = new URI(valueAr1); - valueAr1URI = IdentifierUtil.build(prefix, valueAr1URI); - resolveIdentifier(secInfo, valueAr1URI); - - } - catch (URISyntaxException e) { - LOG.debug("URI casting from String execption " + valueAr1); - throw new InvalidIdentifierException("Unable to convert " + valueAr1 + " "); - } - - } - } - valueArray[i] = valueArr; - } - - org.cagrid.identifiers.namingauthority.domain.IdentifierData ivs = new org.cagrid.identifiers.namingauthority.domain.IdentifierData(); - for (int i = 0; i < keyArray.length; i++) { - URI policyReference = null; - KeyData kd = new KeyData(policyReference, valueArray[i]); - ivs.put(keyArray[i], kd); - } - URI identifierURI = null; - if (identifier == null) { - identifier = (new IdentifierGeneratorImpl()).generate(null).toString(); - } - else { - try { - while (checkIfIdentifierExists(new URI(identifier))) { - identifier = (new IdentifierGeneratorImpl()).generate(null).toString(); - } - } - catch (URISyntaxException e) { - - LOG.warn("URI Syntax exception occured"); - throw new InvalidIdentifierException("URI is Invalid"); - } - } - - try { - identifierURI = new URI(identifier); - } - catch (URISyntaxException e) { - LOG.debug("URI sytanx exception occured by identifier " + identifier); - } - try { - createIdentifier(secInfo, identifierURI, ivs); - temp = identifierURI.toString(); - } - catch (NamingAuthorityConfigurationException e) { - LOG.debug("Naming authority configuration exception occured"); - throw new NamingAuthorityConfigurationException(); - } - catch (InvalidIdentifierException e) { - LOG.debug("Invalid Identifier Exception occured"); - throw new InvalidIdentifierException(); - } - catch (NamingAuthoritySecurityException e) { - LOG.debug("Naming Authority Security Exception occured"); - throw new NamingAuthoritySecurityException(); - } - return temp; - } - - /**** - * A user can create identifiers if any one of the below conditions are met: - * - * (a) PUBLIC_CREATTION key set to "Y" in root identifier (b) User is listed - * by IDENTIFIER_CREATION_USERS key in root identifier (c) No security - * settings are specified - No root identifier - No PUBLIC_CREATION key in - * root identifier - */ - private synchronized void createIdentifierSecurityChecks(SecurityInfo secInfo) throws InvalidIdentifierException, - NamingAuthorityConfigurationException, NamingAuthoritySecurityException { - - List values = SecurityUtil.getPublicCreation(systemValues); - if (values == null || values.isEmpty()) { - // no security - LOG.debug("SECURITY: No PUBLIC_CREATION"); - return; - } - - if (values.size() != 1) { - throw new NamingAuthorityConfigurationException("Bad PUBLIC_CREATION setting detected"); - } - - if (values.get(0).equalsIgnoreCase(SecurityUtil.PUBLIC_CREATION_YES)) { - // everyone can create identifiers - return; - } - - List authorizedUsers = SecurityUtil.getIdentifierCreationUsers(systemValues); - if (authorizedUsers == null || !authorizedUsers.contains(secInfo.getUser())) { - throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, "create identifiers")); - } - } - - /**** - * Returns any directly specified READ_USERS plus any included by - * READWRITE_IDENTIFIERS - */ - private List getAllReadUsers(IdentifierMetadata values) throws InvalidIdentifierException, - NamingAuthorityConfigurationException { - - List readUsers = SecurityUtil.getReadUsers(values); - List otherReadUsers = getReadUsersFromReadWriteIdentifiers(values); - - if (readUsers == null) { - return otherReadUsers; - } - - if (otherReadUsers != null) { - readUsers.addAll(otherReadUsers); - } - - return readUsers; - } - - private boolean hasIdentifierAdminUserAccess(SecurityInfo secInfo, IdentifierMetadata values) - throws InvalidIdentifierException, NamingAuthorityConfigurationException { - - if (hasAdminUserAccess(secInfo, values) || hasSystemAdminUserAccess(secInfo)) { - return true; - } - - return false; - } - - // Checks if user is in ADMIN_USERS in system identifier - private synchronized boolean hasSystemAdminUserAccess(SecurityInfo secInfo) { - if (userAccess(secInfo.getUser(), SecurityUtil.getAdminUsers(systemValues)) == Access.GRANTED) { - return true; - } - return false; - } - - // - // Checks whether user is an ADMIN_USER - // - private boolean hasAdminUserAccess(SecurityInfo secInfo, IdentifierMetadata values) - throws InvalidIdentifierException, NamingAuthorityConfigurationException { - - // Check locally defined ADMIN_USERS list - Access access = userAccess(secInfo.getUser(), SecurityUtil.getAdminUsers(values)); - if (access == Access.GRANTED) { - // No further checks needed - return true; - } - - // Check ADMIN_USERS defined by ADMIN_IDENTIFIERS - Access rwAccess = userAccess(secInfo.getUser(), getAdminUsersFromAdminIdentifiers(values)); - if (rwAccess == Access.GRANTED) { - return true; - } - - return false; - } - - /**** - * Checks whether user has WRITE_USER permission. Default is "true" if there - * are no security settings (no WRITE_USERS key defined) - */ - private boolean hasWriteUserAccess(SecurityInfo secInfo, IdentifierMetadata values) - throws InvalidIdentifierException, NamingAuthorityConfigurationException { - - // Check locally defined WRITE_USERS list - Access access = userAccess(secInfo.getUser(), SecurityUtil.getWriteUsers(values)); - if (access == Access.GRANTED) { - return true; - } - - // Check WRITE_USERS defined by READWRITE_IDENTIFIERS - Access rwAccess = userAccess(secInfo.getUser(), getWriteUsersFromReadWriteIdentifiers(values)); - if (rwAccess != Access.NOSECURITY) { - access = rwAccess; - } - - if (access == Access.DENIED) { - return false; - } - - // Access is granted in the absence of a WRITE_USERS key - return true; - } - - private Access userAccess(String requestingUser, List authorizedUsers) { - if (authorizedUsers == null) { - return Access.NOSECURITY; - } - - if (authorizedUsers.contains(requestingUser)) { - return Access.GRANTED; - } - - return Access.DENIED; - } - - // - // Returns WRITE_USERS listed by any READWRITE_IDENTIFIERS - // - private List getWriteUsersFromReadWriteIdentifiers(IdentifierMetadata values) - throws InvalidIdentifierException, NamingAuthorityConfigurationException { - - List writers = null; - - List rwIdentifiers = SecurityUtil.getReadWriteIdentifiers(values); - if (rwIdentifiers != null) { - for (String identifier : rwIdentifiers) { - List writeUsers = SecurityUtil.getWriteUsers(loadSecurityIdentifier(identifier)); - if (writeUsers != null) { - if (writers == null) { - writers = new ArrayList(); - } - writers.addAll(writeUsers); - } - } - } - - return writers; - } - - // - // Returns READ_USERS listed by any READWRITE_IDENTIFIERS - // - private List getReadUsersFromReadWriteIdentifiers(IdentifierMetadata values) - throws InvalidIdentifierException, NamingAuthorityConfigurationException { - - List readers = null; - - List rwIdentifiers = SecurityUtil.getReadWriteIdentifiers(values); - if (rwIdentifiers != null) { - for (String identifier : rwIdentifiers) { - List readUsers = SecurityUtil.getReadUsers(loadSecurityIdentifier(identifier)); - if (readUsers != null) { - if (readers == null) { - readers = new ArrayList(); - } - readers.addAll(readUsers); - } - } - } - - return readers; - } - - // - // Returns ADMIN_USERS listed by any ADMIN_IDENTIFIERS - // - private List getAdminUsersFromAdminIdentifiers(IdentifierMetadata values) - throws InvalidIdentifierException, NamingAuthorityConfigurationException { - - List allAdmins = null; - - List adminIdentifiers = SecurityUtil.getAdminIdentifiers(values); - if (adminIdentifiers != null) { - for (String identifier : adminIdentifiers) { - List admins = SecurityUtil.getAdminUsers(loadSecurityIdentifier(identifier)); - - if (admins != null) { - if (allAdmins == null) { - allAdmins = new ArrayList(); - } - allAdmins.addAll(admins); - } - } - } - - return allAdmins; - } - - // - // Looks at READ security settings at the key level. - // Key security is determined by looking at the READWRITE_IDENTIFIER - // attached to the key. - // - private Access getKeyReadAccess(SecurityInfo secInfo, URI rwIdentifier) throws InvalidIdentifierException, - NamingAuthorityConfigurationException { - - if (rwIdentifier == null || rwIdentifier.normalize().toString().length() == 0) { - // no security at key level - return Access.NOSECURITY; - } - - List readers = SecurityUtil.getReadUsers(loadIdentifier(rwIdentifier)); - - return userAccess(secInfo.getUser(), readers); - } - - // - // Looks at WRITE security settings at the key level. - // Key security is determined by looking at the READWRITE_IDENTIFIER - // attached to the key. - // - private Access getKeyWriteAccess(SecurityInfo secInfo, URI rwIdentifier) throws InvalidIdentifierException, - NamingAuthorityConfigurationException { - - if (rwIdentifier == null || rwIdentifier.normalize().toString().length() == 0) { - // no security at key level - return Access.NOSECURITY; - } - - List writers = SecurityUtil.getWriteUsers(loadIdentifier(rwIdentifier)); - - return userAccess(secInfo.getUser(), writers); - } - - private synchronized void replaceSystemValues(SecurityInfo secInfo, IdentifierMetadata resolvedValues) { - systemValues = resolvedValues; - LOG.debug("System identifier updated by [" + secInfo.getUser() + "]"); - } - - private synchronized void createSystemIdentifier() { - systemValues = new IdentifierMetadata(); - Collection valCol = new ArrayList(); - systemValues.setLocalIdentifier(SecurityUtil.LOCAL_SYSTEM_IDENTIFIER); - systemValues.setValues(valCol); - - // - // PUBLIC_CREATION is true by default - // - valCol.add(new IdentifierValueKey(Keys.PUBLIC_CREATION, new String[] { SecurityUtil.PUBLIC_CREATION_YES }, null)); - - // - // ADMIN_USERS is an empty list by default - // - valCol.add(new IdentifierValueKey(Keys.ADMIN_USERS, new String[] {}, null)); - save(systemValues); - } - - /******* - * This method is used to validate the security info of the user. - * - * @param secInfo - * @return - */ - private SecurityInfo validateSecurityInfo(SecurityInfo secInfo) { - if (secInfo == null || secInfo.getUser() == null) { - return new SecurityInfoImpl(""); - } - - return secInfo; - } - - /****** - * This method is used to load the security info of an identifier. - * - * @param identifier - * @return - * @throws InvalidIdentifierException - * @throws NamingAuthorityConfigurationException - */ - private IdentifierMetadata loadSecurityIdentifier(String identifier) throws InvalidIdentifierException, - NamingAuthorityConfigurationException { - - try { - return loadIdentifier(new URI(identifier)); - } - catch (URISyntaxException e) { - LOG.error(IdentifierUtil.getStackTrace(e)); - throw new NamingAuthorityConfigurationException("Referred security identifier is bad [" + identifier + "]"); - } - } - - /****** - * This method is used to validate the identifier pattern. - * - * @param identifier - * @throws InvalidIdentifierException - */ - private void validateIdentifierPattern(String identifier) throws InvalidIdentifierException { - - if (StringUtils.isBlank(identifier)) { - return; - } - try { - UUID temp = UUID.fromString(identifier); - } - catch (IllegalArgumentException e) { - LOG.warn("Invalid Identifier " + identifier); - throw new InvalidIdentifierException("identifier is not valid"); - } - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.dao; + +import edu.internet2.middleware.grouper.GroupNotFoundException; +import gov.nih.nci.cagrid.gridgrouper.client.GridGrouper; +import gov.nih.nci.cagrid.gridgrouper.grouper.GrouperI; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.UUID; + +import javax.persistence.NonUniqueResultException; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; +import org.cagrid.identifiers.namingauthority.InvalidIdentifierValuesException; +import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; +import org.cagrid.identifiers.namingauthority.NamingAuthoritySecurityException; +import org.cagrid.identifiers.namingauthority.SecurityInfo; +import org.cagrid.identifiers.namingauthority.domain.IdentifierData; +import org.cagrid.identifiers.namingauthority.domain.IdentifierValues; +import org.cagrid.identifiers.namingauthority.domain.KeyData; +import org.cagrid.identifiers.namingauthority.domain.KeyValues; +import org.cagrid.identifiers.namingauthority.hibernate.IdentifierMetadata; +import org.cagrid.identifiers.namingauthority.hibernate.IdentifierValueKey; +import org.cagrid.identifiers.namingauthority.impl.IdentifierGeneratorImpl; +import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; +import org.cagrid.identifiers.namingauthority.util.Constant; +import org.cagrid.identifiers.namingauthority.util.IdentifierUtil; +import org.cagrid.identifiers.namingauthority.util.Keys; +import org.cagrid.identifiers.namingauthority.util.SecurityUtil; +import org.cagrid.identifiers.namingauthority.util.SecurityUtil.Access; +import org.cagrid.identifiers.namingauthority.util.Tree; + +public class IdentifierMetadataDao extends AbstractDao { + + protected final static Log LOG = LogFactory.getLog(IdentifierMetadataDao.class.getName()); + public static final String PUBLISHER = "PUBLISHER"; + public static final String TYPE = "TYPE"; + public static final String GSID = "GSID"; + public static final String SITE = "SITE"; + public static final String SITE_DATA = "SITEDATA"; + private IdentifierMetadata systemValues; + private URI prefix; + private String grouperURL; + private String groupName; + + public String getGrouperURL() { + return grouperURL; + } + + public void setGrouperURL(String grouperURL) { + this.grouperURL = grouperURL; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + @Override + public Class domainClass() { + return IdentifierMetadata.class; + } + + /****** + * initializer. + * + * @param prefix + * prefix to be used for the representing data. + * @throws NamingAuthorityConfigurationException + */ + public synchronized void initialize(URI prefix) throws NamingAuthorityConfigurationException { + this.prefix = prefix; + try { + systemValues = loadLocalIdentifier(SecurityUtil.LOCAL_SYSTEM_IDENTIFIER); + } + catch (InvalidIdentifierException e) { + LOG.debug("No system identifier defined"); + createSystemIdentifier(); + } + } + + /****** + * This method is used to load the data of an identifier without prefix. + * + * @param identifier + * unprefixed identifier for which the data has to be loaded. + * @return identifier data in the form of IdentifierMetaData. + * @throws InvalidIdentifierException + * @throws NamingAuthorityConfigurationException + */ + public IdentifierMetadata loadLocalIdentifier(final URI localIdentifier) throws InvalidIdentifierException, + NamingAuthorityConfigurationException { + LOG.debug("The local identifier is " + localIdentifier); + List results = getHibernateTemplate().find( + "SELECT md FROM " + domainClass().getName() + " md WHERE md.localIdentifier = ?", + new Object[] { localIdentifier }); + IdentifierMetadata result = null; + if (results.size() > 1) { + throw new NonUniqueResultException("Found " + results.size() + " " + domainClass().getName() + " objects."); + } + else if (results.size() == 1) { + result = results.get(0); + } + if (result == null) { + throw new InvalidIdentifierException("Local identifier (" + localIdentifier + ") does not exist"); + } + return result; + } + + /****** + * This method is used to load the data of an identifier with prefix. + * + * @param identifier + * prefixed identifier for which the data has to be loaded. + * @return identifier data in the form of IdentifierMetaData. + * @throws InvalidIdentifierException + * @throws NamingAuthorityConfigurationException + */ + public IdentifierMetadata loadIdentifier(URI identifier) throws InvalidIdentifierException, + NamingAuthorityConfigurationException { + return loadLocalIdentifier(IdentifierUtil.getLocalName(prefix, identifier)); + } + + /****** + * This method is get the site data from its identifier. note: Site is used + * to store the user information. + * + * @param localIdentifier + * @return IdentifierMetaData instance containing site data. + * @throws InvalidIdentifierException + * @throws NamingAuthorityConfigurationException + */ + public List getSiteData(URI localIdentifier) throws InvalidIdentifierException, + NamingAuthorityConfigurationException { + LOG.debug("The local identifier is " + localIdentifier); + List results = getHibernateTemplate() + .find("SELECT md FROM " + + domainClass().getName() + + " as md INNER JOIN md.values as value INNER JOIN value.values as val WHERE value.key='GSID' and val=?", + new Object[] { localIdentifier.toString() }); + return results; + } + + /**** + * Returns keys associated with the given identifier + */ + public String[] getKeyNames(SecurityInfo secInfo, java.net.URI identifier) throws InvalidIdentifierException, + NamingAuthoritySecurityException, NamingAuthorityConfigurationException { + IdentifierData values = null; + try { + values = getIdentifierData(secInfo, identifier, null); + } + catch (InvalidIdentifierValuesException e) { + throw new NamingAuthorityConfigurationException(e); + } + if (values != null) { + return values.getKeys(); + } + return null; + } + + /**** + * Returns values associated with a key in the given identifier + */ + public KeyData getKeyData(SecurityInfo secInfo, URI identifier, String key) throws InvalidIdentifierException, + NamingAuthoritySecurityException, NamingAuthorityConfigurationException, InvalidIdentifierValuesException { + IdentifierData values = getIdentifierData(secInfo, identifier, key); + if (values != null && values.getValues(key) != null) { + return values.getValues(key); + } + return null; + } + + /**** + * Resolves an identifier to its associated meta-data + */ + public IdentifierData resolveIdentifier(SecurityInfo secInfo, java.net.URI identifier) + throws InvalidIdentifierException, NamingAuthoritySecurityException, NamingAuthorityConfigurationException { + if (identifier == null) { + throw new InvalidIdentifierException("Identifier cannot be null."); + } + try { + if (!identifier.toString().startsWith(prefix.toString())) { + try { + identifier = IdentifierUtil.build(prefix, identifier); + } + catch (Exception e) { + LOG.debug(identifier + " is not a prefixed URI."); + } + } + LOG.debug("the identifier is " + identifier); + IdentifierData completeData = getIdentifierData(secInfo, identifier, null); + identifier = IdentifierUtil.getLocalName(prefix, identifier); + List siteData = getSiteData(identifier); + if (CollectionUtils.isNotEmpty(siteData)) { + LOG.debug("site data size is " + siteData.size()); + int counter = 0; + for (IdentifierMetadata metaData : siteData) { + IdentifierData currentData = IdentifierUtil.convert(metaData.getValues()); + for (String key : currentData.getKeys()) { + if (PUBLISHER.equalsIgnoreCase(key)) { + KeyData data = currentData.getValues(key); + String publisherIdentifier = data.getValues().get(0); + try { + URI publisherURI = new URI(prefix + publisherIdentifier); + IdentifierData siteIdentifier = getIdentifierData(secInfo, publisherURI, null); + if (siteIdentifier != null) { + for (String key1 : siteIdentifier.getKeys()) { + LOG.debug("the key1 is " + key1); + if (!TYPE.equalsIgnoreCase(key1)) { + completeData.put(counter + ":" + key1, siteIdentifier.getValues(key1)); + } + } + } + } + catch (Exception e) { + throw new InvalidIdentifierException(); + } + } + else if (!GSID.equalsIgnoreCase(key) && !TYPE.equalsIgnoreCase(key)) { + LOG.debug("the key is " + key); + completeData.put(counter + ":" + key, currentData.getValues(key)); + } + } + counter++; + } + } + return completeData; + } + catch (InvalidIdentifierValuesException e) { + throw new NamingAuthorityConfigurationException(e); + } + } + + /**** + * A user can read a key from an identifier if any one of the below + * conditions are met: + * + * (a) User is identifier's administrator - User is listed by ADMIN_USERS + * key, or - User is listed by ADMIN_IDENTIFIERS's ADMIN_USERS key, or - + * User is listed by root identifier's ADMIN_USERS key + * + * (b) User is listed by the key's READWRITE_IDENTIFIER's READ_USERS list + * (c) Key has no READWRITE_IDENTIFIER.READ_USERS and user is listed by + * identifier's READ_USERS (d) Key has no READWRITE_IDENTIFIER.READ_USERS + * and user is listed by identifier's READWRITE_IDENTIFIERS.READ_USERS (e) + * No READ_USERS keys at any level (key & identifier) + * + * A security exception is thrown if the identifier has keys and none are + * returned due to permission checks. + */ + public IdentifierData getIdentifierData(SecurityInfo secInfo, java.net.URI identifier, String keyName) + throws InvalidIdentifierException, NamingAuthoritySecurityException, NamingAuthorityConfigurationException, + InvalidIdentifierValuesException { + secInfo = validateSecurityInfo(secInfo); + IdentifierMetadata tmpValues = loadIdentifier(identifier); + if (tmpValues == null) { + return null; + } + if (hasIdentifierAdminUserAccess(secInfo, tmpValues)) { + // + // User is ADMIN_USER + // + return IdentifierUtil.convert(tmpValues.getValues()); + } + Collection valueCol = tmpValues.getValues(); + if (CollectionUtils.isEmpty(valueCol)) { + return null; + } + if (keyName != null) { + IdentifierValueKey searchKey = new IdentifierValueKey(); + searchKey.setKey(keyName); + if (!valueCol.contains(searchKey)) { + throw new InvalidIdentifierValuesException("Key [" + keyName + "] does not exist"); + } + } + Access identifierReadAccess = null; + IdentifierData newValues = new IdentifierData(); + for (IdentifierValueKey ivk : valueCol) { + if (keyName != null && !keyName.equals(ivk.getKey())) { + continue; + } + Access keyAccess = getKeyReadAccess(secInfo, ivk.getPolicyIdentifier()); + if (keyAccess == Access.GRANTED) { + LOG.debug("SECURITY: User [" + secInfo.getUser() + "] can access key [" + ivk.getKey() + "]"); + newValues.put(ivk.getKey(), IdentifierUtil.convert(ivk)); + } + else if (keyAccess == Access.DENIED) { + LOG.debug("SECURITY: User [" + secInfo.getUser() + "] can't access key [" + ivk.getKey() + "]"); + } + else if (keyAccess == Access.NOSECURITY) { + LOG.debug("SECURITY: No key security for [" + ivk.getKey() + "]. Checking identifier security..."); + // Apply identifier level security + if (identifierReadAccess == null) { + List identifierReadUsers = getAllReadUsers(tmpValues); + identifierReadAccess = userAccess(secInfo.getUser(), identifierReadUsers); + } + if (identifierReadAccess == Access.DENIED) { + LOG.debug("SECURITY: User [" + secInfo.getUser() + "] is NOT authorized to read key [" + + ivk.getKey() + "] by identifier"); + } + else { + LOG.debug("SECURITY: User [" + secInfo.getUser() + "] is authorized to read [" + ivk.getKey() + + "] by identifier"); + newValues.put(ivk.getKey(), IdentifierUtil.convert(ivk)); + } + } + } + // Is this the only case when we bark? + if (newValues.getKeys() == null || newValues.getKeys().length == 0) { + String msg; + if (keyName != null) { + msg = "resolve identifier key [" + keyName + "]"; + } + else { + msg = "resolve identifier"; + } + throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, msg)); + } + return newValues; + } + + /**** + * Persists the provided identifier with the given values + */ + public void createIdentifier(SecurityInfo secInfo, URI localIdentifier, IdentifierData ivalues) + throws InvalidIdentifierException, NamingAuthorityConfigurationException, NamingAuthoritySecurityException { + LOG.debug("The value of localIdentifier is " + localIdentifier); + secInfo = validateSecurityInfo(secInfo); + createIdentifierSecurityChecks(secInfo); + save(IdentifierUtil.convert(localIdentifier, ivalues)); + } + + /**** + * Adds the provided keys to the given identifier. + * + * An exception is thrown if any of the provided keys already exists. + * + * Permissions: + * + * Case 1) Creating security-type keys as defined by Keys.isAdminKey() A + * user can create security-type keys if s/he is explicitly listed as an + * ADMIN_USER by either the identifier, or the system (root) identifier. + * + * Case 2) Creating other keys A user can create other keys if s/he is + * listed as a WRITE_USER by the identifier, or if a WRITE_USERS key is not + * configured by the identifier. + * + * Identifier's ADMIN_USERS can create keys of any type. It is unnecessary + * to list them as WRITE_USERS. + */ + public void createKeys(SecurityInfo secInfo, URI identifier, IdentifierData values) + throws InvalidIdentifierException, NamingAuthoritySecurityException, InvalidIdentifierValuesException, + NamingAuthorityConfigurationException { + Boolean writerAccess = null; + Boolean adminAccess = null; + if (values == null || values.getKeys() == null || values.getKeys().length == 0) { + throw new InvalidIdentifierValuesException("No keys were provided"); + } + secInfo = validateSecurityInfo(secInfo); + URI localIdentifier = IdentifierUtil.getLocalName(prefix, identifier); + IdentifierMetadata resolvedValues = loadLocalIdentifier(localIdentifier); + Collection valueKeys = resolvedValues.getValues(); + for (String key : values.getKeys()) { + // Start of security checks + if (Keys.isAdminKey(key)) { + if (adminAccess == null) { + adminAccess = hasIdentifierAdminUserAccess(secInfo, resolvedValues); + } + if (!adminAccess) { + throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, "create key [" + key + + "]. Not an ADMIN_USER")); + } + } + else { + if (writerAccess == null) { + writerAccess = hasWriteUserAccess(secInfo, resolvedValues); + } + if (!writerAccess) { + // + // Check if user is administrator + // + if (adminAccess == null) { + adminAccess = hasIdentifierAdminUserAccess(secInfo, resolvedValues); + } + if (!adminAccess) { + throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, + "create keys. Neither WRITE_USER nor ADMIN_USER")); + } + } + } + // End of security checks + IdentifierValueKey ivk = IdentifierUtil.convert(key, values.getValues(key)); + if (valueKeys.contains(ivk)) { + throw new InvalidIdentifierValuesException("Key [" + key + "] already exists for identifier [" + + identifier.normalize().toString() + "]"); + } + valueKeys.add(ivk); + } + save(resolvedValues); + if (SecurityUtil.isSystemIdentifier(localIdentifier)) { + replaceSystemValues(secInfo, resolvedValues); + } + } + + /**** + * Deletes the provided keys from the given identifier. + * + * An exception is thrown if any of the provided keys does not exist. + * + * Permissions: + * + * Case 1) Deleting security-type keys as defined by Keys.isAdminKey() A + * user can delete security-type keys if s/he is explicitly listed as an + * ADMIN_USER by either the identifier, or the system (root) identifier. + * + * Case 2) Deleting other keys A user can delete other keys if s/he is + * listed as a WRITE_USER by the identifier, or if a WRITE_USERS key is not + * configured by the identifier. + * + * Identifier's ADMIN_USERS can delete keys of any type. It is unnecessary + * to list them as WRITE_USERS. + */ + public void deleteKeys(SecurityInfo secInfo, URI identifier, String[] keyList) throws InvalidIdentifierException, + NamingAuthoritySecurityException, InvalidIdentifierValuesException, NamingAuthorityConfigurationException { + if (keyList == null || keyList.length == 0) { + throw new InvalidIdentifierValuesException("No keys were provided"); + } + secInfo = validateSecurityInfo(secInfo); + Boolean writerAccess = null; + Boolean adminAccess = null; + URI localIdentifier = IdentifierUtil.getLocalName(prefix, identifier); + IdentifierMetadata resolvedValues = loadLocalIdentifier(localIdentifier); + if (resolvedValues.getValues() == null || resolvedValues.getValues().isEmpty()) { + throw new InvalidIdentifierValuesException("Identifier [" + identifier + "] has no keys"); + } + LOG.debug("User [" + secInfo.getUser() + "] deleting some keys for identifier [" + identifier.toString() + "]"); + List keysToDelete = new ArrayList(); + ArrayList keyNames = new ArrayList(Arrays.asList(keyList)); + for (IdentifierValueKey ivk : resolvedValues.getValues()) { + if (!keyNames.contains(ivk.getKey())) { + continue; + } + // Start of security checks + if (Keys.isAdminKey(ivk.getKey())) { + if (adminAccess == null) { + adminAccess = hasIdentifierAdminUserAccess(secInfo, resolvedValues); + } + if (!adminAccess) { + throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, + "delete key [" + ivk.getKey() + "]. Not an ADMIN_USER")); + } + } + else { + if (writerAccess == null) { + writerAccess = hasWriteUserAccess(secInfo, resolvedValues); + } + if (!writerAccess) { + // + // Check if user is administrator + // + if (adminAccess == null) { + adminAccess = hasIdentifierAdminUserAccess(secInfo, resolvedValues); + } + if (!adminAccess) { + throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, + "delete keys. Neither WRITE_USER nor ADMIN_USER")); + } + } + } + // End of security checks + LOG.debug("Removing key [" + ivk.getKey() + "]"); + keysToDelete.add(ivk); + } + if (keysToDelete.size() != keyNames.size()) { + // Unrecognized key. Should we actually fail this? + String missingKeys = ""; + for (String key : keyNames) { + if (!keysToDelete.contains(key)) { + if (missingKeys.equals("")) + missingKeys += key; + else + missingKeys += ", " + key; + } + } + throw new InvalidIdentifierValuesException("Unexpected keys found in the request [" + missingKeys + "]"); + } + if (keysToDelete.size() > 0) { + getHibernateTemplate().deleteAll(keysToDelete); + resolvedValues.getValues().removeAll(keysToDelete); + } + save(resolvedValues); + if (SecurityUtil.isSystemIdentifier(localIdentifier)) { + replaceSystemValues(secInfo, resolvedValues); + } + } + + /**** + * Replaces the values associated with existing keys with the new provided + * values. + * + * An exception is thrown if any of the provided keys does not exist + * + * Permissions: + * + * Identifier's ADMIN_USERS can replace any key values + * + * Security-type key values can only be replaced by ADMIN_USERS + * + * Regular users can replace the values for a key if s/he is listed as a + * WRITE_USER for that key. + * + * When no WRITE_USERS key is defined at the key level, the user must be + * listed as a WRITE_USER for the identifier. + * + * When no WRITE_USERS key is defined for either the key or the identifier, + * any user can replace the values. + */ + public void replaceKeyValues(SecurityInfo secInfo, URI identifier, IdentifierValues newValues) + throws InvalidIdentifierException, NamingAuthoritySecurityException, InvalidIdentifierValuesException, + NamingAuthorityConfigurationException { + if (newValues == null || newValues.getKeys() == null || newValues.getKeys().length == 0) { + throw new InvalidIdentifierValuesException(Constant.NO_KEY_VALUES); + } + secInfo = validateSecurityInfo(secInfo); + URI localIdentifier = IdentifierUtil.getLocalName(prefix, identifier); + IdentifierMetadata resolvedValues = loadLocalIdentifier(localIdentifier); + if (resolvedValues.getValues() == null || resolvedValues.getValues().isEmpty()) { + throw new InvalidIdentifierValuesException("Identifier [" + identifier + "] has no keys"); + } + Boolean identifierAdminAccess = hasIdentifierAdminUserAccess(secInfo, resolvedValues); + Boolean identifierWriteAccess = null; + ArrayList keysToReplace = new ArrayList(Arrays.asList(newValues.getKeys())); + for (IdentifierValueKey ivk : resolvedValues.getValues()) { + if (!keysToReplace.contains(ivk.getKey())) { + continue; + } + if (!identifierAdminAccess) { + if (Keys.isAdminKey(ivk.getKey())) { + String error = SecurityUtil.securityError(secInfo, "replace key [" + ivk.getKey() + + "]. Not an ADMIN_USER"); + LOG.error(error); + throw new NamingAuthoritySecurityException(error); + } + // + // Check key level security using key's read-write identifier + // + Access keyAccess = getKeyWriteAccess(secInfo, ivk.getPolicyIdentifier()); + if (keyAccess == Access.DENIED) { + // + // WRITE_USERS defined for key and this user is not listed + // + String error = SecurityUtil.securityError(secInfo, "replace key [" + ivk.getKey() + + "]. Not a WRITE_USER"); + LOG.error(error); + throw new NamingAuthoritySecurityException(error); + } + if (keyAccess == Access.NOSECURITY) { + // + // Fall back to identifier level security + // + if (identifierWriteAccess == null) { + identifierWriteAccess = hasWriteUserAccess(secInfo, resolvedValues); + } + + if (!identifierWriteAccess) { + // + // WRITE_USERS defined identifier and this user is not + // listed + // + String error = SecurityUtil.securityError(secInfo, "replace key [" + ivk.getKey() + + "]. Not a WRITE_USER"); + LOG.error(error); + throw new NamingAuthoritySecurityException(error); + } + } + } + keysToReplace.remove(ivk.getKey()); + KeyValues kvs = newValues.getValues(ivk.getKey()); + ivk.setValues(kvs.getValues()); + } + + if (keysToReplace.size() > 0) { + throw new InvalidIdentifierValuesException("Key [" + keysToReplace.get(0) + + "] does not exist for identifier [" + identifier.normalize().toString() + "]"); + } + save(resolvedValues); + // Save system identifier if necessary + if (SecurityUtil.isSystemIdentifier(localIdentifier)) { + replaceSystemValues(secInfo, resolvedValues); + } + } + + /**** + * Adds administrator identity to system identifier + */ + public synchronized void createInitialAdministrator(String identity) throws NamingAuthorityConfigurationException { + if (systemValues == null || systemValues.getValues() == null) { + throw new NamingAuthorityConfigurationException("No system values. Please initialize DAO first"); + } + + IdentifierValueKey adminKey = null; + Collection valCol = systemValues.getValues(); + for (IdentifierValueKey ivk : valCol) { + if (ivk.getKey().equals(Keys.ADMIN_USERS)) { + adminKey = ivk; + break; + } + } + if (adminKey == null) { + adminKey = new IdentifierValueKey(); + valCol.add(adminKey); + } + if (adminKey.getValues() != null && adminKey.getValues().size() > 0) { + throw new NamingAuthorityConfigurationException("An administrator already exists"); + } + ArrayList values = new ArrayList(); + values.add(identity); + adminKey.setValues(values); + save(systemValues); + } + + /****** + * This method is used to register an identifier. At the end of this method + * an identifier is generated and saved in the persistent store. If + * suggestedIdentifier is set to null then a new identifier is created and + * is returned. If suggestedIdentifier is not null then system uses this + * identifier only if the identifier does not exists in the persistent store + * otherwise it creates a new identifier, saves it and returns the newly + * created identifier. + * + * @param secInfo + * provides the information about the user. + * @param suggestedIdentifier + * is an identifier that a user would like to register. + * @param parentIdentifiers + * used to represent if current identifier should be child of any + * existing identifiers or not. + * @return an identifier. + * @throws NamingAuthorityConfigurationException + * @throws InvalidIdentifierValuesException + * @throws InvalidIdentifierException + * @throws NamingAuthoritySecurityException + */ + public String registerGSID(SecurityInfo secInfo, String suggestedIdentifier, String[] parentIdentifiers) + throws NamingAuthorityConfigurationException, InvalidIdentifierValuesException, InvalidIdentifierException, + NamingAuthoritySecurityException { + checkSecurity(secInfo, false, true); + String userName = secInfo.getUser(); + String publisherIdentifier = getIdentifierFromUser(userName); + String temp = null; + List keys = new ArrayList(); + List values = new ArrayList(); + if (StringUtils.isNotBlank(suggestedIdentifier)) { + validateIdentifierPattern(suggestedIdentifier); + } + if (parentIdentifiers != null && parentIdentifiers.length > 0) { + for (String parent : parentIdentifiers) + LOG.debug("the parent is " + parent); + String value = ""; + String total_value = ""; + boolean atleastOneParent = false; + for (int i = 0; i < parentIdentifiers.length; i++) { + value = parentIdentifiers[i]; + if (StringUtils.isNotBlank(value)) { + if (StringUtils.isNotBlank(suggestedIdentifier) && StringUtils.isNotBlank(suggestedIdentifier) + && value.equals(suggestedIdentifier)) { + // throw an exception saying that an suggestedIdentifier + // cannot be a parent. + throw new InvalidIdentifierValuesException("Violation: suggested identifier " + + suggestedIdentifier + " is also present in parent identifiers array"); + } + total_value += value + ","; + atleastOneParent = true; + } + } + if (atleastOneParent) { + // remove last comma. + total_value = total_value.substring(0, total_value.length() - 1); + keys.add("parent"); + values.add(total_value); + } + } + keys.add(TYPE); + values.add(GSID); + temp = suggestedIdentifier = createIdentifier(secInfo, suggestedIdentifier, keys, values); + if (suggestedIdentifier != null) { + // second transaction. + keys = new ArrayList(); + values = new ArrayList(); + keys.add(PUBLISHER); + values.add(publisherIdentifier); + keys.add(GSID); + values.add(suggestedIdentifier); + keys.add(TYPE); + values.add(SITE_DATA); + createIdentifier(secInfo, null, keys, values); + } + return temp; + + } + + /****** + * This method is used to register a site for a user. + * + * @param secInfo + * grid credentials for the user. + * @param application + * @param applicationURL + * @param applicationVersion + * @param contactName + * @param contactEmail + * @param contactPhone + * @param organization + * @throws NamingAuthorityConfigurationException + * @throws InvalidIdentifierValuesException + * @throws InvalidIdentifierException + * @throws NamingAuthoritySecurityException + */ + public void registerSite(SecurityInfo secInfo, String application, String applicationURL, + String applicationVersion, String contactName, String contactEmail, String contactPhone, String organization) + throws NamingAuthorityConfigurationException, InvalidIdentifierValuesException, InvalidIdentifierException, + NamingAuthoritySecurityException { + checkSecurity(secInfo, false, false); + List keys = new ArrayList(); + List values = new ArrayList(); + if (StringUtils.isBlank(application)) { + throw new InvalidIdentifierValuesException("application value cannot be null"); + } + else if (StringUtils.isBlank(applicationURL)) { + throw new InvalidIdentifierValuesException("application url value cannot be null"); + } + else if (StringUtils.isBlank(applicationVersion)) { + throw new InvalidIdentifierValuesException("applicaiton version value cannot be null"); + } + else if (StringUtils.isBlank(contactName)) { + throw new InvalidIdentifierValuesException("contact name value cannot be null"); + } + else if (StringUtils.isBlank(contactEmail)) { + throw new InvalidIdentifierValuesException("contact email value cannot be null"); + } + else if (StringUtils.isBlank(contactPhone)) { + throw new InvalidIdentifierValuesException("contact phone value cannot be null"); + } + else if (StringUtils.isBlank(organization)) { + throw new InvalidIdentifierValuesException("organization value cannot be null"); + } + + String[] tempValues = { application, applicationURL, applicationVersion, contactEmail, contactName, + contactPhone, organization, secInfo.getUser() }; + String[] fixedKeys = { "application", "applicationUrl", "applicationVersion", "contactEmail", "contactName", + "contactPhone", "organization", "userName" }; + for (int i = 0; i < fixedKeys.length; i++) { + if (tempValues[i] == null || tempValues[i].trim().length() == 0) { + throw new InvalidIdentifierException(); + } + keys.add(fixedKeys[i]); + values.add(tempValues[i]); + } + keys.add(TYPE); + values.add(SITE); + createIdentifier(secInfo, null, keys, values); + } + + /****** + * This method is used to add a site to existing identifier. + * + * @param secInfo + * security info of the user. + * @param identifier + * identifier to which user would like to add his/her site. + * @throws NamingAuthorityConfigurationException + * @throws InvalidIdentifierValuesException + * @throws InvalidIdentifierException + * @throws NamingAuthoritySecurityException + */ + public void addSite(SecurityInfo secInfo, String identifier) throws NamingAuthorityConfigurationException, + InvalidIdentifierValuesException, InvalidIdentifierException, NamingAuthoritySecurityException { + checkSecurity(secInfo, true, true); + if (StringUtils.isBlank(identifier)) { + throw new InvalidIdentifierException("Identifier cannot be null."); + } + validateIdentifierPattern(identifier); + URI identifierURI = null; + try { + identifierURI = new URI(identifier); + } + catch (URISyntaxException e) { + throw new InvalidIdentifierException("Unable to parse identifier."); + } + IdentifierMetadata imd = loadLocalIdentifier(identifierURI); + if (imd == null) { + throw new InvalidIdentifierException("Identifier does not exists."); + } + String userName = secInfo.getUser(); + String publisherIdentifier = getIdentifierFromUser(userName); + List keys = new ArrayList(); + List values = new ArrayList(); + keys.add(TYPE); + values.add(SITE_DATA); + keys.add(PUBLISHER); + values.add(publisherIdentifier); + keys.add(GSID); + values.add(identifier); + createIdentifier(secInfo, null, keys, values); + } + + /****** + * This method is used to validates the identifier. Validation checks if the + * identifier is in the database or not. if exists returns false else + * returns true. + * + * @param secInfo + * secInfo of the user not a mandatory parameter. + * @param identifier + * identifier for which validation is done. + * @return true if identifier does not exists in the database. + * @throws InvalidIdentifierException + * @throws NamingAuthoritySecurityException + * @throws NamingAuthorityConfigurationException + */ + public boolean validateIdentifier(SecurityInfo secInfo, String identifier) throws InvalidIdentifierException, + NamingAuthoritySecurityException, NamingAuthorityConfigurationException { + if (identifier == null) { + throw new InvalidIdentifierException("Identifier cannot be null."); + } + validateIdentifierPattern(identifier); + try { + URI temp = new URI(identifier); + try { + IdentifierMetadata metaData = loadLocalIdentifier(temp); + if (metaData != null) + return false; + } + catch (Exception e) { + return true; + } + } + catch (URISyntaxException e) { + throw new InvalidIdentifierException("Identifier cannot parsed."); + } + + return true; + } + + /******* + * This method is used to get the parent hierarchy in the form of a tree + * with root node as identifier node. + * + * @param secInfo + * security info of the user can be null. + * @param identifier + * for which the hierarchy to be generated. + * @return Tree representing the parent hierarchy. + * @throws InvalidIdentifierException + * @throws NamingAuthoritySecurityException + * @throws NamingAuthorityConfigurationException + */ + public Tree getParentHierarchy(SecurityInfo secInfo, String identifier) throws InvalidIdentifierException, + NamingAuthoritySecurityException, NamingAuthorityConfigurationException { + if (StringUtils.isBlank(identifier)) { + throw new InvalidIdentifierException("Identifier cannot be null"); + } + validateIdentifierPattern(identifier); + List parents = new ArrayList(); + + Tree currentNode = new Tree(identifier); + Tree rootNode = currentNode; + parents.add(currentNode); + while (parents.size() != 0) { + currentNode = parents.get(0); + String tempIdentifier = (currentNode).getIdentifier(); + parents.remove(0); + IdentifierData currentKeyData = null; + try { + URI uri = null; + try { + uri = new java.net.URI(prefix + tempIdentifier); + } + catch (Exception e) { + } + if (uri != null) { + currentKeyData = getIdentifierData(secInfo, uri, "parent"); + } + } + catch (InvalidIdentifierValuesException e1) { + tempIdentifier = null; + } + if (currentKeyData != null) { + if (currentKeyData.getKeys() != null) { + for (String key : currentKeyData.getKeys()) { + KeyData values = currentKeyData.getValues(key); + // parent should have only one value so get the first + // one. + if (values != null) { + for (String value : values.getValues()) { + String tempURI = null; + try { + if (value != null) { + tempURI = value; + } + else { + LOG.debug("values is null"); + } + } + catch (Exception e) { + e.printStackTrace(); + } + if (tempURI != null) { + Tree tempNode = new Tree(tempURI); + currentNode.addChild(tempNode); + parents.add(tempNode); + } + } + } + else { + LOG.debug("values are null"); + } + } + } + else { + LOG.debug("getKeys is null"); + } + } + else { + LOG.debug("currentkeydata is null"); + } + } + LOG.debug("the tree is " + rootNode.toString(true)); + return rootNode; + } + + /******* + * This method is used to get the child hierarchy in the form of a tree with + * root node as identifier node. + * + * @param secInfo + * security info of the user can be null. + * @param identifier + * for which the hierarchy to be generated. + * @return Tree representing the child hierarchy. + * @throws InvalidIdentifierException + * @throws NamingAuthoritySecurityException + * @throws NamingAuthorityConfigurationException + */ + public Tree getChildHierarchy(SecurityInfo secInfo, String identifier) throws InvalidIdentifierException, + NamingAuthoritySecurityException, InvalidIdentifierValuesException, NamingAuthorityConfigurationException { + if (identifier == null || identifier.length() == 0) { + throw new InvalidIdentifierException("Identifier cannot be null"); + } + validateIdentifierPattern(identifier); + List parents = new ArrayList(); + Tree currentNode = new Tree(identifier); + Tree rootNode = currentNode; + parents.add(currentNode); + while (parents.size() != 0) { + currentNode = parents.get(0); + String tempIdentifier = currentNode.getIdentifier(); + parents.remove(0); + List currentChildren = getChildItems(secInfo, tempIdentifier); + if (currentChildren != null) { + if (currentChildren.size() > 0) { + for (IdentifierMetadata child : currentChildren) { + String key = child.getLocalIdentifier().toString(); + // parent should have only one value so get the first + // one. + if (key != null) { + LOG.debug("the key is " + key); + Tree tempNode = new Tree(key); + currentNode.addChild(tempNode); + parents.add(tempNode); + } + else { + LOG.debug("values are null"); + } + } + } + else { + LOG.debug("current children size is zero"); + } + } + else { + LOG.debug("current child is null"); + } + } + LOG.debug("the tree is " + rootNode.toString(true)); + return rootNode; + } + + /****** + * This method is used to get all the identifiers whose parent is the + * provided identifier. + * + * @param secInfo + * security info of the user can be null. + * @param identifier + * for which the children are found. + * @return list of IdentifierMetadata representing info of each identifier + * which have provided identifier as parent. + * @throws InvalidIdentifierException + * @throws NamingAuthoritySecurityException + * @throws InvalidIdentifierValuesException + * @throws NamingAuthorityConfigurationException + */ + public List getChildItems(SecurityInfo secInfo, String identifier) + throws InvalidIdentifierException, NamingAuthoritySecurityException, InvalidIdentifierValuesException, + NamingAuthorityConfigurationException { + validateSecurityInfo(secInfo); + List results = getHibernateTemplate() + .find("SELECT md FROM " + + domainClass().getName() + + " as md INNER JOIN md.values as value INNER JOIN value.values as val WHERE value.key='parent' and val=?", + new Object[] { identifier }); + LOG.debug("The results Size is " + results.size()); + return results; + } + + /****** + * This method is used to gets the data for all the sites. + * + * @param secInfo + * security info of the user. + * @param naPrefix + * prefix uri. + * @return list of IdentifierData representing the sites. + * @throws InvalidIdentifierException + * @throws NamingAuthoritySecurityException + * @throws InvalidIdentifierValuesException + * @throws NamingAuthorityConfigurationException + */ + public List getSitesData(SecurityInfo secInfo, URI naPrefix) throws InvalidIdentifierException, + NamingAuthoritySecurityException, InvalidIdentifierValuesException, NamingAuthorityConfigurationException { + validateSecurityInfo(secInfo); + List results = getHibernateTemplate() + .find("SELECT md FROM " + + domainClass().getName() + + " as md INNER JOIN md.values as value INNER JOIN value.values as val WHERE value.key='TYPE' and val='SITE'"); + if (results != null) { + LOG.debug("The results Size is " + results.size()); + } + List resultData = new ArrayList(); + if (results != null) { + for (IdentifierMetadata result : results) { + if (result != null) { + IdentifierData tempData = IdentifierUtil.convert(result.getValues()); + if (tempData != null) { + String identifierValue = result.getLocalIdentifier().toString(); + KeyData tempKeyData = new KeyData(tempData.getValues(tempData.getKeys()[0]) + .getPolicyIdentifier(), new String[] { identifierValue }); + tempData.put("IDENTIFIER", tempKeyData); + resultData.add(tempData); + } + } + } + } + return resultData; + } + + /****** + * This method is used to checks if parent identifiers are empty or not. + * + * @param parents + * @return true if parent identifiers are not empty and false otherwise. + */ + private boolean checkIfParentsEmpty(String[] parents) { + boolean flag = false; + if (parents != null && parents.length > 0) { + for (String parent : parents) { + if (StringUtils.isBlank(parent)) { + flag = true; + break; + } + } + } + else { + flag = true; + } + return flag; + } + + /****** + * This method is used to get the identifier of the site associated with the + * user. + * + * @param userName + * string representing user name. + * @return identifier. + */ + public String getIdentifierFromUser(String userName) { + if (StringUtils.isBlank(userName)) + return null; + String temp = null; + List results = getHibernateTemplate() + .find("SELECT md FROM " + + domainClass().getName() + + " as md INNER JOIN md.values as value INNER JOIN value.values as val WHERE value.key='userName' and val=?", + new Object[] { userName.trim() }); + if (results != null && results.size() == 1) { + URI tempGURI = results.get(0).getLocalIdentifier(); + if (tempGURI != null) { + temp = tempGURI.toString(); + } + } + return temp; + } + + /****** + * This method check if the identifier exists in the persistent code. + * + * @param identifier + * @return true if the identifier exists in the persistent and false + * otherwise. + */ + public boolean checkIfIdentifierExists(URI identifier) { + List results = getHibernateTemplate().find( + "SELECT md FROM " + domainClass().getName() + " md WHERE md.localIdentifier = ?", + new Object[] { identifier }); + return results == null || results.isEmpty() ? false : true; + } + + /****** + * This method is used to check the security based on the parameters. + * + * @param secInfo + * info representing the user. + * @param checkOnlyLogin + * if this is true then it checks if user belongs to a group or + * not. + * @param checkHasSite + * if this is true then it check if the user has registered a + * site or not. + * @throws NamingAuthoritySecurityException + */ + public void checkSecurity(SecurityInfo secInfo, boolean checkOnlyLogin, boolean checkHasSite) + throws NamingAuthoritySecurityException { + String caller = secInfo.getUser(); + if (StringUtils.isBlank(caller)) { + throw new NamingAuthoritySecurityException("Please login into the grid to identify yourselves"); + } + if (!checkOnlyLogin) { + // check for a group. + if (!isMember(caller)) { + throw new NamingAuthoritySecurityException("You should be a member of this \"" + groupName + + "\" group before you proceed."); + } + } + String Identifier = getIdentifierFromUser(caller); + if (checkHasSite) { + if (Identifier == null) { + throw new NamingAuthoritySecurityException("Please register a site before you proceed"); + } + } + else { + if (Identifier != null) { + throw new NamingAuthoritySecurityException("You have already registered a site"); + } + } + } + + /****** + * Check whether a user is member of a group or not. + * + * @param userIdentity + * @return + */ + private boolean isMember(String userIdentity) { + if ((StringUtils.isNotEmpty(grouperURL)) && (StringUtils.isNotEmpty(groupName))) { + // Create a Grid Grouper Instance + GrouperI grouper = new GridGrouper(grouperURL); + + try { + // Determine if the user is a member of the group. + boolean isMember = grouper.isMemberOf(userIdentity, groupName); + + if (isMember) { + LOG.debug("The user " + userIdentity + " is a member of " + groupName); + return true; + } + else { + LOG.debug("The user " + userIdentity + " is NOT a member of " + groupName); + return false; + } + } + catch (GroupNotFoundException e) { + LOG.debug("The group " + groupName + " does not exist, therefore the user " + userIdentity + + " is NOT a member."); + return false; + } + } + // returning true if no grouper authentication needed. + return true; + } + + /**** + * Private Stuff + */ + + /****** + * this method save the identifier into the persistent store. + * + */ + private String createIdentifier(SecurityInfo secInfo, String identifier, List keys, List values) + throws InvalidIdentifierException, NamingAuthorityConfigurationException, NamingAuthoritySecurityException { + + String temp = null; + + String[] keyArray = new String[keys.size()]; + String[][] valueArray = new String[keys.size()][]; + for (int i = 0; i < keys.size(); i++) { + keyArray[i] = keys.get(i); + String value = values.get(i); + String[] valueArr; + if (value != null && value.contains(",")) { + valueArr = value.split(","); + } + else { + valueArr = new String[1]; + valueArr[0] = value; + } + if (keys.get(i).contains("parent")) { + LOG.debug("the values are " + valueArr); + for (String valueAr1 : valueArr) { + + // org.apache.axis.types.URI axisUri = getAxisURI(valueAr1, + // builder); + LOG.debug("value Ar1 " + valueAr1); + try { + URI valueAr1URI = new URI(valueAr1); + valueAr1URI = IdentifierUtil.build(prefix, valueAr1URI); + resolveIdentifier(secInfo, valueAr1URI); + + } + catch (URISyntaxException e) { + LOG.debug("URI casting from String execption " + valueAr1); + throw new InvalidIdentifierException("Unable to convert " + valueAr1 + " "); + } + + } + } + valueArray[i] = valueArr; + } + + org.cagrid.identifiers.namingauthority.domain.IdentifierData ivs = new org.cagrid.identifiers.namingauthority.domain.IdentifierData(); + for (int i = 0; i < keyArray.length; i++) { + URI policyReference = null; + KeyData kd = new KeyData(policyReference, valueArray[i]); + ivs.put(keyArray[i], kd); + } + URI identifierURI = null; + if (identifier == null) { + identifier = (new IdentifierGeneratorImpl()).generate(null).toString(); + } + else { + try { + while (checkIfIdentifierExists(new URI(identifier))) { + identifier = (new IdentifierGeneratorImpl()).generate(null).toString(); + } + } + catch (URISyntaxException e) { + + LOG.warn("URI Syntax exception occured"); + throw new InvalidIdentifierException("URI is Invalid"); + } + } + + try { + identifierURI = new URI(identifier); + } + catch (URISyntaxException e) { + LOG.debug("URI sytanx exception occured by identifier " + identifier); + } + try { + createIdentifier(secInfo, identifierURI, ivs); + temp = identifierURI.toString(); + } + catch (NamingAuthorityConfigurationException e) { + LOG.debug("Naming authority configuration exception occured"); + throw new NamingAuthorityConfigurationException(); + } + catch (InvalidIdentifierException e) { + LOG.debug("Invalid Identifier Exception occured"); + throw new InvalidIdentifierException(); + } + catch (NamingAuthoritySecurityException e) { + LOG.debug("Naming Authority Security Exception occured"); + throw new NamingAuthoritySecurityException(); + } + return temp; + } + + /**** + * A user can create identifiers if any one of the below conditions are met: + * + * (a) PUBLIC_CREATTION key set to "Y" in root identifier (b) User is listed + * by IDENTIFIER_CREATION_USERS key in root identifier (c) No security + * settings are specified - No root identifier - No PUBLIC_CREATION key in + * root identifier + */ + private synchronized void createIdentifierSecurityChecks(SecurityInfo secInfo) throws InvalidIdentifierException, + NamingAuthorityConfigurationException, NamingAuthoritySecurityException { + + List values = SecurityUtil.getPublicCreation(systemValues); + if (values == null || values.isEmpty()) { + // no security + LOG.debug("SECURITY: No PUBLIC_CREATION"); + return; + } + + if (values.size() != 1) { + throw new NamingAuthorityConfigurationException("Bad PUBLIC_CREATION setting detected"); + } + + if (values.get(0).equalsIgnoreCase(SecurityUtil.PUBLIC_CREATION_YES)) { + // everyone can create identifiers + return; + } + + List authorizedUsers = SecurityUtil.getIdentifierCreationUsers(systemValues); + if (authorizedUsers == null || !authorizedUsers.contains(secInfo.getUser())) { + throw new NamingAuthoritySecurityException(SecurityUtil.securityError(secInfo, "create identifiers")); + } + } + + /**** + * Returns any directly specified READ_USERS plus any included by + * READWRITE_IDENTIFIERS + */ + private List getAllReadUsers(IdentifierMetadata values) throws InvalidIdentifierException, + NamingAuthorityConfigurationException { + + List readUsers = SecurityUtil.getReadUsers(values); + List otherReadUsers = getReadUsersFromReadWriteIdentifiers(values); + + if (readUsers == null) { + return otherReadUsers; + } + + if (otherReadUsers != null) { + readUsers.addAll(otherReadUsers); + } + + return readUsers; + } + + private boolean hasIdentifierAdminUserAccess(SecurityInfo secInfo, IdentifierMetadata values) + throws InvalidIdentifierException, NamingAuthorityConfigurationException { + + if (hasAdminUserAccess(secInfo, values) || hasSystemAdminUserAccess(secInfo)) { + return true; + } + + return false; + } + + // Checks if user is in ADMIN_USERS in system identifier + private synchronized boolean hasSystemAdminUserAccess(SecurityInfo secInfo) { + if (userAccess(secInfo.getUser(), SecurityUtil.getAdminUsers(systemValues)) == Access.GRANTED) { + return true; + } + return false; + } + + // + // Checks whether user is an ADMIN_USER + // + private boolean hasAdminUserAccess(SecurityInfo secInfo, IdentifierMetadata values) + throws InvalidIdentifierException, NamingAuthorityConfigurationException { + + // Check locally defined ADMIN_USERS list + Access access = userAccess(secInfo.getUser(), SecurityUtil.getAdminUsers(values)); + if (access == Access.GRANTED) { + // No further checks needed + return true; + } + + // Check ADMIN_USERS defined by ADMIN_IDENTIFIERS + Access rwAccess = userAccess(secInfo.getUser(), getAdminUsersFromAdminIdentifiers(values)); + if (rwAccess == Access.GRANTED) { + return true; + } + + return false; + } + + /**** + * Checks whether user has WRITE_USER permission. Default is "true" if there + * are no security settings (no WRITE_USERS key defined) + */ + private boolean hasWriteUserAccess(SecurityInfo secInfo, IdentifierMetadata values) + throws InvalidIdentifierException, NamingAuthorityConfigurationException { + + // Check locally defined WRITE_USERS list + Access access = userAccess(secInfo.getUser(), SecurityUtil.getWriteUsers(values)); + if (access == Access.GRANTED) { + return true; + } + + // Check WRITE_USERS defined by READWRITE_IDENTIFIERS + Access rwAccess = userAccess(secInfo.getUser(), getWriteUsersFromReadWriteIdentifiers(values)); + if (rwAccess != Access.NOSECURITY) { + access = rwAccess; + } + + if (access == Access.DENIED) { + return false; + } + + // Access is granted in the absence of a WRITE_USERS key + return true; + } + + private Access userAccess(String requestingUser, List authorizedUsers) { + if (authorizedUsers == null) { + return Access.NOSECURITY; + } + + if (authorizedUsers.contains(requestingUser)) { + return Access.GRANTED; + } + + return Access.DENIED; + } + + // + // Returns WRITE_USERS listed by any READWRITE_IDENTIFIERS + // + private List getWriteUsersFromReadWriteIdentifiers(IdentifierMetadata values) + throws InvalidIdentifierException, NamingAuthorityConfigurationException { + + List writers = null; + + List rwIdentifiers = SecurityUtil.getReadWriteIdentifiers(values); + if (rwIdentifiers != null) { + for (String identifier : rwIdentifiers) { + List writeUsers = SecurityUtil.getWriteUsers(loadSecurityIdentifier(identifier)); + if (writeUsers != null) { + if (writers == null) { + writers = new ArrayList(); + } + writers.addAll(writeUsers); + } + } + } + + return writers; + } + + // + // Returns READ_USERS listed by any READWRITE_IDENTIFIERS + // + private List getReadUsersFromReadWriteIdentifiers(IdentifierMetadata values) + throws InvalidIdentifierException, NamingAuthorityConfigurationException { + + List readers = null; + + List rwIdentifiers = SecurityUtil.getReadWriteIdentifiers(values); + if (rwIdentifiers != null) { + for (String identifier : rwIdentifiers) { + List readUsers = SecurityUtil.getReadUsers(loadSecurityIdentifier(identifier)); + if (readUsers != null) { + if (readers == null) { + readers = new ArrayList(); + } + readers.addAll(readUsers); + } + } + } + + return readers; + } + + // + // Returns ADMIN_USERS listed by any ADMIN_IDENTIFIERS + // + private List getAdminUsersFromAdminIdentifiers(IdentifierMetadata values) + throws InvalidIdentifierException, NamingAuthorityConfigurationException { + + List allAdmins = null; + + List adminIdentifiers = SecurityUtil.getAdminIdentifiers(values); + if (adminIdentifiers != null) { + for (String identifier : adminIdentifiers) { + List admins = SecurityUtil.getAdminUsers(loadSecurityIdentifier(identifier)); + + if (admins != null) { + if (allAdmins == null) { + allAdmins = new ArrayList(); + } + allAdmins.addAll(admins); + } + } + } + + return allAdmins; + } + + // + // Looks at READ security settings at the key level. + // Key security is determined by looking at the READWRITE_IDENTIFIER + // attached to the key. + // + private Access getKeyReadAccess(SecurityInfo secInfo, URI rwIdentifier) throws InvalidIdentifierException, + NamingAuthorityConfigurationException { + + if (rwIdentifier == null || rwIdentifier.normalize().toString().length() == 0) { + // no security at key level + return Access.NOSECURITY; + } + + List readers = SecurityUtil.getReadUsers(loadIdentifier(rwIdentifier)); + + return userAccess(secInfo.getUser(), readers); + } + + // + // Looks at WRITE security settings at the key level. + // Key security is determined by looking at the READWRITE_IDENTIFIER + // attached to the key. + // + private Access getKeyWriteAccess(SecurityInfo secInfo, URI rwIdentifier) throws InvalidIdentifierException, + NamingAuthorityConfigurationException { + + if (rwIdentifier == null || rwIdentifier.normalize().toString().length() == 0) { + // no security at key level + return Access.NOSECURITY; + } + + List writers = SecurityUtil.getWriteUsers(loadIdentifier(rwIdentifier)); + + return userAccess(secInfo.getUser(), writers); + } + + private synchronized void replaceSystemValues(SecurityInfo secInfo, IdentifierMetadata resolvedValues) { + systemValues = resolvedValues; + LOG.debug("System identifier updated by [" + secInfo.getUser() + "]"); + } + + private synchronized void createSystemIdentifier() { + systemValues = new IdentifierMetadata(); + Collection valCol = new ArrayList(); + systemValues.setLocalIdentifier(SecurityUtil.LOCAL_SYSTEM_IDENTIFIER); + systemValues.setValues(valCol); + + // + // PUBLIC_CREATION is true by default + // + valCol.add(new IdentifierValueKey(Keys.PUBLIC_CREATION, new String[] { SecurityUtil.PUBLIC_CREATION_YES }, null)); + + // + // ADMIN_USERS is an empty list by default + // + valCol.add(new IdentifierValueKey(Keys.ADMIN_USERS, new String[] {}, null)); + save(systemValues); + } + + /******* + * This method is used to validate the security info of the user. + * + * @param secInfo + * @return + */ + private SecurityInfo validateSecurityInfo(SecurityInfo secInfo) { + if (secInfo == null || secInfo.getUser() == null) { + return new SecurityInfoImpl(""); + } + + return secInfo; + } + + /****** + * This method is used to load the security info of an identifier. + * + * @param identifier + * @return + * @throws InvalidIdentifierException + * @throws NamingAuthorityConfigurationException + */ + private IdentifierMetadata loadSecurityIdentifier(String identifier) throws InvalidIdentifierException, + NamingAuthorityConfigurationException { + + try { + return loadIdentifier(new URI(identifier)); + } + catch (URISyntaxException e) { + LOG.error(IdentifierUtil.getStackTrace(e)); + throw new NamingAuthorityConfigurationException("Referred security identifier is bad [" + identifier + "]"); + } + } + + /****** + * This method is used to validate the identifier pattern. + * + * @param identifier + * @throws InvalidIdentifierException + */ + private void validateIdentifierPattern(String identifier) throws InvalidIdentifierException { + + if (StringUtils.isBlank(identifier)) { + return; + } + try { + UUID temp = UUID.fromString(identifier); + } + catch (IllegalArgumentException e) { + LOG.warn("Invalid Identifier " + identifier); + throw new InvalidIdentifierException("identifier is not valid"); + } + } + +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/IdentifierMetadata.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/IdentifierMetadata.java index a2f15a6..58519b5 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/IdentifierMetadata.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/IdentifierMetadata.java @@ -1,103 +1,112 @@ -package org.cagrid.identifiers.namingauthority.hibernate; - -import java.net.URI; -import java.util.Collection; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; -import javax.persistence.Table; - -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Index; -import org.hibernate.annotations.Type; - - -@Entity -@GenericGenerator(name = "id-generator", strategy = "native") -@Table(name = "identifiers") -public class IdentifierMetadata { - - @Id - @GeneratedValue - @Index(name="index_identifiers_id") - private Long id; - - @Column(nullable = false, unique = true) - @Type(type = "org.cagrid.identifiers.namingauthority.hibernate.URIUserType") - @Index(name="index_identifiers_localIdentifier") - private URI localIdentifier; - - @OneToMany(fetch=FetchType.EAGER,cascade = CascadeType.ALL) - @JoinColumn(name = "identifier_id", nullable = false) - private Collection values; - - - public Collection getValues() { - return this.values; - } - - - public void setValues(Collection values) { - this.values = values; - } - - - public void setId(Long id) { - this.id = id; - } - - - public Long getId() { - return id; - } - - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((getLocalIdentifier() == null) ? 0 : getLocalIdentifier().hashCode()); - result = prime * result + ((values == null) ? 0 : values.hashCode()); - return result; - } - - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - IdentifierMetadata other = (IdentifierMetadata) obj; - if (getLocalIdentifier() == null) { - if (other.getLocalIdentifier() != null) - return false; - } else if (!getLocalIdentifier().equals(other.getLocalIdentifier())) - return false; - if (values == null) { - if (other.values != null) - return false; - } else if (!values.equals(other.values)) - return false; - return true; - } - - - public void setLocalIdentifier(URI relativeIdentifier) { - this.localIdentifier = relativeIdentifier; - } - - - public URI getLocalIdentifier() { - return localIdentifier; - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.hibernate; + +import java.net.URI; +import java.util.Collection; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Index; +import org.hibernate.annotations.Type; + + +@Entity +@GenericGenerator(name = "id-generator", strategy = "native") +@Table(name = "identifiers") +public class IdentifierMetadata { + + @Id + @GeneratedValue + @Index(name="index_identifiers_id") + private Long id; + + @Column(nullable = false, unique = true) + @Type(type = "org.cagrid.identifiers.namingauthority.hibernate.URIUserType") + @Index(name="index_identifiers_localIdentifier") + private URI localIdentifier; + + @OneToMany(fetch=FetchType.EAGER,cascade = CascadeType.ALL) + @JoinColumn(name = "identifier_id", nullable = false) + private Collection values; + + + public Collection getValues() { + return this.values; + } + + + public void setValues(Collection values) { + this.values = values; + } + + + public void setId(Long id) { + this.id = id; + } + + + public Long getId() { + return id; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getLocalIdentifier() == null) ? 0 : getLocalIdentifier().hashCode()); + result = prime * result + ((values == null) ? 0 : values.hashCode()); + return result; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IdentifierMetadata other = (IdentifierMetadata) obj; + if (getLocalIdentifier() == null) { + if (other.getLocalIdentifier() != null) + return false; + } else if (!getLocalIdentifier().equals(other.getLocalIdentifier())) + return false; + if (values == null) { + if (other.values != null) + return false; + } else if (!values.equals(other.values)) + return false; + return true; + } + + + public void setLocalIdentifier(URI relativeIdentifier) { + this.localIdentifier = relativeIdentifier; + } + + + public URI getLocalIdentifier() { + return localIdentifier; + } + +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/IdentifierValueKey.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/IdentifierValueKey.java index 2bf47ef..71db531 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/IdentifierValueKey.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/IdentifierValueKey.java @@ -1,135 +1,144 @@ -package org.cagrid.identifiers.namingauthority.hibernate; - -import java.net.URI; -import java.util.Arrays; -import java.util.List; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinTable; -import javax.persistence.Table; - -import org.hibernate.annotations.CollectionOfElements; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Index; -import org.hibernate.annotations.Type; - - -@Entity -@GenericGenerator(name = "id-generator", strategy = "native") -@Table(name = "identifier_keys") -public class IdentifierValueKey { - - @Id - @GeneratedValue - private Long id; - - @Column(nullable = false, name = "value_key", length = 1024) - @Index(name="index_identifier_keys_key") - private String key; - - @CollectionOfElements(fetch = FetchType.EAGER) - @Fetch(FetchMode.SELECT) - @JoinTable(name = "identifier_key_values") - @Column(name = "value", length = 500) - private List values; - - @Column(nullable = true, unique = false) - @Type(type = "org.cagrid.identifiers.namingauthority.hibernate.URIUserType") - private URI policyIdentifier; - - public IdentifierValueKey() {} - - public IdentifierValueKey(IdentifierValueKey ivk) { - setPolicyIdentifier(ivk.getPolicyIdentifier()); - setKey(ivk.getKey()); - setValues(ivk.getValues()); - } - - public IdentifierValueKey(String key, List values, URI rwIdentifier) { - setPolicyIdentifier(rwIdentifier); - setKey(key); - setValues(values); - } - - public IdentifierValueKey(String key, String[] values, URI rwIdentifier) { - this(key, Arrays.asList(values), rwIdentifier); - } - - public URI getPolicyIdentifier() { - return this.policyIdentifier; - } - - public void setPolicyIdentifier(URI identifier) { - this.policyIdentifier = identifier; - } - - public List getValues() { - return this.values; - } - - - public void setValues(List values) { - this.values = values; - } - - - public void setKey(String key) { - this.key = key; - } - - - public String getKey() { - return this.key; - } - - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - result = prime * result + ((values == null) ? 0 : values.hashCode()); - return result; - } - - - @Override - public boolean equals(Object obj) { - // DEFINITION, DEFINITION, READ THIS BEFORE YOU MAKE - // A CHANGE HERE. Two IdentifierValueKey objects are - // considered equal if the keys match. Nothing else - // matters. Lots of code depends on this. Do not - // change unless you know what you are doing. - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - IdentifierValueKey other = (IdentifierValueKey) obj; - if (this.key == null) { - if (other.key != null) - return false; - } else if (!this.key.equals(other.key)) - return false; - - return true; - } - - - private void setId(Long id) { - this.id = id; - } - - - public Long getId() { - return this.id; - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.hibernate; + +import java.net.URI; +import java.util.Arrays; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinTable; +import javax.persistence.Table; + +import org.hibernate.annotations.CollectionOfElements; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Index; +import org.hibernate.annotations.Type; + + +@Entity +@GenericGenerator(name = "id-generator", strategy = "native") +@Table(name = "identifier_keys") +public class IdentifierValueKey { + + @Id + @GeneratedValue + private Long id; + + @Column(nullable = false, name = "value_key", length = 1024) + @Index(name="index_identifier_keys_key") + private String key; + + @CollectionOfElements(fetch = FetchType.EAGER) + @Fetch(FetchMode.SELECT) + @JoinTable(name = "identifier_key_values") + @Column(name = "value", length = 500) + private List values; + + @Column(nullable = true, unique = false) + @Type(type = "org.cagrid.identifiers.namingauthority.hibernate.URIUserType") + private URI policyIdentifier; + + public IdentifierValueKey() {} + + public IdentifierValueKey(IdentifierValueKey ivk) { + setPolicyIdentifier(ivk.getPolicyIdentifier()); + setKey(ivk.getKey()); + setValues(ivk.getValues()); + } + + public IdentifierValueKey(String key, List values, URI rwIdentifier) { + setPolicyIdentifier(rwIdentifier); + setKey(key); + setValues(values); + } + + public IdentifierValueKey(String key, String[] values, URI rwIdentifier) { + this(key, Arrays.asList(values), rwIdentifier); + } + + public URI getPolicyIdentifier() { + return this.policyIdentifier; + } + + public void setPolicyIdentifier(URI identifier) { + this.policyIdentifier = identifier; + } + + public List getValues() { + return this.values; + } + + + public void setValues(List values) { + this.values = values; + } + + + public void setKey(String key) { + this.key = key; + } + + + public String getKey() { + return this.key; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + ((values == null) ? 0 : values.hashCode()); + return result; + } + + + @Override + public boolean equals(Object obj) { + // DEFINITION, DEFINITION, READ THIS BEFORE YOU MAKE + // A CHANGE HERE. Two IdentifierValueKey objects are + // considered equal if the keys match. Nothing else + // matters. Lots of code depends on this. Do not + // change unless you know what you are doing. + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IdentifierValueKey other = (IdentifierValueKey) obj; + if (this.key == null) { + if (other.key != null) + return false; + } else if (!this.key.equals(other.key)) + return false; + + return true; + } + + + private void setId(Long id) { + this.id = id; + } + + + public Long getId() { + return this.id; + } + +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/URIUserType.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/URIUserType.java index 3570a66..5e8f755 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/URIUserType.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/hibernate/URIUserType.java @@ -1,108 +1,117 @@ -package org.cagrid.identifiers.namingauthority.hibernate; - -import java.io.Serializable; -import java.net.URI; -import java.net.URISyntaxException; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; - -import org.hibernate.HibernateException; -import org.hibernate.usertype.UserType; - - -/** - * This type makes sure Hibernate stores URIs as strings in the database (when - * its used). - * - * @author oster - */ -public class URIUserType implements UserType { - - public static final int[] SQL_TYPES = {Types.VARCHAR}; - - - public Object assemble(Serializable cached, Object owner) throws HibernateException { - return cached; - } - - - public Object deepCopy(Object value) throws HibernateException { - if (value != null) { - URI uri = (URI) value; - try { - return new URI(uri.toString()); - } catch (URISyntaxException e) { - throw new HibernateException("Invalid URI", e); - } - } else { - return null; - } - - } - - - public Serializable disassemble(Object value) throws HibernateException { - return (Serializable) value; - } - - - public boolean equals(Object o1, Object o2) throws HibernateException { - if (o1 == null) { - return o2 == null; - } - return o1.equals(o2); - } - - - public int hashCode(Object x) throws HibernateException { - return x.hashCode(); - } - - - public boolean isMutable() { - return false; - } - - - public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { - if (rs.wasNull()) { - return null; - } else { - try { - String val = rs.getString(names[0]); - if (val == null) - return null; - return new URI(val); - } catch (URISyntaxException e) { - throw new HibernateException("Invalid URI", e); - } - } - } - - - public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { - if (value == null) { - st.setNull(index, Types.VARCHAR); - } else { - URI uri = (URI) value; - st.setString(index, uri.toString()); - } - } - - - public Object replace(Object original, Object target, Object owner) throws HibernateException { - return original; - } - - - public Class returnedClass() { - return URI.class; - } - - - public int[] sqlTypes() { - return SQL_TYPES; - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.hibernate; + +import java.io.Serializable; +import java.net.URI; +import java.net.URISyntaxException; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; + +import org.hibernate.HibernateException; +import org.hibernate.usertype.UserType; + + +/** + * This type makes sure Hibernate stores URIs as strings in the database (when + * its used). + * + * @author oster + */ +public class URIUserType implements UserType { + + public static final int[] SQL_TYPES = {Types.VARCHAR}; + + + public Object assemble(Serializable cached, Object owner) throws HibernateException { + return cached; + } + + + public Object deepCopy(Object value) throws HibernateException { + if (value != null) { + URI uri = (URI) value; + try { + return new URI(uri.toString()); + } catch (URISyntaxException e) { + throw new HibernateException("Invalid URI", e); + } + } else { + return null; + } + + } + + + public Serializable disassemble(Object value) throws HibernateException { + return (Serializable) value; + } + + + public boolean equals(Object o1, Object o2) throws HibernateException { + if (o1 == null) { + return o2 == null; + } + return o1.equals(o2); + } + + + public int hashCode(Object x) throws HibernateException { + return x.hashCode(); + } + + + public boolean isMutable() { + return false; + } + + + public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { + if (rs.wasNull()) { + return null; + } else { + try { + String val = rs.getString(names[0]); + if (val == null) + return null; + return new URI(val); + } catch (URISyntaxException e) { + throw new HibernateException("Invalid URI", e); + } + } + } + + + public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { + if (value == null) { + st.setNull(index, Types.VARCHAR); + } else { + URI uri = (URI) value; + st.setString(index, uri.toString()); + } + } + + + public Object replace(Object original, Object target, Object owner) throws HibernateException { + return original; + } + + + public Class returnedClass() { + return URI.class; + } + + + public int[] sqlTypes() { + return SQL_TYPES; + } +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/http/HttpProcessorImpl.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/http/HttpProcessorImpl.java index 3f98ed4..fe31d46 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/http/HttpProcessorImpl.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/http/HttpProcessorImpl.java @@ -1,321 +1,330 @@ -package org.cagrid.identifiers.namingauthority.http; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.Writer; -import java.net.URI; -import java.net.URISyntaxException; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.cagrid.identifiers.namingauthority.HttpProcessor; -import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; -import org.cagrid.identifiers.namingauthority.NamingAuthority; -import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; -import org.cagrid.identifiers.namingauthority.NamingAuthoritySecurityException; -import org.cagrid.identifiers.namingauthority.domain.IdentifierData; -import org.cagrid.identifiers.namingauthority.domain.KeyData; -import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; -import org.cagrid.identifiers.namingauthority.util.IdentifierUtil; -import org.exolab.castor.xml.MarshalException; -import org.exolab.castor.xml.Marshaller; -import org.exolab.castor.xml.ValidationException; -import org.globus.axis.gsi.GSIConstants; - - -public class HttpProcessorImpl implements HttpProcessor { - - protected static Log LOG = LogFactory.getLog(HttpProcessorImpl.class.getName()); - private NamingAuthority namingAuthority; - private Marshaller serializer; - - public static String ERR_HDR = "There was an error processing your request."; - - public static String HTTP_ACCEPT_HDR = "Accept"; - public static String HTTP_ACCEPT_HTML = "text/html"; - public static String HTTP_ACCEPT_XML = "application/xml"; - public static String HTTP_ACCEPT_ANY = "*/*"; - - public void setNamingAuthority(NamingAuthority na) { - this.namingAuthority = na; - } - - public NamingAuthority getNamingAuthority() { - return namingAuthority; - } - - public void setSerializer( Marshaller aSerializer ) { - this.serializer = aSerializer; - } - - public boolean xmlResponseRequired(HttpServletRequest req) { - boolean htmlOk = false; - boolean xmlOk = false; - boolean anyOk = false; - - String resType = req.getHeader(HTTP_ACCEPT_HDR); - - System.out.println("ACCEPT[" + resType + "]"); - - if (resType != null) { - - // I found that each browser specifies Accept header - // differently (see below). For example, Safari specifies - // application/xml as the first accepted format, so - // obviously, if we just take into account the first - // format, we'd always return XML to Safari, which is - // undesired. So what we'll do is that we'll return - // HTML unless it is not listed as one of the accepted - // formats. "*/*" will also override XML. Client programs - // other than browsers wishing to retrieve XML should list - // XML only. - // - // Safari - // application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 - // - // Firefox - // text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 - // - // IE - // */* - - String[] resTypeArr = resType.split(","); - for (String type : resTypeArr) { - if (type.contains(HTTP_ACCEPT_HTML)) - htmlOk = true; - else if (type.contains(HTTP_ACCEPT_ANY)) - anyOk = true; - else if (type.contains(HTTP_ACCEPT_XML)) - xmlOk = true; - } - - if (!htmlOk && !anyOk && xmlOk) - return true; - } - - return false; - } - - - public String htmlResponse(URI uri, IdentifierData ivs) throws NamingAuthorityConfigurationException { - StringBuffer msg = new StringBuffer(); - - if (ivs == null) { - msg.append("

Local identifier [" + uri + "] could not be found

\n"); - } else { - msg.append("

" + IdentifierUtil.build(namingAuthority.getConfiguration().getNaPrefixURI(), uri) - + "

\n
\n"); - - for (String key : ivs.getKeys()) { - msg.append("Key:  " + key + "
\n"); - KeyData kd = ivs.getValues(key); - if (kd.getPolicyIdentifier() != null) { - msg.append("Policy Identifier:  "); - msg.append(kd.getPolicyIdentifier().normalize().toString()); - } - msg.append("
\n"); - - if (kd.getValues() != null) { - for (String value : kd.getValues()) { - msg.append("Key Data:  " + escape(value) + "
\n"); - } - } - msg.append("
\n"); - } - } - - return msg.toString(); - } - - protected String makeErrStr(String msg, Throwable t) { - StringBuffer sb = new StringBuffer(); - - sb.append(ERR_HDR); - - if (t != null) { - sb.append("\n") - .append(IdentifierUtil.getStackTrace(t)) - .append("\n"); - } - - return sb.toString(); - } - - protected String makeHtmlErrStr(String msg, Throwable t) { - StringBuffer sb = new StringBuffer(); - - sb.append("

").append(ERR_HDR).append("

") - .append("

").append(msg).append("

"); - - if (t != null) { - sb.append("
") - .append("
") - .append(t.toString()) - .append("
") - .append(IdentifierUtil.getStackTrace(t)); - } - - String outStr = sb.toString().replace("\n", "
"); - return outStr; - } - - protected String makeErrStr( boolean xml, String msg, Throwable t ) { - if (xml) { - return makeErrStr(msg, t); - } - return makeHtmlErrStr(msg, t); - } - - protected String makeErrStr( boolean xml, String msg ) { - if (xml) { - return makeErrStr(msg, null); - } - return makeHtmlErrStr(msg, null); - } - - protected String serialize( Object ivs ) throws IOException, MarshalException, ValidationException { - Writer out = new StringWriter(); - serializer.setWriter(out); - serializer.marshal(ivs); - - return out.toString(); - } - - protected URI getServletURI(HttpServletRequest req) throws URISyntaxException { - String servletURL = req.getRequestURL().toString(); - String servletPath = req.getServletPath(); - - return new URI(servletURL.substring(0, - servletURL.indexOf(servletPath) + servletPath.length()) - + "/"); - } - - protected String serializeNAConfiguration(URI servletURI) - throws MarshalException, ValidationException, IOException { - - namingAuthority.getConfiguration().setNaBaseURI(servletURI); - return serialize(namingAuthority.getConfiguration()); - } - - protected String htmlNAConfiguration(URI servletURI) - throws MarshalException, ValidationException, IOException { - - namingAuthority.getConfiguration().setNaBaseURI(servletURI); - - StringBuilder sb = new StringBuilder("
"); - sb.append("
Naming Authority
\n
") - .append(namingAuthority.getConfiguration().getNaBaseURI()) - .append("

\n
Naming Authority Grid Service
\n
" ) - .append(namingAuthority.getConfiguration().getNaGridSvcURI().toString()) - .append("

\n
Naming Authority Prefix
\n
" ) - .append(namingAuthority.getConfiguration().getNaPrefixURI().toString()) - .append("
"); - - return sb.toString(); - } - - public void process(HttpServletRequest request, HttpServletResponse response) throws IOException { - StringBuffer msg = new StringBuffer(); - int responseStatus = HttpServletResponse.SC_OK; - - SecurityInfoImpl secInfo = new SecurityInfoImpl( - (String) request.getAttribute(GSIConstants.GSI_USER_DN)); - - // - // ?config causes to ignore resolution and - // return naming authority configuration - // instead - // - String config = request.getParameter("config"); - if (config != null) { - try { - if (xmlResponseRequired(request)) { - msg.append(serializeNAConfiguration(getServletURI(request))); - response.setContentType(HTTP_ACCEPT_XML); - } else { - msg.append(htmlNAConfiguration(getServletURI(request))); - response.setContentType(HTTP_ACCEPT_HTML); - } - } catch( Exception e ) { - msg.append(makeErrStr("Server error while serializing naming authority's configuration", e)); - responseStatus = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; - } - } else { - // - // Specifying ?xml in the URL forces XML output - // (Usefull for a user debugging from a web - // browser) - // - boolean forceXML = false; - if (request.getParameter("xml") != null) { - forceXML = true; - } - - boolean xmlResponse = forceXML || xmlResponseRequired(request); - - URI uri = URI.create(request.getPathInfo()); - - if (uri == null || uri.getPath().length() <= 1 || !uri.getPath().startsWith("/")) { - msg.append(makeErrStr(xmlResponse, "No identifier provided")); - responseStatus = HttpServletResponse.SC_BAD_REQUEST; - } else { - - IdentifierData ivs = null; - try { - ivs = (IdentifierData) namingAuthority.resolveIdentifier(secInfo, IdentifierUtil.build(namingAuthority - .getConfiguration().getNaPrefixURI(), uri)); - - if (xmlResponse) { - msg.append(serialize(ivs)); - response.setContentType(HTTP_ACCEPT_XML); - } else { - msg.append(htmlResponse(uri, ivs)); - response.setContentType(HTTP_ACCEPT_HTML); - } - } catch (InvalidIdentifierException e) { - responseStatus = HttpServletResponse.SC_NOT_FOUND; - String error = makeErrStr(xmlResponse, "Invalid Identifier Exception", e); - LOG.error(error); - msg.append(error); - - } catch (NamingAuthorityConfigurationException e) { - responseStatus = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; - String error = makeErrStr(xmlResponse, "Naming Authority Configuration Exception", e); - LOG.error(error); - msg.append(error); - - } catch (NamingAuthoritySecurityException e) { - responseStatus = HttpServletResponse.SC_FORBIDDEN; - String error = makeErrStr(xmlResponse, "Naming Authority Security Exception", e); - LOG.error(error); - msg.append(error); - - } catch (Exception e) { - responseStatus = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; - String error = makeErrStr(xmlResponse, "Unexpected system error", e); - LOG.error(error); - msg.append(error); - - } - } - } - - if ( responseStatus != HttpServletResponse.SC_OK ) { - response.setContentType(HTTP_ACCEPT_HTML); - } - - response.setStatus(responseStatus); - response.getWriter().println(msg.toString()); - }; - - - private String escape(String inStr) { - String outStr = inStr.replaceAll("<", "<"); - outStr = outStr.replaceAll(">", ">"); - return outStr; - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.http; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.Writer; +import java.net.URI; +import java.net.URISyntaxException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.cagrid.identifiers.namingauthority.HttpProcessor; +import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; +import org.cagrid.identifiers.namingauthority.NamingAuthority; +import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; +import org.cagrid.identifiers.namingauthority.NamingAuthoritySecurityException; +import org.cagrid.identifiers.namingauthority.domain.IdentifierData; +import org.cagrid.identifiers.namingauthority.domain.KeyData; +import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; +import org.cagrid.identifiers.namingauthority.util.IdentifierUtil; +import org.exolab.castor.xml.MarshalException; +import org.exolab.castor.xml.Marshaller; +import org.exolab.castor.xml.ValidationException; +import org.globus.axis.gsi.GSIConstants; + + +public class HttpProcessorImpl implements HttpProcessor { + + protected static Log LOG = LogFactory.getLog(HttpProcessorImpl.class.getName()); + private NamingAuthority namingAuthority; + private Marshaller serializer; + + public static String ERR_HDR = "There was an error processing your request."; + + public static String HTTP_ACCEPT_HDR = "Accept"; + public static String HTTP_ACCEPT_HTML = "text/html"; + public static String HTTP_ACCEPT_XML = "application/xml"; + public static String HTTP_ACCEPT_ANY = "*/*"; + + public void setNamingAuthority(NamingAuthority na) { + this.namingAuthority = na; + } + + public NamingAuthority getNamingAuthority() { + return namingAuthority; + } + + public void setSerializer( Marshaller aSerializer ) { + this.serializer = aSerializer; + } + + public boolean xmlResponseRequired(HttpServletRequest req) { + boolean htmlOk = false; + boolean xmlOk = false; + boolean anyOk = false; + + String resType = req.getHeader(HTTP_ACCEPT_HDR); + + System.out.println("ACCEPT[" + resType + "]"); + + if (resType != null) { + + // I found that each browser specifies Accept header + // differently (see below). For example, Safari specifies + // application/xml as the first accepted format, so + // obviously, if we just take into account the first + // format, we'd always return XML to Safari, which is + // undesired. So what we'll do is that we'll return + // HTML unless it is not listed as one of the accepted + // formats. "*/*" will also override XML. Client programs + // other than browsers wishing to retrieve XML should list + // XML only. + // + // Safari + // application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 + // + // Firefox + // text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 + // + // IE + // */* + + String[] resTypeArr = resType.split(","); + for (String type : resTypeArr) { + if (type.contains(HTTP_ACCEPT_HTML)) + htmlOk = true; + else if (type.contains(HTTP_ACCEPT_ANY)) + anyOk = true; + else if (type.contains(HTTP_ACCEPT_XML)) + xmlOk = true; + } + + if (!htmlOk && !anyOk && xmlOk) + return true; + } + + return false; + } + + + public String htmlResponse(URI uri, IdentifierData ivs) throws NamingAuthorityConfigurationException { + StringBuffer msg = new StringBuffer(); + + if (ivs == null) { + msg.append("

Local identifier [" + uri + "] could not be found

\n"); + } else { + msg.append("

" + IdentifierUtil.build(namingAuthority.getConfiguration().getNaPrefixURI(), uri) + + "

\n
\n"); + + for (String key : ivs.getKeys()) { + msg.append("Key:  " + key + "
\n"); + KeyData kd = ivs.getValues(key); + if (kd.getPolicyIdentifier() != null) { + msg.append("Policy Identifier:  "); + msg.append(kd.getPolicyIdentifier().normalize().toString()); + } + msg.append("
\n"); + + if (kd.getValues() != null) { + for (String value : kd.getValues()) { + msg.append("Key Data:  " + escape(value) + "
\n"); + } + } + msg.append("
\n"); + } + } + + return msg.toString(); + } + + protected String makeErrStr(String msg, Throwable t) { + StringBuffer sb = new StringBuffer(); + + sb.append(ERR_HDR); + + if (t != null) { + sb.append("\n") + .append(IdentifierUtil.getStackTrace(t)) + .append("\n"); + } + + return sb.toString(); + } + + protected String makeHtmlErrStr(String msg, Throwable t) { + StringBuffer sb = new StringBuffer(); + + sb.append("

").append(ERR_HDR).append("

") + .append("

").append(msg).append("

"); + + if (t != null) { + sb.append("
") + .append("
") + .append(t.toString()) + .append("
") + .append(IdentifierUtil.getStackTrace(t)); + } + + String outStr = sb.toString().replace("\n", "
"); + return outStr; + } + + protected String makeErrStr( boolean xml, String msg, Throwable t ) { + if (xml) { + return makeErrStr(msg, t); + } + return makeHtmlErrStr(msg, t); + } + + protected String makeErrStr( boolean xml, String msg ) { + if (xml) { + return makeErrStr(msg, null); + } + return makeHtmlErrStr(msg, null); + } + + protected String serialize( Object ivs ) throws IOException, MarshalException, ValidationException { + Writer out = new StringWriter(); + serializer.setWriter(out); + serializer.marshal(ivs); + + return out.toString(); + } + + protected URI getServletURI(HttpServletRequest req) throws URISyntaxException { + String servletURL = req.getRequestURL().toString(); + String servletPath = req.getServletPath(); + + return new URI(servletURL.substring(0, + servletURL.indexOf(servletPath) + servletPath.length()) + + "/"); + } + + protected String serializeNAConfiguration(URI servletURI) + throws MarshalException, ValidationException, IOException { + + namingAuthority.getConfiguration().setNaBaseURI(servletURI); + return serialize(namingAuthority.getConfiguration()); + } + + protected String htmlNAConfiguration(URI servletURI) + throws MarshalException, ValidationException, IOException { + + namingAuthority.getConfiguration().setNaBaseURI(servletURI); + + StringBuilder sb = new StringBuilder("
"); + sb.append("
Naming Authority
\n
") + .append(namingAuthority.getConfiguration().getNaBaseURI()) + .append("

\n
Naming Authority Grid Service
\n
" ) + .append(namingAuthority.getConfiguration().getNaGridSvcURI().toString()) + .append("

\n
Naming Authority Prefix
\n
" ) + .append(namingAuthority.getConfiguration().getNaPrefixURI().toString()) + .append("
"); + + return sb.toString(); + } + + public void process(HttpServletRequest request, HttpServletResponse response) throws IOException { + StringBuffer msg = new StringBuffer(); + int responseStatus = HttpServletResponse.SC_OK; + + SecurityInfoImpl secInfo = new SecurityInfoImpl( + (String) request.getAttribute(GSIConstants.GSI_USER_DN)); + + // + // ?config causes to ignore resolution and + // return naming authority configuration + // instead + // + String config = request.getParameter("config"); + if (config != null) { + try { + if (xmlResponseRequired(request)) { + msg.append(serializeNAConfiguration(getServletURI(request))); + response.setContentType(HTTP_ACCEPT_XML); + } else { + msg.append(htmlNAConfiguration(getServletURI(request))); + response.setContentType(HTTP_ACCEPT_HTML); + } + } catch( Exception e ) { + msg.append(makeErrStr("Server error while serializing naming authority's configuration", e)); + responseStatus = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; + } + } else { + // + // Specifying ?xml in the URL forces XML output + // (Usefull for a user debugging from a web + // browser) + // + boolean forceXML = false; + if (request.getParameter("xml") != null) { + forceXML = true; + } + + boolean xmlResponse = forceXML || xmlResponseRequired(request); + + URI uri = URI.create(request.getPathInfo()); + + if (uri == null || uri.getPath().length() <= 1 || !uri.getPath().startsWith("/")) { + msg.append(makeErrStr(xmlResponse, "No identifier provided")); + responseStatus = HttpServletResponse.SC_BAD_REQUEST; + } else { + + IdentifierData ivs = null; + try { + ivs = (IdentifierData) namingAuthority.resolveIdentifier(secInfo, IdentifierUtil.build(namingAuthority + .getConfiguration().getNaPrefixURI(), uri)); + + if (xmlResponse) { + msg.append(serialize(ivs)); + response.setContentType(HTTP_ACCEPT_XML); + } else { + msg.append(htmlResponse(uri, ivs)); + response.setContentType(HTTP_ACCEPT_HTML); + } + } catch (InvalidIdentifierException e) { + responseStatus = HttpServletResponse.SC_NOT_FOUND; + String error = makeErrStr(xmlResponse, "Invalid Identifier Exception", e); + LOG.error(error); + msg.append(error); + + } catch (NamingAuthorityConfigurationException e) { + responseStatus = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; + String error = makeErrStr(xmlResponse, "Naming Authority Configuration Exception", e); + LOG.error(error); + msg.append(error); + + } catch (NamingAuthoritySecurityException e) { + responseStatus = HttpServletResponse.SC_FORBIDDEN; + String error = makeErrStr(xmlResponse, "Naming Authority Security Exception", e); + LOG.error(error); + msg.append(error); + + } catch (Exception e) { + responseStatus = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; + String error = makeErrStr(xmlResponse, "Unexpected system error", e); + LOG.error(error); + msg.append(error); + + } + } + } + + if ( responseStatus != HttpServletResponse.SC_OK ) { + response.setContentType(HTTP_ACCEPT_HTML); + } + + response.setStatus(responseStatus); + response.getWriter().println(msg.toString()); + }; + + + private String escape(String inStr) { + String outStr = inStr.replaceAll("<", "<"); + outStr = outStr.replaceAll(">", ">"); + return outStr; + } +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/http/HttpServer.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/http/HttpServer.java index 6998b93..c592530 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/http/HttpServer.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/http/HttpServer.java @@ -1,52 +1,61 @@ -package org.cagrid.identifiers.namingauthority.http; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.cagrid.identifiers.namingauthority.HttpProcessor; -import org.mortbay.jetty.Handler; -import org.mortbay.jetty.Request; -import org.mortbay.jetty.Server; -import org.mortbay.jetty.handler.AbstractHandler; - - -public class HttpServer implements Runnable { - - private HttpProcessor processor; - - private int _port; - - - public HttpServer(HttpProcessor processor, int port) { - this.processor = processor; - _port = port; - } - - - public void start() { - new Thread(this).start(); - } - - - public void run() { - Handler handler = new AbstractHandler() { - public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) - throws java.io.IOException, javax.servlet.ServletException { - processor.process(request, response); - ((Request) request).setHandled(true); - } - }; - - Server server = new Server(_port); - server.setHandler(handler); - try { - server.start(); - - System.out.println("HTTP Jetty Server Started on port " + _port); - server.join(); - } catch (Exception e) { - System.out.println("Failed to start Jetty HTTP Server: " + e); - e.printStackTrace(); - } - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.http; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.cagrid.identifiers.namingauthority.HttpProcessor; +import org.mortbay.jetty.Handler; +import org.mortbay.jetty.Request; +import org.mortbay.jetty.Server; +import org.mortbay.jetty.handler.AbstractHandler; + + +public class HttpServer implements Runnable { + + private HttpProcessor processor; + + private int _port; + + + public HttpServer(HttpProcessor processor, int port) { + this.processor = processor; + _port = port; + } + + + public void start() { + new Thread(this).start(); + } + + + public void run() { + Handler handler = new AbstractHandler() { + public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) + throws java.io.IOException, javax.servlet.ServletException { + processor.process(request, response); + ((Request) request).setHandled(true); + } + }; + + Server server = new Server(_port); + server.setHandler(handler); + try { + server.start(); + + System.out.println("HTTP Jetty Server Started on port " + _port); + server.join(); + } catch (Exception e) { + System.out.println("Failed to start Jetty HTTP Server: " + e); + e.printStackTrace(); + } + } +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/IdentifierGeneratorImpl.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/IdentifierGeneratorImpl.java index 6e7475b..56bc3da 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/IdentifierGeneratorImpl.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/IdentifierGeneratorImpl.java @@ -1,13 +1,22 @@ -package org.cagrid.identifiers.namingauthority.impl; - -import java.net.URI; - -import org.cagrid.identifiers.namingauthority.IdentifierGenerator; -import org.cagrid.identifiers.namingauthority.domain.NamingAuthorityConfig; - -public class IdentifierGeneratorImpl implements IdentifierGenerator { - - public URI generate(NamingAuthorityConfig config) { - return URI.create(java.util.UUID.randomUUID().toString()); - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.impl; + +import java.net.URI; + +import org.cagrid.identifiers.namingauthority.IdentifierGenerator; +import org.cagrid.identifiers.namingauthority.domain.NamingAuthorityConfig; + +public class IdentifierGeneratorImpl implements IdentifierGenerator { + + public URI generate(NamingAuthorityConfig config) { + return URI.create(java.util.UUID.randomUUID().toString()); + } +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/NamingAuthorityImpl.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/NamingAuthorityImpl.java index fdd559d..496d37d 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/NamingAuthorityImpl.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/NamingAuthorityImpl.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority.impl; import java.net.URI; diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/NamingAuthorityService.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/NamingAuthorityService.java index e2728f9..938bc4c 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/NamingAuthorityService.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/NamingAuthorityService.java @@ -1,77 +1,86 @@ -package org.cagrid.identifiers.namingauthority.impl; - -import java.io.IOException; - -import javax.servlet.Servlet; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.cagrid.identifiers.namingauthority.HttpProcessor; -import org.cagrid.identifiers.namingauthority.dao.IdentifierMetadataDao; -import org.globus.axis.gsi.GSIConstants; - - -public class NamingAuthorityService extends HttpServlet { - protected static Log LOG = LogFactory.getLog(NamingAuthorityService.class.getName()); - private static final long serialVersionUID = 1L; - private HttpProcessor processor; - - - /** - * @see HttpServlet#HttpServlet() - */ - public NamingAuthorityService() { - super(); - } - - - /** - * @see Servlet#init(ServletConfig) - */ - public void init(ServletConfig config) throws ServletException { - super.init(config); - - org.springframework.web.context.WebApplicationContext context = - org.springframework.web.context.support.WebApplicationContextUtils - .getRequiredWebApplicationContext(getServletContext()); - - this.processor = (HttpProcessor) context.getBean("httpProcessor", - HttpProcessor.class); - } - - - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse - * response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - LOG.debug("getPathInfo[" + request.getPathInfo() + "]"); - LOG.debug("getQueryString[" + request.getQueryString() + "]"); - LOG.debug("getRequestURI[" + request.getRequestURI() + "]"); - LOG.debug("getRequestURL[" + request.getRequestURL() + "]"); - LOG.debug("getServerName[" + request.getServerName() + "]"); - LOG.debug("getServerPort[" + request.getServerPort() + "]"); - LOG.debug("getServletPath[" + request.getServletPath() + "]"); - LOG.debug("User Identity[" + request.getAttribute(GSIConstants.GSI_USER_DN)); - - processor.process(request, response); - } - - - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse - * response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, - IOException { - - System.out.println("doPost not implemented..."); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.impl; + +import java.io.IOException; + +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.cagrid.identifiers.namingauthority.HttpProcessor; +import org.cagrid.identifiers.namingauthority.dao.IdentifierMetadataDao; +import org.globus.axis.gsi.GSIConstants; + + +public class NamingAuthorityService extends HttpServlet { + protected static Log LOG = LogFactory.getLog(NamingAuthorityService.class.getName()); + private static final long serialVersionUID = 1L; + private HttpProcessor processor; + + + /** + * @see HttpServlet#HttpServlet() + */ + public NamingAuthorityService() { + super(); + } + + + /** + * @see Servlet#init(ServletConfig) + */ + public void init(ServletConfig config) throws ServletException { + super.init(config); + + org.springframework.web.context.WebApplicationContext context = + org.springframework.web.context.support.WebApplicationContextUtils + .getRequiredWebApplicationContext(getServletContext()); + + this.processor = (HttpProcessor) context.getBean("httpProcessor", + HttpProcessor.class); + } + + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse + * response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + LOG.debug("getPathInfo[" + request.getPathInfo() + "]"); + LOG.debug("getQueryString[" + request.getQueryString() + "]"); + LOG.debug("getRequestURI[" + request.getRequestURI() + "]"); + LOG.debug("getRequestURL[" + request.getRequestURL() + "]"); + LOG.debug("getServerName[" + request.getServerName() + "]"); + LOG.debug("getServerPort[" + request.getServerPort() + "]"); + LOG.debug("getServletPath[" + request.getServletPath() + "]"); + LOG.debug("User Identity[" + request.getAttribute(GSIConstants.GSI_USER_DN)); + + processor.process(request, response); + } + + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse + * response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + + System.out.println("doPost not implemented..."); + } + +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/SecurityInfoImpl.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/SecurityInfoImpl.java index 35edbcd..4797a82 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/SecurityInfoImpl.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/impl/SecurityInfoImpl.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority.impl; import org.cagrid.identifiers.namingauthority.SecurityInfo; diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/serialization/URIFieldHandler.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/serialization/URIFieldHandler.java index 4ea2706..f1040c8 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/serialization/URIFieldHandler.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/serialization/URIFieldHandler.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority.serialization; import java.net.URI; diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Constant.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Constant.java index 4f9cea5..20cab29 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Constant.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Constant.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority.util; public class Constant diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/IdentifierUtil.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/IdentifierUtil.java index 8a7c687..5e207a2 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/IdentifierUtil.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/IdentifierUtil.java @@ -1,169 +1,178 @@ -package org.cagrid.identifiers.namingauthority.util; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; -import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; -import org.cagrid.identifiers.namingauthority.domain.IdentifierData; -import org.cagrid.identifiers.namingauthority.domain.KeyData; -import org.cagrid.identifiers.namingauthority.hibernate.IdentifierMetadata; -import org.cagrid.identifiers.namingauthority.hibernate.IdentifierValueKey; - - -public class IdentifierUtil { - - public static URI build(URI prefix, URI localName) throws NamingAuthorityConfigurationException { - try { - verifyPrefix(prefix); - } catch(Exception e) { - throw new NamingAuthorityConfigurationException(e.getMessage()); - } - - if (localName == null) { - throw new IllegalArgumentException("Localname must not be null."); - } else if (localName.isAbsolute()) { - throw new IllegalArgumentException("Localname must be a relative URI."); - - } - - // request.getPathInfo() strips required "/" from identifier URL, replace it - String scheme = localName.getScheme(); - String path = localName.getPath(); - // trim off any leading / so the URI resolving doesn't treat it as an - // absolute path - if (path.startsWith("/")) { - path = path.substring(1); - } - String url = path; - if (scheme != null) { - url = scheme + ":/" + path; - } - localName = URI.create(url); - - return prefix.resolve(localName); - } - - public static URI getLocalName(URI prefix, URI identifier) throws InvalidIdentifierException, NamingAuthorityConfigurationException { - try { - verifyPrefix(prefix); - } catch(Exception e) { - throw new NamingAuthorityConfigurationException(e.getMessage()); - } - - String idStr = identifier.normalize().toString(); - String prefixStr = prefix.normalize().toString(); - if (!idStr.startsWith(prefixStr) || prefixStr.length() >= idStr.length()) { - throw new InvalidIdentifierException("Identifier (" + identifier + ") is not local to prefix (" + prefix - + ")."); - } - - return prefix.relativize(identifier); - } - - public static void verifyPrefix(URI prefix) throws IllegalArgumentException { - if (prefix == null) { - throw new IllegalArgumentException("Prefix must not be null."); - } else if (!prefix.isAbsolute()) { - throw new IllegalArgumentException("Prefix must be an absolute URI : " + prefix); - } else if (prefix.getFragment() != null) { - throw new IllegalArgumentException("Prefix must not contain a fragment: " + prefix); - } else if (prefix.getQuery() != null) { - throw new IllegalArgumentException("Prefix must not contain a query: " + prefix); - } else if (!prefix.getPath().endsWith("/")) { - throw new IllegalArgumentException("Prefix must have a trailing slash: " + prefix); - } - } - - // Returns list of values associated with the key - // Returns null if the key does not exist in values - // Returns an empty list if they key exists but have no values - public static List getKeyValues( IdentifierMetadata values, String keyName ) { - - if (values == null) { - return null; - } - - Collection cvalues = values.getValues(); - if (cvalues == null) { - return null; - } - - for(IdentifierValueKey ivk : cvalues) { - if (ivk.getKey().equals(keyName)) { - if (ivk.getValues() == null) { - return new ArrayList(); - } - return ivk.getValues(); - } - } - - return null; - } - - public static String getStackTrace(Throwable t) { - StringWriter stringWritter = new StringWriter(); - PrintWriter printWritter = new PrintWriter(stringWritter, true); - t.printStackTrace(printWritter); - printWritter.flush(); - stringWritter.flush(); - - return stringWritter.toString(); - } - - public static IdentifierValueKey convert(String key, KeyData kd) { - - IdentifierValueKey ivk = new IdentifierValueKey(); - ivk.setKey(key); - - if (kd != null) { - ivk.setPolicyIdentifier(kd.getPolicyIdentifier()); - ivk.setValues(kd.getValues()); - } - - return ivk; - } - - public static IdentifierMetadata convert(URI localIdentifier, IdentifierData ivalues) { - - IdentifierMetadata md = new IdentifierMetadata(); - md.setLocalIdentifier(localIdentifier); - List values = new ArrayList(); - md.setValues(values); - - if (ivalues != null) { - String[] keys = ivalues.getKeys(); - for (String key : keys) { - values.add(IdentifierUtil.convert(key, ivalues.getValues(key))); - } - } - - return md; - } - - public static IdentifierData convert(Collection valueCollection) { - IdentifierData result = null; - - if (valueCollection != null && valueCollection.size() > 0) { - result = new IdentifierData(); - Map values = new HashMap(); - result.setValues(values); - - for (IdentifierValueKey vk : valueCollection) { - values.put(vk.getKey(), convert(vk)); - } - } - - return result; - } - - public static KeyData convert(IdentifierValueKey ivk) { - return new KeyData(ivk.getPolicyIdentifier(), ivk.getValues()); - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.util; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; +import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; +import org.cagrid.identifiers.namingauthority.domain.IdentifierData; +import org.cagrid.identifiers.namingauthority.domain.KeyData; +import org.cagrid.identifiers.namingauthority.hibernate.IdentifierMetadata; +import org.cagrid.identifiers.namingauthority.hibernate.IdentifierValueKey; + + +public class IdentifierUtil { + + public static URI build(URI prefix, URI localName) throws NamingAuthorityConfigurationException { + try { + verifyPrefix(prefix); + } catch(Exception e) { + throw new NamingAuthorityConfigurationException(e.getMessage()); + } + + if (localName == null) { + throw new IllegalArgumentException("Localname must not be null."); + } else if (localName.isAbsolute()) { + throw new IllegalArgumentException("Localname must be a relative URI."); + + } + + // request.getPathInfo() strips required "/" from identifier URL, replace it + String scheme = localName.getScheme(); + String path = localName.getPath(); + // trim off any leading / so the URI resolving doesn't treat it as an + // absolute path + if (path.startsWith("/")) { + path = path.substring(1); + } + String url = path; + if (scheme != null) { + url = scheme + ":/" + path; + } + localName = URI.create(url); + + return prefix.resolve(localName); + } + + public static URI getLocalName(URI prefix, URI identifier) throws InvalidIdentifierException, NamingAuthorityConfigurationException { + try { + verifyPrefix(prefix); + } catch(Exception e) { + throw new NamingAuthorityConfigurationException(e.getMessage()); + } + + String idStr = identifier.normalize().toString(); + String prefixStr = prefix.normalize().toString(); + if (!idStr.startsWith(prefixStr) || prefixStr.length() >= idStr.length()) { + throw new InvalidIdentifierException("Identifier (" + identifier + ") is not local to prefix (" + prefix + + ")."); + } + + return prefix.relativize(identifier); + } + + public static void verifyPrefix(URI prefix) throws IllegalArgumentException { + if (prefix == null) { + throw new IllegalArgumentException("Prefix must not be null."); + } else if (!prefix.isAbsolute()) { + throw new IllegalArgumentException("Prefix must be an absolute URI : " + prefix); + } else if (prefix.getFragment() != null) { + throw new IllegalArgumentException("Prefix must not contain a fragment: " + prefix); + } else if (prefix.getQuery() != null) { + throw new IllegalArgumentException("Prefix must not contain a query: " + prefix); + } else if (!prefix.getPath().endsWith("/")) { + throw new IllegalArgumentException("Prefix must have a trailing slash: " + prefix); + } + } + + // Returns list of values associated with the key + // Returns null if the key does not exist in values + // Returns an empty list if they key exists but have no values + public static List getKeyValues( IdentifierMetadata values, String keyName ) { + + if (values == null) { + return null; + } + + Collection cvalues = values.getValues(); + if (cvalues == null) { + return null; + } + + for(IdentifierValueKey ivk : cvalues) { + if (ivk.getKey().equals(keyName)) { + if (ivk.getValues() == null) { + return new ArrayList(); + } + return ivk.getValues(); + } + } + + return null; + } + + public static String getStackTrace(Throwable t) { + StringWriter stringWritter = new StringWriter(); + PrintWriter printWritter = new PrintWriter(stringWritter, true); + t.printStackTrace(printWritter); + printWritter.flush(); + stringWritter.flush(); + + return stringWritter.toString(); + } + + public static IdentifierValueKey convert(String key, KeyData kd) { + + IdentifierValueKey ivk = new IdentifierValueKey(); + ivk.setKey(key); + + if (kd != null) { + ivk.setPolicyIdentifier(kd.getPolicyIdentifier()); + ivk.setValues(kd.getValues()); + } + + return ivk; + } + + public static IdentifierMetadata convert(URI localIdentifier, IdentifierData ivalues) { + + IdentifierMetadata md = new IdentifierMetadata(); + md.setLocalIdentifier(localIdentifier); + List values = new ArrayList(); + md.setValues(values); + + if (ivalues != null) { + String[] keys = ivalues.getKeys(); + for (String key : keys) { + values.add(IdentifierUtil.convert(key, ivalues.getValues(key))); + } + } + + return md; + } + + public static IdentifierData convert(Collection valueCollection) { + IdentifierData result = null; + + if (valueCollection != null && valueCollection.size() > 0) { + result = new IdentifierData(); + Map values = new HashMap(); + result.setValues(values); + + for (IdentifierValueKey vk : valueCollection) { + values.put(vk.getKey(), convert(vk)); + } + } + + return result; + } + + public static KeyData convert(IdentifierValueKey ivk) { + return new KeyData(ivk.getPolicyIdentifier(), ivk.getValues()); + } +} diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Keys.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Keys.java index 16893df..b16f209 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Keys.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Keys.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority.util; import java.util.ArrayList; diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/SecurityUtil.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/SecurityUtil.java index 880d706..ff18966 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/SecurityUtil.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/SecurityUtil.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority.util; import java.net.URI; diff --git a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Tree.java b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Tree.java index 493d21e..b6da6ee 100644 --- a/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Tree.java +++ b/identifiers-namingauthority/src/org/cagrid/identifiers/namingauthority/util/Tree.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority.util; import java.net.URI; diff --git a/identifiers-namingauthority/test/resources/na.test.properties b/identifiers-namingauthority/test/resources/na.test.properties index 483be79..1b901ce 100644 --- a/identifiers-namingauthority/test/resources/na.test.properties +++ b/identifiers-namingauthority/test/resources/na.test.properties @@ -1,28 +1,37 @@ -# dont change these three properties they are present for backward compatibility. -cagrid.na.prefix=https://purlz.cagrid.org:8443/localhost/ -cagrid.na.schemauri=https://localhost:8443/namingauthority/org.cagrid.identifiers.namingauthority.xsd -cagrid.na.grid.url=https://localhost:8443/wsrf/services/cagrid/IdentifiersNAService - -# Dialect of the database currently we support only mysql so dont change it. -cagrid.na.db.dialect=org.hibernate.dialect.MySQL5InnoDBDialect - -# Driver used for connecting to the database and dont change it. -cagrid.na.db.driver=com.mysql.jdbc.Driver - -# name of the database which this project should use. -cagrid.na.db.name=nadb - -# the url of the database for the jdbc calls. -cagrid.na.db.url=jdbc:mysql://localhost:3306/${cagrid.na.db.name} - -# the user name for the database connection. -cagrid.na.db.username=root - -# the password for the database connection. -cagrid.na.db.password= - -# the grid grouper URL which should be used . -cagrid.na.gridgrouper.grouperURL= - -# the group name should be use to check for the +#L +# Copyright Washington University in St. Louis +# Copyright SemanticBits +# Copyright Persistent Systems +# +# Distributed under the OSI-approved BSD 3-Clause License. +# See http://ncip.github.com/gsid/LICENSE.txt for details. +#L + +# dont change these three properties they are present for backward compatibility. +cagrid.na.prefix=https://purlz.cagrid.org:8443/localhost/ +cagrid.na.schemauri=https://localhost:8443/namingauthority/org.cagrid.identifiers.namingauthority.xsd +cagrid.na.grid.url=https://localhost:8443/wsrf/services/cagrid/IdentifiersNAService + +# Dialect of the database currently we support only mysql so dont change it. +cagrid.na.db.dialect=org.hibernate.dialect.MySQL5InnoDBDialect + +# Driver used for connecting to the database and dont change it. +cagrid.na.db.driver=com.mysql.jdbc.Driver + +# name of the database which this project should use. +cagrid.na.db.name=nadb + +# the url of the database for the jdbc calls. +cagrid.na.db.url=jdbc:mysql://localhost:3306/${cagrid.na.db.name} + +# the user name for the database connection. +cagrid.na.db.username=root + +# the password for the database connection. +cagrid.na.db.password= + +# the grid grouper URL which should be used . +cagrid.na.gridgrouper.grouperURL= + +# the group name should be use to check for the cagrid.na.gridgrouper.groupName= \ No newline at end of file diff --git a/identifiers-namingauthority/test/resources/test-applicationContext-properties.xml b/identifiers-namingauthority/test/resources/test-applicationContext-properties.xml index 52d9ed5..b5f354e 100644 --- a/identifiers-namingauthority/test/resources/test-applicationContext-properties.xml +++ b/identifiers-namingauthority/test/resources/test-applicationContext-properties.xml @@ -1,4 +1,14 @@ + + + 0) - for (Tree child : tree.getChildren()) - printTree(child, tabber + "\t"); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority; + +import java.net.URI; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.cagrid.identifiers.namingauthority.domain.IdentifierData; +import org.cagrid.identifiers.namingauthority.domain.KeyData; +import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; +import org.cagrid.identifiers.namingauthority.test.NamingAuthorityTestCaseBase; +import org.cagrid.identifiers.namingauthority.util.Tree; +import org.junit.Test; +import org.springframework.test.annotation.Rollback; + +public class NamingAuthorityTestCase extends NamingAuthorityTestCaseBase { + + private static IdentifierData globalValues = null; + protected static Log LOG = LogFactory.getLog(NamingAuthorityTestCase.class.getName()); + + static { + globalValues = new IdentifierData(); + + globalValues.put("URL", new KeyData(null, + new String[] { "http://na.cagrid.org/foo", "http://na.cagrid.org/bar" })); + + globalValues.put("CODE", new KeyData(null, new String[] { "007" })); + } + + @Test + public void testRegisterGSID() { + // System.out.println("testing the RegisterGSID"); + LOG.info("testing testRegisterGSID method"); + + // check no register access. + SecurityInfo secInfo = new SecurityInfoImpl("Unknown"); + try { + this.NamingAuthority.registerGSID(secInfo, null, null); + fail("test registerGSID"); + } + catch (Exception e) { + LOG.info("passed registerGSID for " + secInfo.getUser() + ". MSG:\" " + e.getMessage() + "\""); + } + + secInfo = new SecurityInfoImpl("User13"); + + try { + this.NamingAuthority.registerSite(secInfo, "a", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", + "443", "SB"); + LOG.info("passed registerSite inorder to test registerGSID for user " + secInfo.getUser()); + } + catch (Exception e) { + StringBuffer sb = new StringBuffer(); + for (StackTraceElement temp : e.getStackTrace()) + sb.append(temp.getClassName() + "[" + temp.getLineNumber() + "]\n"); + fail("test registeSite for user " + secInfo.getUser() + ". MSG:\"" + sb.toString() + "\""); + } + String identifier = null; + try { + identifier = this.NamingAuthority.registerGSID(secInfo, null, null); + LOG.info("passed registerGSID without parent and Identifier for " + secInfo.getUser() + "."); + } + catch (Exception e) { + fail("test registerGSID without parent and Identifier for " + secInfo.getUser() + ". MSG: \"" + + e.getMessage() + "\""); + } + + try { + this.NamingAuthority.registerGSID(secInfo, null, new String[] { identifier, " ", "" }); + LOG.info("passed test registerGSID with parentIdentifiers not null for " + secInfo.getUser() + "."); + } + catch (Exception e) { + fail("test registerGSID with parentIdentifiers not null for " + secInfo.getUser() + ". MSG: \"" + + e.getMessage() + "\""); + } + identifier = "5784d1dd-9373-533e-8086-fd479fbd564e"; + try { + identifier = this.NamingAuthority.registerGSID(secInfo, identifier, null); + LOG.info("passed test registerGSID with suggestedIdentifier not null for " + secInfo.getUser() + ". id: " + + identifier); + } + catch (Exception e) { + fail("test registerGSID with suggestedIdentifier not null for " + secInfo.getUser() + ". MSG: \"" + + e.getMessage() + "\""); + } + + try { + identifier = this.NamingAuthority.registerGSID(secInfo, identifier, new String[] { identifier, " ", "" }); + fail("test registerGSID with suggestedIdentifier and parent identifiers as not null and with suggestedIdentifier as one of the member in the parent identifier " + + secInfo.getUser()); + } + catch (Exception e) { + LOG.info("test registerGSID with suggestedIdentifier and parent identifiers as not null and with suggestedIdentifier as one of the member in the parent identifier " + + secInfo.getUser()); + } + } + + @Test + public void testRegisterSite() { + SecurityInfo secInfo = new SecurityInfoImpl("User2"); + + try { + this.NamingAuthority.registerSite(secInfo, "a", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", + "443", "SB"); + LOG.info("passed registerSite for " + secInfo.getUser() + "."); + } + catch (Exception e) { + fail("test registeSite for " + secInfo.getUser() + ". MSG: \"" + e.getMessage() + "\""); + e.getStackTrace(); + } + + try { + this.NamingAuthority.registerSite(secInfo, "a1", "a1", "1.01", "srikalyan1", "srikalyan1@semanticbits.com", + "4431", "SB"); + fail("test registeSite for user " + secInfo.getUser() + "."); + } + catch (Exception e) { + LOG.info("passed registerSite for " + secInfo.getUser() + " for registiering again. MSG: \"" + + e.getMessage() + "\""); + } + + } + + @Test + public void testAddSite() { + SecurityInfo secInfo = new SecurityInfoImpl("Unknown"); + try { + this.NamingAuthority.addSite(secInfo, null); + fail("test addSite with null identifier and unregistered user for " + secInfo.getUser() + "."); + } + catch (Exception e) { + LOG.info("passed addSite with null identifier and unregistered user for " + secInfo.getUser() + ". MSG: " + + e.getMessage() + "\""); + } + + secInfo = new SecurityInfoImpl("User3"); + + try { + this.NamingAuthority.registerSite(secInfo, "a", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", + "443", "SB"); + LOG.info("passed registerSite for " + secInfo.getUser() + " inorder to test addSite."); + } + catch (Exception e) { + fail("test registeSite for " + secInfo.getUser() + ". MSG: \"" + e.getMessage() + "\""); + } + + String identifier = null; + try { + this.NamingAuthority.addSite(secInfo, identifier); + fail("test addSite with null identifier and registered user for " + secInfo.getUser() + "."); + } + catch (Exception e) { + LOG.info("passed addSite with null identifier and registered user for " + secInfo.getUser() + ". MSG: \"" + + e.getMessage() + "\""); + } + + try { + identifier = this.NamingAuthority.registerGSID(secInfo, null, null); + LOG.info("passed registerGSID for " + secInfo.getUser() + " to test addSite."); + } + catch (Exception e) { + fail("test registerGSID for " + secInfo.getUser() + " to test addSite. MSG: \"" + e.getMessage() + "\""); + } + + secInfo = new SecurityInfoImpl("User4"); + + try { + this.NamingAuthority.registerSite(secInfo, "a", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", + "443", "SB"); + LOG.info("passed registerSite for " + secInfo.getUser() + " inorder to test addSite."); + } + catch (Exception e) { + fail("test registeSite for " + secInfo.getUser() + " inorder to test addSite. MSG: \"" + e.getMessage() + + "\""); + } + + try { + this.NamingAuthority.addSite(secInfo, identifier); + LOG.info("passed addSite with valid identifier for " + secInfo.getUser() + "."); + } + catch (Exception e) { + fail("test addSite for " + secInfo.getUser() + ". MSG: " + e.getMessage() + "\""); + } + + identifier = "5784d1dd-9373-433e-8086-fd479fbd564e"; + try { + this.NamingAuthority.addSite(secInfo, identifier); + fail("test addSite with invalid identifier for " + secInfo.getUser() + " "); + } + catch (Exception e) { + LOG.info("passed addSite with invalid identifier for " + secInfo.getUser() + ""); + } + + } + + @Test + public void testCreateBatchIdentifiers() { + SecurityInfoImpl secInfo = new SecurityInfoImpl("null"); + try { + this.NamingAuthority.createBatchIdentifiers(secInfo, 0); + fail("test createBatchIdentifiers for user " + secInfo.getUser() + "."); + } + catch (Exception e) { + LOG.info("passed createBatchIdentifiers for " + secInfo.getUser() + "."); + } + + secInfo = new SecurityInfoImpl("User5"); + + + try { + this.NamingAuthority.registerSite(secInfo, "a", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", + "443", "SB"); + LOG.info("passed registerSite inorder to test createBatchIdentifiers for user " + secInfo.getUser() + "."); + } + catch (Exception e) { + fail("test registeSite for user " + secInfo.getUser() + " to test creatBatchIdentifiers. MSG:\"" + + e.getMessage() + "\""); + } + try { + this.NamingAuthority.createBatchIdentifiers(secInfo, 10); + LOG.info("passed createBatchIdentifiers for valid number for " + secInfo.getUser() + "."); + } + catch (Exception e) { + fail("test createBatchIdentifiers for valid number for " + secInfo.getUser() + "."); + } + + try { + this.NamingAuthority.createBatchIdentifiers(secInfo, 102); + fail("test createBatchIdentifiers for invalid number for " + secInfo.getUser() + "."); + } + catch (Exception e) { + LOG.info("passed createBatchIdentifiers for invalid number for " + secInfo.getUser() + "."); + } + + try { + this.NamingAuthority.createBatchIdentifiers(secInfo, -1); + fail("test createBatchIdentifiers for invalid number for " + secInfo.getUser() + "."); + } + catch (Exception e) { + LOG.info("passed createBatchIdentifiers for invalid number for " + secInfo.getUser() + "."); + } + } + + public void testGetParentHierarchy() { + + SecurityInfo secInfo = new SecurityInfoImpl("User6"); + String identifier = null; + Tree tree = null; + try { + tree = this.NamingAuthority.getParentHierarchy(null, null); + fail("test getParentHierarchy for user null and identifier null"); + } + catch (Exception e) { + LOG.info("passed getParentHierarchy for user null and identifier null"); + } + + try { + this.NamingAuthority.registerSite(secInfo, "a", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", + "443", "SB"); + LOG.info("passed registerSite inorder to test getParentHierarchy for user " + secInfo.getUser()); + } + catch (Exception e) { + fail("test registeSite for user " + secInfo.getUser() + ". MSG:\"" + e.getMessage() + "\""); + } + + try { + identifier = this.NamingAuthority.registerGSID(secInfo, null, null); + LOG.info("passed registerGSID without parent and Identifier for " + secInfo.getUser() + "."); + } + catch (Exception e) { + fail("test registerGSID without parent and Identifier for " + secInfo.getUser() + ". MSG: \"" + + e.getMessage() + "\""); + } + + try { + tree = this.NamingAuthority.getParentHierarchy(null, identifier); + LOG.info("passed getParentHierarchy for user null and identifier having no parent"); + printTree(tree); + } + catch (Exception e) { + fail("test getParentHierarchy for user null and identifier having no parent"); + } + + try { + identifier = this.NamingAuthority.registerGSID(secInfo, null, new String[] { identifier }); + LOG.info("passed registerGSID with parent for " + secInfo.getUser() + "."); + } + catch (Exception e) { + fail("test registerGSID with parent for " + secInfo.getUser() + ". MSG: \"" + e.getMessage() + "\""); + } + + try { + tree = this.NamingAuthority.getParentHierarchy(null, identifier); + LOG.info("passed getParentHierarchy for user null and identifier having more than one parent"); + printTree(tree); + } + catch (Exception e) { + fail("test getParentHierarchy for user null and identifier having more than one parent"); + } + } + + @Test + public void testGetChildHierarchy() { + SecurityInfo secInfo = new SecurityInfoImpl("User7"); + String identifier1 = null; + Tree tree = null; + try { + tree = this.NamingAuthority.getChildHierarchy(null, null); + fail("test getChildHierarchy for user null and identifier null"); + } + catch (Exception e) { + LOG.info("passed getChildHierarchy for user null and identifier null"); + } + + try { + this.NamingAuthority.registerSite(secInfo, "a", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", + "443", "SB"); + LOG.info("passed registerSite inorder to test getChildHierarchy for user " + secInfo.getUser()); + } + catch (Exception e) { + fail("test registeSite for user " + secInfo.getUser() + ". MSG:\"" + e.getMessage() + "\""); + } + + try { + identifier1 = this.NamingAuthority.registerGSID(secInfo, null, null); + LOG.info("passed registerGSID without child and Identifier for " + secInfo.getUser() + "."); + } + catch (Exception e) { + fail("test registerGSID without child and Identifier for " + secInfo.getUser() + ". MSG: \"" + + e.getMessage() + "\""); + } + + try { + tree = this.NamingAuthority.getChildHierarchy(null, identifier1); + LOG.info("passed getChildHierarchy for user null and identifier having no child"); + printTree(tree); + } + catch (Exception e) { + fail("test getChildHierarchy for user null and identifier having no child"); + } + String identifier2 = null; + try { + identifier2 = this.NamingAuthority.registerGSID(secInfo, null, new String[] { identifier1 }); + LOG.info("passed registerGSID with child for " + secInfo.getUser() + "."); + } + catch (Exception e) { + fail("test registerGSID with child for " + secInfo.getUser() + ". MSG: \"" + e.getMessage() + "\""); + } + + try { + tree = this.NamingAuthority.getChildHierarchy(null, identifier1); + LOG.info("passed getChildHierarchy for user null and identifier having more than one child"); + printTree(tree); + } + catch (Exception e) { + fail("test getChildHierarchy for user null and identifier having more than one child"); + } + } + + @Test + public void testValidateIdentifier() { + String identifier = null; + SecurityInfo secInfo = null; + boolean isValid; + try { + isValid = this.NamingAuthority.validateIdentifier(secInfo, identifier); + fail("test validateIdentifier for null Identifier"); + } + catch (Exception e) { + LOG.info("passed validateIdentifier for null Identifier"); + } + + identifier = "b08e7909-401d-4949-9f6d-2c8d8366b173"; + + try { + isValid = this.NamingAuthority.validateIdentifier(secInfo, identifier); + LOG.info("passed validateIdentifier for not null Identifier"); + } + catch (Exception e) { + fail("test validateIdentifier for not null Identifier"); + } + identifier = "b08e7909-401d-9f6d-2c8d8366b173"; + try { + isValid = this.NamingAuthority.validateIdentifier(secInfo, identifier); + fail("test validateIdentifier for invalid Identifier"); + } + catch (Exception e) { + LOG.info("passed validateIdentifier for invalid Identifier"); + } + + } + + @Test + public void testResolveIdentifier() { + URI identifier = null; + String identifier1 = null; + SecurityInfo secInfo = null; + IdentifierData id = null; + try { + id = this.NamingAuthority.resolveIdentifier(secInfo, identifier); + fail("test resolveIdentifier for null user and null identifier"); + } + catch (Exception e) { + LOG.info("passed resolveIdentifier for null user and null identifier"); + } + secInfo = new SecurityInfoImpl("User8"); + try { + this.NamingAuthority.registerSite(secInfo, "a", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com", + "443", "SB"); + LOG.info("passed registerSite for " + secInfo.getUser() + " inorder to test resolveIdentifier."); + } + catch (Exception e) { + fail("test registeSite for " + secInfo.getUser() + ". MSG: \"" + e.getMessage() + "\""); + } + + try { + identifier1 = this.NamingAuthority.registerGSID(secInfo, null, null); + LOG.info("passed registerGSID for " + secInfo.getUser() + " to test resolveIdentifier."); + } + catch (Exception e) { + fail("test registerGSID for " + secInfo.getUser() + " to test resolveIdentifier. MSG: \"" + e.getMessage() + + "\""); + } + + try { + Thread.sleep(1000); + identifier = new URI(identifier1); + id = this.NamingAuthority.resolveIdentifier(secInfo, identifier); + if (id == null) { + fail("test resolveIdentifier for null user and valid identifier"); + } + else { + LOG.info("passed resolveIdentifier for null user and valid identifier"); + printData(id); + } + } + catch (Exception e) { + fail("test resolveIdentifier for null user and not null identifier " + identifier1); + } + + } + + private void printData(IdentifierData id) { + if (id != null) { + for (String key : id.getKeys()) { + KeyData values = id.getValues(key); + if (values != null) { + LOG.info(key + ": " + values.getValues()); + } + } + } + } + + private void printTree(Tree tree) { + if (tree == null) { + return; + } + String tabber = ""; + printTree(tree, tabber); + } + + private void printTree(Tree tree, String tabber) { + if (tree == null) + return; + LOG.info(tabber + tree.getIdentifier()); + if (tree.getChildren() != null && tree.getChildren().size() > 0) + for (Tree child : tree.getChildren()) + printTree(child, tabber + "\t"); + } + +} diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/Pair.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/Pair.java index 195bb72..7b76e19 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/Pair.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/Pair.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority; public class Pair diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/StressTestCase.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/StressTestCase.java index d5a986a..d7c7d96 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/StressTestCase.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/StressTestCase.java @@ -1,97 +1,106 @@ -package org.cagrid.identifiers.namingauthority; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; -import org.cagrid.identifiers.namingauthority.test.NamingAuthorityTestCaseBase; -import org.junit.Test; - -public class StressTestCase -{ - @Test - public void testStress() throws Exception - { - long numberOfTests = StressTestUtil.avgNumOfTests = 100l; - int[] numberOfThreadz = { 1}; - int threadPool = 50; - for (int numberOfThreads : numberOfThreadz ) - { - System.out.println("\n\n\n*********************************************************************"); - System.out.println("The number of threads "+numberOfThreads); - double average = 0; - SecurityInfo client = new SecurityInfoImpl("srikalyan"); - TestName[] tests = { TestName.REGISTER_GSID, TestName.PARENT_HIERARCHY, TestName.CHILD_HIERARCHY, - TestName.VALIDATE_IDENTIFIER, TestName.RESOLVE_IDENTIFIER, TestName.ADD_SITE, - TestName.BATCH_IDENTIFIERS, TestName.ALL }; - for (TestName testName : tests) - { - - // this.NamingAuthority.registerSite(client, "site", "a", "1.0", - // "srikalyan", "srikalyan@semanticbits.com","443-481-7555", - // "sb"); - ExecutorService executor = Executors.newFixedThreadPool(threadPool); - List> futures = new ArrayList>(); - List temp = new ArrayList(); - if (testName == TestName.REGISTER_GSID) - StressTestUtil.recreateTempFile(); - Thread.sleep(10000); - long startStress = System.currentTimeMillis(); - for (int i = 0; i < numberOfThreads; i++) - { - String threadName = "" + i; - StressTestUtil thread = new StressTestUtil(threadName, numberOfTests, testName, client);// ,new - // TestUtil(this.NamingAuthority)); - Future future = executor.submit(thread, thread); - futures.add(future); - } - for (Future future : futures) - { - try - { - StressTestUtil e = future.get(); - } - catch (InterruptedException e) - { - System.out.println("Interrupted Exception occured " + e.getMessage()); - } - catch (ExecutionException e) - { - System.out.println("Execution Exception occured " + e.getMessage()); - } - } - long endStress = System.currentTimeMillis(); - System.out.println("##############################################################"); - - System.out.println(" the duration test " + testName.name() + " is " + (endStress - startStress)); - average = ((double) (endStress - startStress)) - / (((double) numberOfTests) * ((double) numberOfThreads) * 1000.0); - System.out.println("the avg process is " + average); - Map> threadTime = StressTestUtil.getThreadTime(); - // System.out.println("##############################################################"); - // System.out.println("Number of Threads "+numberOfThreads); - long total = 0; - for (String key : threadTime.keySet()) - { - // System.out.println("Thread: "+key); - Pair currentThreadPair = threadTime.get(key); - // System.out.println("Start Time: "+currentThreadPair.start); - // System.out.println("End Time: "+currentThreadPair.finish); - long diff = currentThreadPair.finish - currentThreadPair.start; - // System.out.println("Duration: "+diff); - total += diff; - } - average = (double) total / (((double) numberOfTests) * ((double) numberOfThreads) * 1000.0); - System.out.println("The average response time is " + average); - System.out.println("##############################################################"); - executor.shutdown(); - Thread.sleep(10000); - } - } - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.cagrid.identifiers.namingauthority.impl.SecurityInfoImpl; +import org.cagrid.identifiers.namingauthority.test.NamingAuthorityTestCaseBase; +import org.junit.Test; + +public class StressTestCase +{ + @Test + public void testStress() throws Exception + { + long numberOfTests = StressTestUtil.avgNumOfTests = 100l; + int[] numberOfThreadz = { 1}; + int threadPool = 50; + for (int numberOfThreads : numberOfThreadz ) + { + System.out.println("\n\n\n*********************************************************************"); + System.out.println("The number of threads "+numberOfThreads); + double average = 0; + SecurityInfo client = new SecurityInfoImpl("srikalyan"); + TestName[] tests = { TestName.REGISTER_GSID, TestName.PARENT_HIERARCHY, TestName.CHILD_HIERARCHY, + TestName.VALIDATE_IDENTIFIER, TestName.RESOLVE_IDENTIFIER, TestName.ADD_SITE, + TestName.BATCH_IDENTIFIERS, TestName.ALL }; + for (TestName testName : tests) + { + + // this.NamingAuthority.registerSite(client, "site", "a", "1.0", + // "srikalyan", "srikalyan@semanticbits.com","443-481-7555", + // "sb"); + ExecutorService executor = Executors.newFixedThreadPool(threadPool); + List> futures = new ArrayList>(); + List temp = new ArrayList(); + if (testName == TestName.REGISTER_GSID) + StressTestUtil.recreateTempFile(); + Thread.sleep(10000); + long startStress = System.currentTimeMillis(); + for (int i = 0; i < numberOfThreads; i++) + { + String threadName = "" + i; + StressTestUtil thread = new StressTestUtil(threadName, numberOfTests, testName, client);// ,new + // TestUtil(this.NamingAuthority)); + Future future = executor.submit(thread, thread); + futures.add(future); + } + for (Future future : futures) + { + try + { + StressTestUtil e = future.get(); + } + catch (InterruptedException e) + { + System.out.println("Interrupted Exception occured " + e.getMessage()); + } + catch (ExecutionException e) + { + System.out.println("Execution Exception occured " + e.getMessage()); + } + } + long endStress = System.currentTimeMillis(); + System.out.println("##############################################################"); + + System.out.println(" the duration test " + testName.name() + " is " + (endStress - startStress)); + average = ((double) (endStress - startStress)) + / (((double) numberOfTests) * ((double) numberOfThreads) * 1000.0); + System.out.println("the avg process is " + average); + Map> threadTime = StressTestUtil.getThreadTime(); + // System.out.println("##############################################################"); + // System.out.println("Number of Threads "+numberOfThreads); + long total = 0; + for (String key : threadTime.keySet()) + { + // System.out.println("Thread: "+key); + Pair currentThreadPair = threadTime.get(key); + // System.out.println("Start Time: "+currentThreadPair.start); + // System.out.println("End Time: "+currentThreadPair.finish); + long diff = currentThreadPair.finish - currentThreadPair.start; + // System.out.println("Duration: "+diff); + total += diff; + } + average = (double) total / (((double) numberOfTests) * ((double) numberOfThreads) * 1000.0); + System.out.println("The average response time is " + average); + System.out.println("##############################################################"); + executor.shutdown(); + Thread.sleep(10000); + } + } + } +} diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/StressTestUtil.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/StressTestUtil.java index 9667624..2377553 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/StressTestUtil.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/StressTestUtil.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority; import java.io.BufferedReader; diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/TestName.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/TestName.java index b71a60c..e641274 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/TestName.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/TestName.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority; public enum TestName diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/TestUtil.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/TestUtil.java index 2561930..5bba75e 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/TestUtil.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/TestUtil.java @@ -1,3 +1,12 @@ +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + package org.cagrid.identifiers.namingauthority; diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/hibernate/HibernateMappingTestCase.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/hibernate/HibernateMappingTestCase.java index b971093..19b45cb 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/hibernate/HibernateMappingTestCase.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/hibernate/HibernateMappingTestCase.java @@ -1,46 +1,55 @@ -package org.cagrid.identifiers.namingauthority.hibernate; - -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.cagrid.identifiers.namingauthority.test.NamingAuthorityIntegrationTestCaseBase; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.persister.entity.EntityPersister; - - -public class HibernateMappingTestCase extends NamingAuthorityIntegrationTestCaseBase { - - protected SessionFactory sessionFactory; - - - public void testEverything() throws Exception { - Map metadata = sessionFactory.getAllClassMetadata(); - String className = ""; - for (Iterator i = metadata.values().iterator(); i.hasNext();) { - Session session = sessionFactory.openSession(); - try { - EntityPersister persister = (EntityPersister) i.next(); - className = persister.getEntityName(); - System.out.println("select: " + className); - List result = session.createQuery("from " + className + " c").list(); - System.out.println("returned " + result.size() + " records for " + - className); - - assertTrue(true); - - } catch (Exception ex) { - fail("Hibernate mapping error. Following class has incorrect mapping: " + className); - } finally { - session.close(); - } - } - } - - - public void setSessionFactory(SessionFactory sessionFactory) { - this.sessionFactory = sessionFactory; - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.hibernate; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.cagrid.identifiers.namingauthority.test.NamingAuthorityIntegrationTestCaseBase; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.persister.entity.EntityPersister; + + +public class HibernateMappingTestCase extends NamingAuthorityIntegrationTestCaseBase { + + protected SessionFactory sessionFactory; + + + public void testEverything() throws Exception { + Map metadata = sessionFactory.getAllClassMetadata(); + String className = ""; + for (Iterator i = metadata.values().iterator(); i.hasNext();) { + Session session = sessionFactory.openSession(); + try { + EntityPersister persister = (EntityPersister) i.next(); + className = persister.getEntityName(); + System.out.println("select: " + className); + List result = session.createQuery("from " + className + " c").list(); + System.out.println("returned " + result.size() + " records for " + + className); + + assertTrue(true); + + } catch (Exception ex) { + fail("Hibernate mapping error. Following class has incorrect mapping: " + className); + } finally { + session.close(); + } + } + } + + + public void setSessionFactory(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + +} diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/NamingAuthorityIntegrationTestCaseBase.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/NamingAuthorityIntegrationTestCaseBase.java index 350e02c..8ef6a94 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/NamingAuthorityIntegrationTestCaseBase.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/NamingAuthorityIntegrationTestCaseBase.java @@ -1,18 +1,27 @@ -package org.cagrid.identifiers.namingauthority.test; - -import org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests; - - -public abstract class NamingAuthorityIntegrationTestCaseBase extends AbstractAnnotationAwareTransactionalTests { - - public NamingAuthorityIntegrationTestCaseBase() { - setPopulateProtectedVariables(true); - } - - - @Override - protected String[] getConfigLocations() { - return new String[]{SpringTestApplicationContextConstants.NA_BASE_LOCATION, - SpringTestApplicationContextConstants.TEST_BASE_LOCATION}; - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.test; + +import org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests; + + +public abstract class NamingAuthorityIntegrationTestCaseBase extends AbstractAnnotationAwareTransactionalTests { + + public NamingAuthorityIntegrationTestCaseBase() { + setPopulateProtectedVariables(true); + } + + + @Override + protected String[] getConfigLocations() { + return new String[]{SpringTestApplicationContextConstants.NA_BASE_LOCATION, + SpringTestApplicationContextConstants.TEST_BASE_LOCATION}; + } +} diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/NamingAuthorityTestCaseBase.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/NamingAuthorityTestCaseBase.java index 4be2491..0cb4e96 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/NamingAuthorityTestCaseBase.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/NamingAuthorityTestCaseBase.java @@ -1,152 +1,161 @@ -package org.cagrid.identifiers.namingauthority.test; - -import java.net.URI; -import java.util.Arrays; -import java.util.List; - -import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; -import org.cagrid.identifiers.namingauthority.InvalidIdentifierValuesException; -import org.cagrid.identifiers.namingauthority.MaintainerNamingAuthority; -import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; -import org.cagrid.identifiers.namingauthority.domain.IdentifierData; -import org.cagrid.identifiers.namingauthority.domain.KeyData; -import org.cagrid.identifiers.namingauthority.util.SecurityUtil; - - -public abstract class NamingAuthorityTestCaseBase extends NamingAuthorityIntegrationTestCaseBase { - protected MaintainerNamingAuthority NamingAuthority; - - - @Override - protected void onSetUp() throws Exception { - super.onSetUp(); - assertNotNull(this.NamingAuthority); - } - - protected void checkKeysWithValues(IdentifierData resolvedValues, String[] keyNames) { - - for(String key : keyNames) { - List values = null; - try { - values = resolvedValues.getValues(key).getValues(); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - - if (values.size() == 0) { - fail("Keys has no values"); - } - } - } - - protected void assertKeyValues(IdentifierData values, String[] keyNames) { - URI id = null; - try { - id = this.NamingAuthority.createIdentifier(null, values); - } catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - fail("test configuration error"); - - } catch (InvalidIdentifierValuesException e) { - fail("Unexpected failure on creation:" + e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - fail("test configuration error"); - } - - KeyData resolvedValues = null; - - for(String key : keyNames) { - try { - resolvedValues = this.NamingAuthority.getKeyData(null, id, key); - } catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - fail("test configuration error"); - } catch (InvalidIdentifierException e) { - fail("Unexpected failure on resolution:" + e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - fail("test configuration error"); - } - List inValues = values.getValues(key).getValues(); - assertEquals(inValues.toArray(new String[inValues.size()]), resolvedValues.getValuesAsArray()); - } - } - - protected void assertKeys(IdentifierData values) { - URI id = null; - try { - id = this.NamingAuthority.createIdentifier(null, values); - } catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - fail("test configuration error"); - - } catch (InvalidIdentifierValuesException e) { - fail("Unexpected failure on creation:" + e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - fail("test configuration error"); - } - - String[] resolvedKeys = null; - - try { - resolvedKeys = this.NamingAuthority.getKeyNames(null, id); - } catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - fail("test configuration error"); - } catch (InvalidIdentifierException e) { - fail("Unexpected failure on resolution:" + e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - fail("test configuration error"); - } - assertEquals(values.getKeys(), resolvedKeys); - } - - protected void assertResolvedValues(IdentifierData values) { - URI id = null; - try { - id = this.NamingAuthority.createIdentifier(null, values); - } catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - fail("test configuration error"); - - } catch (InvalidIdentifierValuesException e) { - fail("Unexpected failure on creation:" + e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - fail("test configuration error"); - } - - IdentifierData resolvedValues = null; - - try { - resolvedValues = this.NamingAuthority.resolveIdentifier(null, id); - } catch (NamingAuthorityConfigurationException e) { - e.printStackTrace(); - fail("test configuration error"); - } catch (InvalidIdentifierException e) { - fail("Unexpected failure on resolution:" + e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - fail("test configuration error"); - } - assertEquals(values, resolvedValues); - } - - protected void assertEquals(String[] arr1, String[] arr2) { - - Arrays.sort(arr1); - Arrays.sort(arr2); - - assertEquals(Arrays.asList(arr1), Arrays.asList(arr2)); - } - - protected URI getSystemIdentifier() { - return URI.create(this.NamingAuthority.getConfiguration() - .getNaPrefixURI().normalize().toString() - + SecurityUtil.LOCAL_SYSTEM_IDENTIFIER); - } -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.test; + +import java.net.URI; +import java.util.Arrays; +import java.util.List; + +import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; +import org.cagrid.identifiers.namingauthority.InvalidIdentifierValuesException; +import org.cagrid.identifiers.namingauthority.MaintainerNamingAuthority; +import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; +import org.cagrid.identifiers.namingauthority.domain.IdentifierData; +import org.cagrid.identifiers.namingauthority.domain.KeyData; +import org.cagrid.identifiers.namingauthority.util.SecurityUtil; + + +public abstract class NamingAuthorityTestCaseBase extends NamingAuthorityIntegrationTestCaseBase { + protected MaintainerNamingAuthority NamingAuthority; + + + @Override + protected void onSetUp() throws Exception { + super.onSetUp(); + assertNotNull(this.NamingAuthority); + } + + protected void checkKeysWithValues(IdentifierData resolvedValues, String[] keyNames) { + + for(String key : keyNames) { + List values = null; + try { + values = resolvedValues.getValues(key).getValues(); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + if (values.size() == 0) { + fail("Keys has no values"); + } + } + } + + protected void assertKeyValues(IdentifierData values, String[] keyNames) { + URI id = null; + try { + id = this.NamingAuthority.createIdentifier(null, values); + } catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + fail("test configuration error"); + + } catch (InvalidIdentifierValuesException e) { + fail("Unexpected failure on creation:" + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + fail("test configuration error"); + } + + KeyData resolvedValues = null; + + for(String key : keyNames) { + try { + resolvedValues = this.NamingAuthority.getKeyData(null, id, key); + } catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + fail("test configuration error"); + } catch (InvalidIdentifierException e) { + fail("Unexpected failure on resolution:" + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + fail("test configuration error"); + } + List inValues = values.getValues(key).getValues(); + assertEquals(inValues.toArray(new String[inValues.size()]), resolvedValues.getValuesAsArray()); + } + } + + protected void assertKeys(IdentifierData values) { + URI id = null; + try { + id = this.NamingAuthority.createIdentifier(null, values); + } catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + fail("test configuration error"); + + } catch (InvalidIdentifierValuesException e) { + fail("Unexpected failure on creation:" + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + fail("test configuration error"); + } + + String[] resolvedKeys = null; + + try { + resolvedKeys = this.NamingAuthority.getKeyNames(null, id); + } catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + fail("test configuration error"); + } catch (InvalidIdentifierException e) { + fail("Unexpected failure on resolution:" + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + fail("test configuration error"); + } + assertEquals(values.getKeys(), resolvedKeys); + } + + protected void assertResolvedValues(IdentifierData values) { + URI id = null; + try { + id = this.NamingAuthority.createIdentifier(null, values); + } catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + fail("test configuration error"); + + } catch (InvalidIdentifierValuesException e) { + fail("Unexpected failure on creation:" + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + fail("test configuration error"); + } + + IdentifierData resolvedValues = null; + + try { + resolvedValues = this.NamingAuthority.resolveIdentifier(null, id); + } catch (NamingAuthorityConfigurationException e) { + e.printStackTrace(); + fail("test configuration error"); + } catch (InvalidIdentifierException e) { + fail("Unexpected failure on resolution:" + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + fail("test configuration error"); + } + assertEquals(values, resolvedValues); + } + + protected void assertEquals(String[] arr1, String[] arr2) { + + Arrays.sort(arr1); + Arrays.sort(arr2); + + assertEquals(Arrays.asList(arr1), Arrays.asList(arr2)); + } + + protected URI getSystemIdentifier() { + return URI.create(this.NamingAuthority.getConfiguration() + .getNaPrefixURI().normalize().toString() + + SecurityUtil.LOCAL_SYSTEM_IDENTIFIER); + } +} diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/SpringTestApplicationContextConstants.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/SpringTestApplicationContextConstants.java index 09ec7ef..185ecdd 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/SpringTestApplicationContextConstants.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/SpringTestApplicationContextConstants.java @@ -1,11 +1,20 @@ -package org.cagrid.identifiers.namingauthority.test; - -public interface SpringTestApplicationContextConstants { - - public static final String SPRING_CLASSPATH_PREFIX = "classpath*:"; - public static final String SPRING_FILE_PREFIX = "file:"; - - public static final String NA_BASE_LOCATION = SPRING_FILE_PREFIX + "WebContent/WEB-INF/applicationContext-na.xml"; - public static final String TEST_BASE_LOCATION = SPRING_CLASSPATH_PREFIX + "test-applicationContext-properties.xml"; - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.test; + +public interface SpringTestApplicationContextConstants { + + public static final String SPRING_CLASSPATH_PREFIX = "classpath*:"; + public static final String SPRING_FILE_PREFIX = "file:"; + + public static final String NA_BASE_LOCATION = SPRING_FILE_PREFIX + "WebContent/WEB-INF/applicationContext-na.xml"; + public static final String TEST_BASE_LOCATION = SPRING_CLASSPATH_PREFIX + "test-applicationContext-properties.xml"; + +} diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/TestInstantiationException.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/TestInstantiationException.java index 6f5213e..8f7a981 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/TestInstantiationException.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/test/TestInstantiationException.java @@ -1,23 +1,32 @@ -package org.cagrid.identifiers.namingauthority.test; - -public class TestInstantiationException extends Exception { - - public TestInstantiationException() { - } - - - public TestInstantiationException(String message) { - super(message); - } - - - public TestInstantiationException(Throwable cause) { - super(cause); - } - - - public TestInstantiationException(String message, Throwable cause) { - super(message, cause); - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.test; + +public class TestInstantiationException extends Exception { + + public TestInstantiationException() { + } + + + public TestInstantiationException(String message) { + super(message); + } + + + public TestInstantiationException(Throwable cause) { + super(cause); + } + + + public TestInstantiationException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/util/IdentifierUtilTestCase.java b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/util/IdentifierUtilTestCase.java index 028eab9..edb9473 100644 --- a/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/util/IdentifierUtilTestCase.java +++ b/identifiers-namingauthority/test/src/org/cagrid/identifiers/namingauthority/util/IdentifierUtilTestCase.java @@ -1,119 +1,128 @@ -package org.cagrid.identifiers.namingauthority.util; - -import java.net.URI; -import java.net.URISyntaxException; - -import junit.framework.TestCase; - -import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; -import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; -import org.junit.Test; - - -public class IdentifierUtilTestCase extends TestCase { - - @Test - public void testInvalidPrefixes() { - assertInvalidPrefix(""); - assertInvalidPrefix("asdf"); - assertInvalidPrefix("http://foo.com/?foo"); - assertInvalidPrefix("http://foo.com/#foo"); - assertInvalidPrefix("http://foo.com/?foo#foo"); - assertInvalidPrefix("http://foo.com"); - assertInvalidPrefix("http://foo.com/a/b"); - } - - - public void testInvalidIdentifiers() { - assertInvalidIdentifier("http://foo.com/", "http://foo.com"); - assertInvalidIdentifier("http://foo.com/", "http://foo.com/"); - assertInvalidIdentifier("http://foo.com/", ""); - assertInvalidIdentifier("http://foo.com/", "http://foobar.com/asdf"); - assertInvalidIdentifier("http://foo.com/", "http://foobar.com/asdf/asdf"); - assertInvalidIdentifier("http://foo.com/asdf/", "http://foobar.com/../asdf"); - assertInvalidIdentifier("http://foo.com/asdf/", "http://foobar.com/../a"); - - } - - - private void assertInvalidIdentifier(String prefix, String identifier) { - try { - IdentifierUtil.verifyPrefix(new URI(prefix)); - } catch (URISyntaxException e) { - e.printStackTrace(); - fail("Test configuration issue."); - } catch (Exception e) { - fail("Unexpected exception for prefix (" + prefix + ")."); - } - - try { - IdentifierUtil.getLocalName(new URI(prefix), new URI(identifier)); - fail("Excepted exception was not thrown for prefix (" + prefix + ") and id (" + identifier + ")"); - } catch (URISyntaxException e) { - e.printStackTrace(); - fail("Test configuration issue."); - } catch (InvalidIdentifierException e) { - // expected - } catch (Exception e) { - fail("Unexpected exception for prefix (" + prefix + ") and id (" + identifier + ") :" + e.getMessage()); - } - - } - - - private void assertInvalidPrefix(String prefix) { - try { - IdentifierUtil.verifyPrefix(new URI(prefix)); - fail("Expected exception for invalid prefix (" + prefix + "), but it was not thrown."); - } catch (URISyntaxException e) { - e.printStackTrace(); - fail("Test configuration issue."); - } catch (IllegalArgumentException e) { - // expected - } catch (Exception e) { - fail("Expected exception for invalid prefix (" + prefix + "), but unexcepted Exception type thrown (" - + e.getClass() + ")."); - } - } - - - @Test - public void testBuild() throws URISyntaxException, NamingAuthorityConfigurationException { - URI prefix = new URI("http://na.cagrid.org/foo/"); - URI shortID = new URI("http://na.cagrid.org/foo/1"); - - // NOTE: our current algorithm treats this as the same, as the localName - // isn't just a "string" its a relative path in a URI - assertEquals(shortID, IdentifierUtil.build(prefix, URI.create("1"))); - assertEquals(shortID, IdentifierUtil.build(prefix, URI.create("/1"))); - assertEquals(shortID, IdentifierUtil.build(prefix, URI.create("./1"))); - assertEquals(shortID, IdentifierUtil.build(prefix, URI.create("../foo/1"))); - - URI longPrefix = new URI("http://na.cagrid.org/foo/bar/baz/"); - URI longID = new URI("http://na.cagrid.org/foo/bar/baz/foo/bar/"); - - assertEquals(longID, IdentifierUtil.build(longPrefix, URI.create("foo/bar/"))); - assertEquals(longID, IdentifierUtil.build(longPrefix, URI.create("/foo/bar/"))); - assertEquals(longID, IdentifierUtil.build(longPrefix, URI.create("./foo/bar/"))); - assertEquals(longID, IdentifierUtil.build(longPrefix, URI.create("../baz/foo/bar/"))); - } - - - @Test - public void testLocalName() throws URISyntaxException, InvalidIdentifierException, NamingAuthorityConfigurationException { - URI prefix = new URI("http://na.cagrid.org/foo/"); - URI shortID = new URI("http://na.cagrid.org/foo/1"); - - assertEquals(new URI("1"), IdentifierUtil.getLocalName(prefix, shortID)); - assertEquals(new URI("1"), IdentifierUtil.getLocalName(prefix, new URI("http://na.cagrid.org/foo/./1"))); - assertEquals(new URI("1"), IdentifierUtil.getLocalName(prefix, new URI("http://na.cagrid.org/foo/../foo/1"))); - - - URI longPrefix = new URI("http://na.cagrid.org/foo/bar/baz/"); - URI longID = new URI("http://na.cagrid.org/foo/bar/baz/foo/bar/"); - - assertEquals(new URI("foo/bar/"), IdentifierUtil.getLocalName(longPrefix, longID)); - - } - -} +/*L + * Copyright Washington University in St. Louis + * Copyright SemanticBits + * Copyright Persistent Systems + * + * Distributed under the OSI-approved BSD 3-Clause License. + * See http://ncip.github.com/gsid/LICENSE.txt for details. + */ + +package org.cagrid.identifiers.namingauthority.util; + +import java.net.URI; +import java.net.URISyntaxException; + +import junit.framework.TestCase; + +import org.cagrid.identifiers.namingauthority.InvalidIdentifierException; +import org.cagrid.identifiers.namingauthority.NamingAuthorityConfigurationException; +import org.junit.Test; + + +public class IdentifierUtilTestCase extends TestCase { + + @Test + public void testInvalidPrefixes() { + assertInvalidPrefix(""); + assertInvalidPrefix("asdf"); + assertInvalidPrefix("http://foo.com/?foo"); + assertInvalidPrefix("http://foo.com/#foo"); + assertInvalidPrefix("http://foo.com/?foo#foo"); + assertInvalidPrefix("http://foo.com"); + assertInvalidPrefix("http://foo.com/a/b"); + } + + + public void testInvalidIdentifiers() { + assertInvalidIdentifier("http://foo.com/", "http://foo.com"); + assertInvalidIdentifier("http://foo.com/", "http://foo.com/"); + assertInvalidIdentifier("http://foo.com/", ""); + assertInvalidIdentifier("http://foo.com/", "http://foobar.com/asdf"); + assertInvalidIdentifier("http://foo.com/", "http://foobar.com/asdf/asdf"); + assertInvalidIdentifier("http://foo.com/asdf/", "http://foobar.com/../asdf"); + assertInvalidIdentifier("http://foo.com/asdf/", "http://foobar.com/../a"); + + } + + + private void assertInvalidIdentifier(String prefix, String identifier) { + try { + IdentifierUtil.verifyPrefix(new URI(prefix)); + } catch (URISyntaxException e) { + e.printStackTrace(); + fail("Test configuration issue."); + } catch (Exception e) { + fail("Unexpected exception for prefix (" + prefix + ")."); + } + + try { + IdentifierUtil.getLocalName(new URI(prefix), new URI(identifier)); + fail("Excepted exception was not thrown for prefix (" + prefix + ") and id (" + identifier + ")"); + } catch (URISyntaxException e) { + e.printStackTrace(); + fail("Test configuration issue."); + } catch (InvalidIdentifierException e) { + // expected + } catch (Exception e) { + fail("Unexpected exception for prefix (" + prefix + ") and id (" + identifier + ") :" + e.getMessage()); + } + + } + + + private void assertInvalidPrefix(String prefix) { + try { + IdentifierUtil.verifyPrefix(new URI(prefix)); + fail("Expected exception for invalid prefix (" + prefix + "), but it was not thrown."); + } catch (URISyntaxException e) { + e.printStackTrace(); + fail("Test configuration issue."); + } catch (IllegalArgumentException e) { + // expected + } catch (Exception e) { + fail("Expected exception for invalid prefix (" + prefix + "), but unexcepted Exception type thrown (" + + e.getClass() + ")."); + } + } + + + @Test + public void testBuild() throws URISyntaxException, NamingAuthorityConfigurationException { + URI prefix = new URI("http://na.cagrid.org/foo/"); + URI shortID = new URI("http://na.cagrid.org/foo/1"); + + // NOTE: our current algorithm treats this as the same, as the localName + // isn't just a "string" its a relative path in a URI + assertEquals(shortID, IdentifierUtil.build(prefix, URI.create("1"))); + assertEquals(shortID, IdentifierUtil.build(prefix, URI.create("/1"))); + assertEquals(shortID, IdentifierUtil.build(prefix, URI.create("./1"))); + assertEquals(shortID, IdentifierUtil.build(prefix, URI.create("../foo/1"))); + + URI longPrefix = new URI("http://na.cagrid.org/foo/bar/baz/"); + URI longID = new URI("http://na.cagrid.org/foo/bar/baz/foo/bar/"); + + assertEquals(longID, IdentifierUtil.build(longPrefix, URI.create("foo/bar/"))); + assertEquals(longID, IdentifierUtil.build(longPrefix, URI.create("/foo/bar/"))); + assertEquals(longID, IdentifierUtil.build(longPrefix, URI.create("./foo/bar/"))); + assertEquals(longID, IdentifierUtil.build(longPrefix, URI.create("../baz/foo/bar/"))); + } + + + @Test + public void testLocalName() throws URISyntaxException, InvalidIdentifierException, NamingAuthorityConfigurationException { + URI prefix = new URI("http://na.cagrid.org/foo/"); + URI shortID = new URI("http://na.cagrid.org/foo/1"); + + assertEquals(new URI("1"), IdentifierUtil.getLocalName(prefix, shortID)); + assertEquals(new URI("1"), IdentifierUtil.getLocalName(prefix, new URI("http://na.cagrid.org/foo/./1"))); + assertEquals(new URI("1"), IdentifierUtil.getLocalName(prefix, new URI("http://na.cagrid.org/foo/../foo/1"))); + + + URI longPrefix = new URI("http://na.cagrid.org/foo/bar/baz/"); + URI longID = new URI("http://na.cagrid.org/foo/bar/baz/foo/bar/"); + + assertEquals(new URI("foo/bar/"), IdentifierUtil.getLocalName(longPrefix, longID)); + + } + +} diff --git a/identifiers-namingauthority/test/test.xml b/identifiers-namingauthority/test/test.xml index 170d32e..ea0e0fa 100644 --- a/identifiers-namingauthority/test/test.xml +++ b/identifiers-namingauthority/test/test.xml @@ -1,91 +1,100 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - commit; - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + commit; + + + + + diff --git a/identifiers-namingauthority/webapp.xml b/identifiers-namingauthority/webapp.xml index 819296c..95c30dc 100644 --- a/identifiers-namingauthority/webapp.xml +++ b/identifiers-namingauthority/webapp.xml @@ -1,56 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +