Scripts: UpdateCAKeyName: handle Email OIDs

Fixes an issue where where one CA was represented with a long string
where the OID representing the email address in a DN
(1.2.840.113549.1.9.1) was not decoded - an even the value was printed
out in hex, resulting into:

1.2.840.113549.1.9.1=#16197072656d69756d2d736572766572407468617774652e636f6d,CN=Thawte
Premium Server CA,OU=Certification Services Division,O=Thawte Consulting
cc,L=Cape Town,ST=Western Cape,C=ZA

Surprisingly, while c.getSubjectDN() nicely decodes the OID and the
value, getSubjectX500Principal().getName() does not.

As the c.getSubjectDN() method is deprecated ("denigrated"), we have to
use getSubjectX500Principal().  A suitable way forward is to use the
getName(String format, Map<String,String> oidMap) method and provide an
oidMap (using the newer format RFC2253 as the format)
MigScripts: Update refresh-db.sh to set CA names.

Update refresh-db.sh to invoke UpdateCADatabaseRecords.groovy to set CA
names.
Merge branch 'aaf-develop' into code-develop
Merge pull request #154 from University-of-Auckland/aaf-develop

Scripts: UpdateCAKeyName: handle Email OIDs
Tests: Copy missing resources.groovy among plugins

Copy missing resources.groovy from base plugin into api, administation
and reporting plugins.  Else, tests (grails test-app) fail for these
plugins with ClassNotFoundException: resources
Tests: Metadata: fix output from similarExcludingID

In metadata tests, fix the output from similarExcludingID.  If this
method call from a "then" clause of a Spock test returns false, the
output from the test (the error reported) includes only the call to this
method - result, method name, arguments.

Calling this method with a simple Diff object means only the the first
difference (which typically is the ID attribute ignored by this method)
is printed and the actual XML difference found is hidden away.

Change the code to instead convert the simple Diff to a DetailedDiff
before calling similarExcludingID - that way, all differences captured
in the DetailedDiff are printed and the test errors are much easier to
track down.
Tests: metadata: fix validUntil timezone to UTC

Some tests in the metadata plugin were using hard-coded timestamps but
these timestamps were interpreted relative to the current timezone - and
in other timezones then Australia/Brisbane caused the tests to fail as
the value would not match the UTC-pinned value in expected output.

Explicitly set the timezone to UTC in the tests and adjust test data
accordingly.
Merge pull request #156 from University-of-Auckland/aaf-develop

Fix several issues with tests:
Metadata: Add support for Registration Information

Add functionality to the MetadataGenerationService to emit Registration
and Publishing Information (RPI) as requested in the eduGAIN metadata
profile.

This functionality is controlled by these configuration variables (with
sample values):

config.aaf.fr.metadata.registrationAuthority = "https://www.federation.org/"
config.aaf.fr.metadata.registrationPolicy = "https://www.federation.org/RegistrationPolicy/"
config.aaf.fr.metadata.registrationPolicyLang = "en"

Without these values set (which is the default), this functionality is
not active.

The sample configuration file fr-config.groovy.example has sample
configuration which is commented out by default.

The MetadataGenerationService pulls this information from the config and
stores this cached locally (can be refreshed with a call to
initializeRegInfoConfig() which is otherwise called only the first time
these settings are accessed).

There is a corresponding test in MetadataGenerationServiceSpec with
expected output in testvalidentitiesdescriptorwreginfo.xml
Metadata: MetadataGenerationSv as InitializingBean

Initialize the MetadataGenerationService as an InitializingBean to
address the comments raised in #157:

* removed commented-out constructor.

* implemented org.springframework.beans.factory.InitializingBean to get
  notifications after dependencies are injected.

* rename initializeRegInfoConfig() to afterPropertiesSet() to match the
  InitializingBean interface.

* drop the registrationInitialized variable tracking whether we have
  initialized.

* drop the calls to initializeRegInfoConfig() as the intializion gets
  called automatically after dependencies are injected.
** this also addresses the request to split the call onto multiple lines
   - the call has now been removed instead.

* and adjusted the spock test for the feature to force re-initialization
  by instead explicitly calling metadataGenerationService.afterPropertiesSet()
Messages: fix minor typo in migrateorganization msg

Fix minor typo in templates.fr.entitydescriptor.overview.migrateorganization
message: immediently => immediately
Reporting: fix typo in error message
Reporting: CA Usage: skip disabled certificates

The CA Usage Compliance Report has been producing data that was looking
bogus - turns out it was doing a report over all certificates, including
the ones taht had been "deleted" from the descriptor - which in reality
is only being flagged as disabled.

Fix this by honouring the "disabled" flag and skipping over such
certificates in the causage report.
Base: Fix CryptoService to properly decode DN

This is similar to what was handled in \#154 / commit
8a032c8f8ce90bd749ebe67e8dbb8b04fa15a7a7

Some CAs represent the email address with OID 1.2.840.113549.1.9.1 which
does not get decoded by getSubjectX500Principal().getName() /
getIssuerX500Principal().getName() and is displayed as the OID with the
value being printed out in hex - like:

1.2.840.113549.1.9.1=#16197072656d69756d2d736572766572407468617774652e636f6d,CN=Thawte
Premium Server CA,OU=Certification Services Division,O=Thawte Consulting
cc,L=Cape Town,ST=Western Cape,C=ZA

Fix this by instead getName(String format, Map oidMap) method and
provide an oidMap mapping this OID to "E".

Define the oidMap HashMap as a class field for CryptoService and reuse
that from the issuer() and subject() methods.
APIv1: Fix IdP and SP web links in json responses

Minor bug: the IdP and SP APIv1 controllers were generating incorrect
weblink entries in the JSON data for an IdP or SP:

IdP: "weblink":"https://registry.tuakiri.ac.nz/federationregistry/IDPSSODescriptor/show/3"
SP:  "weblink":"https://registry.tuakiri.ac.nz/federationregistry/SPSSODescriptor/show/5"

The links should actually be pointing to:

   identityProvider controller instead of IDPSSODescriptor
and
   serviceProvider controller instead of SPSSODescriptor

Fixed the 'controller' parameters to g:createLink.
Merge pull request #159 from University-of-Auckland/develop-fix-message-typo

Messages: fix minor typo in migrateorganization msg
Metadata: RegistrationInfo: honour minimal and ext

Honour the minimal and ext (RoleExtensions) flags in the code generation
the Registration Info (RPI) extensions.  I.e., specifically, do not
generate this extension if either minimal is set OR roleExtensions is
not set.

Also pass these parameters to the populateSchema() method so that the
schema definition gets added ONLY if the RPI extension would be actually
generated.
Merge pull request #161 from University-of-Auckland/develop-fix-causage

Minor fixes mostly around certificates
MetadataGenerationService: clean up reginfo code

Clean up the Registration and Publishing Information extension to the
MetadataGenerationService as per comments by @braddleybeddoes in #157 -
specifically:
* use "x && !x.isEmpty()" to test if a string is set to a non-empty value
* correctly reference local variables instead of the fields in config
* drop unnecessary explicit "return" in front of the return value
  in the populateSchema function
MetadataGenerationService: refer to RPI XSD

Add the reference to the Registration and Publishing Info XSD in the
generated metadata (if the RPI namespace is actually used).

The XSD file itself can be downloaded from
http://docs.oasis-open.org/security/saml/Post2.0/saml-metadata-rpi/v1.0/cs01/xsd/saml-metadata-rpi-v1.0.xsd
- and it is the responsibility of interested parties to deploy the XSD
locally to validate the mdrpi extensions.

Adjust the test-case data accordingly.