Changeset 207


Ignore:
Timestamp:
03/03/10 13:08:06 (14 years ago)
Author:
patdui
Message:
  • addd Basic security in webapp
  • Added Delete functionality in registry
  • Made POST and DELETE use authorisation
Location:
ComponentRegistry/trunk/ComponentRegistry
Files:
4 added
15 edited
1 moved

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/pom.xml

    r172 r207  
    7373      <groupId>com.sun.jersey</groupId>
    7474      <artifactId>jersey-server</artifactId>
    75       <version>1.1.2-ea</version>
     75      <version>1.1.5</version>
    7676    </dependency>
    7777    <dependency> <!-- Needed for "automatic" json support -->
    7878      <groupId>com.sun.jersey</groupId>
    7979      <artifactId>jersey-json</artifactId>
    80       <version>1.1.2-ea</version>
     80      <version>1.1.5</version>
    8181      <exclusions>
    82       <!--Jersey has dependencies with different group ids therefore maven cannot resolve the conflict
    83        and gives me both jars (two of stax and two of jaxb-impl). Excluding them manually to overcome the problem -->
    84         <exclusion>             
     82        <!--
     83          Jersey has dependencies with different group ids therefore maven cannot resolve the conflict and gives me both
     84          jars (two of stax and two of jaxb-impl). Excluding them manually to overcome the problem
     85        -->
     86        <exclusion>
    8587          <groupId>stax</groupId>
    86           <artifactId>stax-api</artifactId> 
    87         </exclusion>
    88         <exclusion>             
     88          <artifactId>stax-api</artifactId>
     89        </exclusion>
     90        <exclusion>
    8991          <groupId>com.sun.xml.bind</groupId>
    90           <artifactId>jaxb-impl</artifactId> 
     92          <artifactId>jaxb-impl</artifactId>
    9193        </exclusion>
    9294      </exclusions>
     
    9597      <groupId>com.sun.jersey.contribs</groupId>
    9698      <artifactId>jersey-multipart</artifactId>
    97       <version>1.1.2-ea</version>
     99      <version>1.1.5</version>
    98100    </dependency>
    99101    <dependency> <!-- Client used for RegistryFiller command line tool-->
    100102      <groupId>com.sun.jersey</groupId>
    101103      <artifactId>jersey-client</artifactId>
    102       <version>1.1.2-ea</version>
    103     </dependency>
     104      <version>1.1.5</version>
     105    </dependency>
     106    <dependency>
     107      <groupId>net.sf.saxon</groupId>
     108      <artifactId>saxon-dom</artifactId>
     109      <version>8.7</version>
     110    </dependency>
     111
    104112    <dependency>
    105113      <groupId>com.sun.jersey</groupId>
    106114      <artifactId>jersey-test-framework</artifactId>
    107       <version>1.1.2-ea</version>
     115      <version>1.1.5</version>
    108116      <scope>test</scope>
    109117      <exclusions>
     
    116124          <artifactId>grizzly-servlet-webserver</artifactId>
    117125        </exclusion>
    118         <exclusion>             
     126        <exclusion>
    119127          <groupId>com.sun.xml.bind</groupId>
    120           <artifactId>jaxb-impl</artifactId> 
     128          <artifactId>jaxb-impl</artifactId>
    121129        </exclusion>
    122130      </exclusions>
     
    127135      <version>1.0.1</version>
    128136    </dependency>
     137    <dependency>
     138      <groupId>de.mpg.mpgaai</groupId>
     139      <artifactId>mpgaai-jaas</artifactId>
     140      <version>1.3.2</version>
     141    </dependency>
     142
     143    <dependency>
     144      <groupId>de.mpg.mpgaai</groupId>
     145      <artifactId>mpgaai-shhaa</artifactId>
     146      <version>1.0.2</version>
     147    </dependency>
     148
    129149  </dependencies>
    130150
  • ComponentRegistry/trunk/ComponentRegistry/properties/flexindex.properties

    r34 r207  
    11title=Clarin Component Registry
    2 version_major=9
     2version_major=10
    33version_minor=0
    4 version_revision=124
     4version_revision=0
    55width=100%
    66height=100%
  • ComponentRegistry/trunk/ComponentRegistry/src/main/assembly/registryFiller.xml

    r89 r207  
    1717            <includes>
    1818                <include>log4j.properties</include> <!-- Copy log4j to the bin dir to make it a bit easier to change values in it -->
     19                <include>registry.properties</include> <!-- Needs to be adjusted before running scripts -->
    1920            </includes>
    2021            <outputDirectory>bin</outputDirectory>
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java

    r107 r207  
    11package clarin.cmdi.componentregistry;
    22
     3import java.io.IOException;
     4import java.security.Principal;
    35import java.util.List;
    46
     
    1012
    1113    public static final String REGISTRY_ID = "clarin.eu:cr1:";
    12    
     14
    1315    List<ComponentDescription> getComponentDescriptions();
     16
    1417    List<ProfileDescription> getProfileDescriptions();
     18
    1519    CMDComponentSpec getMDProfile(String id);
     20
    1621    CMDComponentSpec getMDComponent(String id);
     22
    1723    List<MDProfile> searchMDProfiles(String searchPattern);
    1824
     
    2228     */
    2329    int registerMDProfile(ProfileDescription description, CMDComponentSpec spec);
    24     //What about some Credentials or metadata also add in the parameters?
    2530
    2631    int registerMDComponent(ComponentDescription description, CMDComponentSpec spec);
    2732
    2833    String getMDProfileAsXml(String profileId);
     34
    2935    String getMDProfileAsXsd(String profileId);
    3036
    3137    String getMDComponentAsXml(String componentId);
     38
    3239    String getMDComponentAsXsd(String componentId);
    3340
    34     //Remove from registry?
     41    /**
     42     *
     43     * @param profileId
     44     * @param principal
     45     * @throws IOException
     46     * @throws UserUnauthorizedException thrown when principal does not match creator of profile
     47     */
     48    void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException;
     49
     50    /**
     51     *
     52     * @param componentId
     53     * @param principal
     54     * @throws IOException
     55     * @throws UserUnauthorizedException thrown when principal does not match creator of component
     56     */
     57    void deleteMDComponent(String componentId, Principal principal) throws IOException, UserUnauthorizedException;
     58
    3559    //getElements?
    3660    //List<ConceptLinks> getConceptLinks(String componentId, String xpath); We only need xpath I think it contains the componentId's
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistryImpl.java

    r136 r207  
    88import java.io.StringWriter;
    99import java.io.Writer;
     10import java.security.Principal;
    1011import java.util.ArrayList;
    1112import java.util.Collection;
     
    2021import org.apache.commons.io.FileUtils;
    2122import org.apache.commons.io.IOUtils;
    22 import org.apache.commons.io.filefilter.TrueFileFilter;
     23import org.apache.commons.io.filefilter.IOFileFilter;
     24import org.apache.commons.io.filefilter.NameFileFilter;
     25import org.apache.commons.io.filefilter.NotFileFilter;
    2326import org.apache.commons.io.filefilter.WildcardFileFilter;
    2427import org.apache.commons.lang.StringUtils;
     
    119122    private Map<String, ProfileDescription> loadProfileDescriptions() {
    120123        Collection files = FileUtils.listFiles(configuration.getProfileDir(), new WildcardFileFilter(DESCRIPTION_FILE_NAME),
    121                 TrueFileFilter.TRUE);
     124                DIRS_WITH_DESCRIPTIONS);
    122125        Map<String, ProfileDescription> result = new HashMap<String, ProfileDescription>();
    123126        for (Iterator iterator = files.iterator(); iterator.hasNext();) {
     
    130133    }
    131134
     135    private final static IOFileFilter DIRS_WITH_DESCRIPTIONS = new NotFileFilter(new NameFileFilter(Configuration.DELETED_DIR_NAME));
     136
    132137    private Map<String, ComponentDescription> loadComponentDescriptions() {
    133         Collection files = FileUtils.listFiles(getComponentDir(), new WildcardFileFilter(DESCRIPTION_FILE_NAME), TrueFileFilter.TRUE);
     138        Collection files = FileUtils.listFiles(getComponentDir(), new WildcardFileFilter(DESCRIPTION_FILE_NAME), DIRS_WITH_DESCRIPTIONS);
    134139        Map<String, ComponentDescription> result = new HashMap<String, ComponentDescription>();
    135140        for (Iterator iterator = files.iterator(); iterator.hasNext();) {
     
    310315    }
    311316
     317    public void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException {
     318        ProfileDescription desc = profileDescriptions.get(profileId);
     319        if (desc != null) {
     320            checkAuthorisation(desc, principal);
     321            File profileFile = getProfileFile(profileId);
     322            if (profileFile.exists()) {
     323                FileUtils.moveDirectoryToDirectory(profileFile.getParentFile(), configuration.getProfileDeletionDir(), true);
     324                profileDescriptions.remove(profileId);
     325                profilesCache.remove(profileId);
     326            } // else no profile so nothing to delete
     327        }
     328    }
     329
     330    private void checkAuthorisation(AbstractDescription desc, Principal principal) throws UserUnauthorizedException {
     331        if (!principal.getName().equals(desc.getCreatorName())) {
     332            throw new UserUnauthorizedException("Unauthorized operation user: " + principal.getName()
     333                    + " was not the creator of profile/component (description=" + desc + ").");
     334        }
     335    }
     336
     337    public void deleteMDComponent(String componentId, Principal principal) throws IOException, UserUnauthorizedException {
     338        ComponentDescription desc = componentDescriptions.get(componentId);
     339        if (desc != null) {
     340            checkAuthorisation(desc, principal);
     341            File componentFile = getComponentFile(componentId);
     342            if (componentFile.exists()) {
     343                FileUtils.moveDirectoryToDirectory(componentFile.getParentFile(), configuration.getComponentDeletionDir(), true);
     344                componentDescriptions.remove(componentId);
     345                componentsCache.remove(componentId);
     346            } // else no component so nothing to delete
     347        }
     348    }
     349
    312350}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/Configuration.java

    r55 r207  
    88public class Configuration {
    99
     10    public static final String DELETED_DIR_NAME = "deleted";
     11
    1012    private final static Logger LOG = LoggerFactory.getLogger(Configuration.class);
    1113
     
    1315    private File componentDir;
    1416    private File profileDir;
     17    private File profileDeletionDir;
     18    private File componentDeletionDir;
    1519
    1620    public void init() {
     
    1923        componentDir = new File(registryRoot, "components");
    2024        isValid &= validateAndCreate(componentDir);
     25        componentDeletionDir = new File(componentDir, DELETED_DIR_NAME);
     26        isValid &= validateAndCreate(componentDeletionDir);
    2127        profileDir = new File(registryRoot, "profiles");
    2228        isValid &= validateAndCreate(profileDir);
     29        profileDeletionDir = new File(profileDir, DELETED_DIR_NAME);
     30        isValid &= validateAndCreate(profileDeletionDir);
    2331        if (isValid) {
    2432            LOG.info("Initialized Component Registry succesfully. Registry is located in: "+registryRoot);
     
    5159        return profileDir;
    5260    }
     61   
     62    public File getProfileDeletionDir() {
     63        return profileDeletionDir;
     64    }
     65
     66    public File getComponentDeletionDir() {
     67        return componentDeletionDir;
     68    }
    5369
    5470}
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/AbstractDescription.java

    r127 r207  
    2121    private String registrationDate;
    2222    private String creatorName;
    23     @XmlElement(namespace="http://www.w3.org/1999/xlink")
     23    @XmlElement(namespace = "http://www.w3.org/1999/xlink")
    2424    private String href;
    2525
     
    7474    @Override
    7575    public String toString() {
    76         return "Name=" + getName() + ", id=" + getId();
     76        return "Name=" + getName() + ", id=" + getId() + ", creatorName=" + getCreatorName();
    7777    }
    7878
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r127 r207  
    11package clarin.cmdi.componentregistry.rest;
    22
     3import java.io.IOException;
    34import java.io.InputStream;
    45import java.net.URI;
     6import java.security.Principal;
     7import java.util.Arrays;
    58import java.util.Date;
    69import java.util.List;
    710
    811import javax.ws.rs.Consumes;
     12import javax.ws.rs.DELETE;
    913import javax.ws.rs.GET;
    1014import javax.ws.rs.POST;
     
    1620import javax.ws.rs.core.MediaType;
    1721import javax.ws.rs.core.Response;
     22import javax.ws.rs.core.SecurityContext;
    1823import javax.ws.rs.core.UriInfo;
     24import javax.ws.rs.core.Response.Status;
    1925
    2026import org.slf4j.Logger;
     
    2329import clarin.cmdi.componentregistry.ComponentRegistry;
    2430import clarin.cmdi.componentregistry.ComponentRegistryImpl;
     31import clarin.cmdi.componentregistry.UserUnauthorizedException;
    2532import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    2633import clarin.cmdi.componentregistry.model.AbstractDescription;
     
    3643    @Context
    3744    UriInfo uriInfo;
     45    @Context
     46    SecurityContext security;
    3847
    3948    private final static Logger LOG = LoggerFactory.getLogger(ComponentRegistryRestService.class);
     
    4150    public static final String DATA_FORM_FIELD = "data";
    4251    public static final String NAME_FORM_FIELD = "name";
    43     public static final String CREATOR_NAME_FORM_FIELD = "creatorName";
    4452    public static final String DESCRIPTION_FORM_FIELD = "description";
    4553    public static final String GROUP_FORM_FIELD = "group";
     
    7583        LOG.info("Component with id: " + componentId + " is requested.");
    7684        return registry.getMDComponent(componentId);
     85    }
     86
     87    @DELETE
     88    @Path("/components/{componentId}")
     89    public Response deleteRegisteredComponent(@PathParam("componentId") String componentId) {
     90        Principal principal = security.getUserPrincipal();
     91        if (principal == null) {
     92            throw new IllegalArgumentException("no user principal found.");
     93        }
     94        LOG.info("Component with id: " + componentId + " set for deletion.");
     95        try {
     96            registry.deleteMDComponent(componentId, principal);
     97        } catch (IOException e) {
     98            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     99            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     100        } catch (UserUnauthorizedException e) {
     101            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     102            return Response.serverError().status(Status.UNAUTHORIZED).build();
     103        }
     104        LOG.info("Component with id: " + componentId + " deleted.");
     105        return Response.ok().build();
    77106    }
    78107
     
    102131    }
    103132
     133    @DELETE
     134    @Path("/profiles/{profileId}")
     135    public Response deleteRegisteredProfile(@PathParam("profileId") String profileId) {
     136        Principal principal = security.getUserPrincipal();
     137        if (principal == null) {
     138            throw new IllegalArgumentException("no user principal found.");
     139        }
     140        LOG.info("Profile with id: " + profileId + " set for deletion.");
     141        try {
     142            registry.deleteMDProfile(profileId, principal);
     143        } catch (IOException e) {
     144            LOG.info("Profile with id: " + profileId + " deletion failed.", e);
     145            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     146        } catch (UserUnauthorizedException e) {
     147            LOG.info("Profile with id: " + profileId + " deletion failed.", e);
     148            return Response.serverError().status(Status.UNAUTHORIZED).build();
     149        }
     150        LOG.info("Profile with id: " + profileId + " deleted.");
     151        return Response.ok().build();
     152    }
     153
    104154    @GET
    105155    @Path("/profiles/{profileId}/{rawType}")
     
    124174    @Consumes("multipart/form-data")
    125175    public RegisterResponse registerProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
    126             @FormDataParam(CREATOR_NAME_FORM_FIELD) String creatorName, @FormDataParam(DESCRIPTION_FORM_FIELD) String description) {
     176            @FormDataParam(DESCRIPTION_FORM_FIELD) String description) {
     177        Principal principal = security.getUserPrincipal();
     178        if (principal == null) {
     179            throw new IllegalArgumentException("no user principal found.");
     180        }
    127181        ProfileDescription desc = createNewProfileDescription();
    128         desc.setCreatorName(creatorName);
     182        desc.setCreatorName(principal.getName());
    129183        desc.setName(name);
    130184        desc.setDescription(description);
    131185        desc.setRegistrationDate(AbstractDescription.DATE_FORMAT.format(new Date()));
    132186        LOG.info("Trying to register Profile: " + desc);
    133         return register(input, desc);
     187        return register(input, desc, principal);
    134188    }
    135189
     
    139193    @Consumes("multipart/form-data")
    140194    public RegisterResponse registerComponent(@FormDataParam(DATA_FORM_FIELD) InputStream input,
    141             @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(CREATOR_NAME_FORM_FIELD) String creatorName,
    142             @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group) {
     195            @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
     196            @FormDataParam(GROUP_FORM_FIELD) String group) {
     197        Principal principal = security.getUserPrincipal();
     198        if (principal == null) {
     199            throw new IllegalArgumentException("no user principal found.");
     200        }
    143201        ComponentDescription desc = createNewComponentDescription();
    144         desc.setCreatorName(creatorName);
     202        desc.setCreatorName(principal.getName());
    145203        desc.setName(name);
    146204        desc.setDescription(description);
     
    148206        desc.setRegistrationDate(AbstractDescription.DATE_FORMAT.format(new Date()));
    149207        LOG.info("Trying to register Component: " + desc);
    150         return register(input, desc);
    151     }
    152 
    153     private RegisterResponse register(InputStream input, AbstractDescription desc) {
    154         DescriptionValidator descriptionValidator = new DescriptionValidator(desc);
    155         MDValidator validator = new MDValidator(input, desc, registry);
    156         RegisterResponse response = new RegisterResponse();
    157         validate(response, descriptionValidator, validator);
    158         if (response.getErrors().isEmpty()) {
    159             CMDComponentSpec spec = validator.getCMDComponentSpec();
    160             int returnCode = spec.isIsProfile() ? registry.registerMDProfile((ProfileDescription) desc, spec) : registry
    161                     .registerMDComponent((ComponentDescription) desc, spec);
    162             if (returnCode == 0) {
    163                 response.setRegistered(true);
    164                 response.setDescription(desc);
     208        return register(input, desc, principal);
     209    }
     210
     211    private RegisterResponse register(InputStream input, AbstractDescription desc, Principal principal) {
     212        try {
     213            DescriptionValidator descriptionValidator = new DescriptionValidator(desc);
     214            MDValidator validator = new MDValidator(input, desc, registry);
     215            RegisterResponse response = new RegisterResponse();
     216            validate(response, descriptionValidator, validator);
     217            if (response.getErrors().isEmpty()) {
     218                CMDComponentSpec spec = validator.getCMDComponentSpec();
     219                int returnCode = spec.isIsProfile() ? registry.registerMDProfile((ProfileDescription) desc, spec) : registry
     220                        .registerMDComponent((ComponentDescription) desc, spec);
     221                if (returnCode == 0) {
     222                    response.setRegistered(true);
     223                    response.setDescription(desc);
     224                } else {
     225                    response.setRegistered(false);
     226                    response.addError("Unable to register at this moment. Internal server error.");
     227                }
    165228            } else {
     229                LOG.info("Registration failed with validation errors:" + Arrays.toString(response.getErrors().toArray()));
    166230                response.setRegistered(false);
    167                 response.addError("Unable to register at this moment. Internal server error.");
    168231            }
    169         } else {
    170             response.setRegistered(false);
    171         }
    172         response.setIsProfile(desc.isProfile());
    173         return response;
     232            response.setIsProfile(desc.isProfile());
     233            return response;
     234        } finally {
     235            try {
     236                input.close();//either we read the input or there was an exception, we need to close it.
     237            } catch (IOException e) {
     238                LOG.error("Error when closing inputstream: ", e);
     239            }
     240        }
    174241    }
    175242
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/MDValidator.java

    r127 r207  
    5858    }
    5959
    60 
    6160    private void validateComponents(List<CMDComponentType> cmdComponents) {
    6261        for (CMDComponentType cmdComponentType : cmdComponents) {
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryFiller.java

    r157 r207  
    44import java.io.ByteArrayOutputStream;
    55import java.io.File;
     6import java.io.FileInputStream;
    67import java.io.IOException;
    78import java.net.HttpURLConnection;
     
    1314import java.util.List;
    1415import java.util.Map;
     16import java.util.Properties;
    1517import java.util.Set;
    1618
     
    5557    private RegistryToolHelper helper;
    5658
    57     public RegistryFiller(String url) {
     59    // Properties:
     60    //userName=tomcat
     61    //password=tomcat
     62    //registryFillerUrl=http://localhost:8080/ComponentRegistry/rest/registry
     63    //registryMigrationUrl=http://lux16.mpi.nl:8080/ds/ComponentRegistry/rest/registry
     64    Properties properties = new Properties();
     65    static final String FILLER_URL_PROP = "registryFillerUrl";
     66    static final String MIGRATION_URL_PROP = "registryMigrationUrl";
     67    private static final String PASSWORD_PROP = "password";
     68    private static final String USER_NAME_PROP = "userName";
     69
     70    public RegistryFiller(String urlPropName) throws IOException {
     71        properties.load(new FileInputStream("/registry.properties"));
     72        String url = properties.getProperty(urlPropName);
    5873        URI uri = UriBuilder.fromUri(url).build();
    5974        Client client = Client.create();
     
    6176        unresolvedComponents = new HashSet<RegObject>();
    6277        resolvedComponents = new HashMap<RegObject, CMDComponentSpec>();
    63         helper = new RegistryToolHelper(service);
     78        helper = new RegistryToolHelper(service, properties.getProperty(USER_NAME_PROP), properties.getProperty(PASSWORD_PROP));
    6479    }
    6580
    6681    /**
    67      * RegistryFiller "P.Duin" "Test files" imdi -c /Users/patdui/Workspace/Clarin/metadata/toolkit/components/imdi/component*.xml
    68      * @param args
    69      *
    70      *            Uses a heuristic to resolve components which are linked together through fileName. It will try to find the component with
    71      *            a name equal to the filename (without extension) and set the registered id correct.
     82     * Uses a heuristic to resolve components which are linked together through fileName. It will try to find the component with a name
     83     * equal to the filename (without extension) and set the registered id correct.
     84     * @param args RegistryFiller "P.Duin" "Test files" imdi -c
     85     *            /Users/patdui/Workspace/Clarin/metadata/toolkit/components/imdi/component*.xml
     86     * @throws IOException when properties cannot be loaded
    7287     *
    7388     */
    74     public static void main(String[] args) {
     89    public static void main(String[] args) throws IOException {
    7590        LOG.info("RegistryFiller started with arguments: " + Arrays.toString(args));
    7691        if (args.length == 0 || args.length < 5) {
    7792            printUsage();
    7893        }
    79         String url = "http://localhost:8080/ComponentRegistry/rest/registry";
    80         RegistryFiller filler = new RegistryFiller(url);
     94        RegistryFiller filler = new RegistryFiller(FILLER_URL_PROP);
    8195        String creatorName = args[0];
    8296        String description = args[1];
     
    108122    private static void printUsage() {
    109123        System.out.println("usage: <creatorName> <description> <groupType> <-c|-p (components or profiles)> <xml file(s)>");
     124        System.out.println("It also needs a filled in registry.properties");
    110125        System.exit(0);
    111126    }
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryMigration.java

    r157 r207  
    22
    33import java.io.File;
     4import java.io.IOException;
    45import java.util.Arrays;
    56import java.util.List;
     
    2122    private final static Logger LOG = LoggerFactory.getLogger(RegistryMigration.class);
    2223    private Configuration config;
    23     private final String targetUrl;
    2424    private ComponentRegistryImpl registry;
    2525
    2626    /*
    27      * http://lux16.mpi.nl:8080/ds/ComponentRegistry/rest/registry
    28      *
    2927     * /tmp/ComponentRegistry
    3028     */
    31     public RegistryMigration(String sourceDir, String targetUrl) {
    32         this.targetUrl = targetUrl;
     29    public RegistryMigration(String sourceDir) {
    3330        config = new Configuration();
    3431        config.setRegistryRoot(new File(sourceDir));
     
    3835    }
    3936
    40     private void migrate() {
    41         RegistryFiller filler = new RegistryFiller(targetUrl);
     37    private void migrate() throws IOException {
     38        RegistryFiller filler = new RegistryFiller(RegistryFiller.MIGRATION_URL_PROP);
    4239        addComponents(filler);
    4340        addProfiles(filler);
     
    6865    /**
    6966     * @param args
     67     * @throws IOException
    7068     */
    71     public static void main(String[] args) {
     69    public static void main(String[] args) throws IOException {
    7270        LOG.info("RegistryMigration started with arguments: " + Arrays.toString(args));
    73         if (args.length != 2) {
     71        if (args.length != 1) {
    7472            printUsage();
    7573        }
    76         RegistryMigration migration = new RegistryMigration(args[0], args[1]);
     74        RegistryMigration migration = new RegistryMigration(args[0]);
    7775        migration.migrate();
    7876    }
    7977
    8078    private static void printUsage() {
    81         System.out.println("usage: <source registry directory> <target registry URL>");
     79        System.out.println("usage: <source registry directory>");
     80        System.out.println("It also needs a filled in registry.properties");
    8281        System.exit(0);
    8382    }
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryToolHelper.java

    r131 r207  
    44import java.io.InputStream;
    55
     6import javax.ws.rs.core.HttpHeaders;
    67import javax.ws.rs.core.MediaType;
    78
     
    1314
    1415import com.sun.jersey.api.client.WebResource;
     16import com.sun.jersey.api.client.WebResource.Builder;
     17import com.sun.jersey.core.util.Base64;
    1518import com.sun.jersey.multipart.FormDataMultiPart;
    1619
     
    2225    private int failed = 0;
    2326
    24     public RegistryToolHelper(WebResource service) {
     27    private final String userName;
     28
     29    private final String password;
     30
     31    public RegistryToolHelper(WebResource service, String userName, String password) {
    2532        this.service = service;
     33        this.userName = userName;
     34        this.password = password;
    2635    }
    2736
     
    2938        FormDataMultiPart form = createForm(input, creatorName, description, name);
    3039        form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, group);
    31         RegisterResponse response = service.path("/components").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     40        RegisterResponse response = getAuthenticatedResource("/components").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    3241        handleResult(response);
    3342    }
     
    3544    public void registerProfile(InputStream input, String creatorName, String description, String name) throws IOException {
    3645        FormDataMultiPart form = createForm(input, creatorName, description, name);
    37         RegisterResponse response = service.path("/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     46        RegisterResponse response = getAuthenticatedResource("/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    3847        handleResult(response);
    3948    }
     49   
     50    private Builder getAuthenticatedResource(String path) {
     51        return service.path(path).header(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(userName+":"+password)));
     52    }
     53
    4054
    4155    private FormDataMultiPart createForm(InputStream input, String creatorName, String description, String name) throws IOException {
     
    4458        form.field(ComponentRegistryRestService.NAME_FORM_FIELD, name);
    4559        form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, description);
    46         form.field(ComponentRegistryRestService.CREATOR_NAME_FORM_FIELD, creatorName);
    4760        return form;
    4861    }
  • ComponentRegistry/trunk/ComponentRegistry/src/main/webapp/WEB-INF/web.xml

    r60 r207  
    55  <description>Clarin Metadata Component Registry</description>
    66
     7<!--  <context-param>
     8    <param-name>ShhaaConfigLocation</param-name>
     9    <param-value>/WEB-INF/shhaa.xml</param-value>
     10  </context-param> -->
    711  <listener>
    812    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    913  </listener>
     14  <!--
     15    filter> <filter-name>AAIFilter</filter-name> <filter-class>de.mpg.aai.shhaa.AuthFilter</filter-class> </filter>
     16    <filter-mapping> <filter-name>AAIFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener>
     17    <listener-class>de.mpg.aai.shhaa.config.ConfigContextListener</listener-class> </listener
     18  -->
    1019
    1120  <servlet>
    12     <servlet-name>Jersey Web Application</servlet-name>
     21    <servlet-name>ComponentRegistry Web Application</servlet-name>
    1322    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    1423    <init-param>
     
    1928  </servlet>
    2029  <servlet-mapping>
    21     <servlet-name>Jersey Web Application</servlet-name>
     30    <servlet-name>ComponentRegistry Web Application</servlet-name>
    2231    <url-pattern>/rest/*</url-pattern>
    2332  </servlet-mapping>
    2433
    25 
     34  <security-constraint>
     35    <display-name>ComponentRegistry web service</display-name>
     36    <web-resource-collection>
     37      <web-resource-name>ComponentRegistry edit</web-resource-name>
     38      <description></description>
     39      <url-pattern>/rest/*</url-pattern>
     40      <http-method>DELETE</http-method>
     41      <http-method>PUT</http-method>
     42      <http-method>POST</http-method>
     43     <!--   <http-method>GET</http-method>-->
     44    </web-resource-collection>
     45    <auth-constraint>
     46      <role-name>tomcat</role-name>
     47    </auth-constraint>
     48  </security-constraint>
     49  <login-config>
     50    <auth-method>BASIC</auth-method>
     51  </login-config>
     52  <security-role>
     53    <description>
     54      The role that is required to log in to the Manager Application
     55    </description>
     56    <role-name>tomcat</role-name>
     57  </security-role>
    2658</web-app>
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/ComponentRegistryImplTest.java

    r136 r207  
    11package clarin.cmdi.componentregistry;
    22
    3 import static org.junit.Assert.assertEquals;
     3import static junit.framework.Assert.assertEquals;
    44import static org.junit.Assert.assertFalse;
    55import static org.junit.Assert.assertNotNull;
    66import static org.junit.Assert.assertNull;
    77import static org.junit.Assert.assertTrue;
     8import static org.junit.Assert.fail;
    89
    910import java.io.File;
     
    2021import clarin.cmdi.componentregistry.model.ComponentDescription;
    2122import clarin.cmdi.componentregistry.model.ProfileDescription;
     23import clarin.cmdi.componentregistry.rest.DummyPrincipal;
    2224import clarin.cmdi.componentregistry.rest.TestHelper;
    2325
     
    2527
    2628    private File tmpRegistryDir;
     29    private final static DummyPrincipal PRINCIPAL = DummyPrincipal.DUMMY_PRINCIPAL;
    2730
    2831    @Test
     
    262265    }
    263266
     267    @Test
     268    public void testDeleteProfile() throws Exception {
     269        ComponentRegistry register = getTestRegistry(getRegistryDir());
     270        ProfileDescription description = ProfileDescription.createNewDescription();
     271        description.setName("Aap");
     272        description.setCreatorName(PRINCIPAL.getName());
     273        description.setDescription("MyDescription");
     274        CMDComponentSpec testProfile = TestHelper.getTestProfile();
     275
     276        register.registerMDProfile(description, testProfile);
     277
     278        assertEquals(1, register.getProfileDescriptions().size());
     279        assertNotNull(register.getMDProfile(description.getId()));
     280
     281        try {
     282            register.deleteMDProfile(description.getId(), new DummyPrincipal("Fake User"));
     283            fail("Should have thrown exception");
     284        }catch(UserUnauthorizedException e) {}
     285        register.deleteMDComponent(description.getId(), new DummyPrincipal("Fake User"));
     286
     287        assertEquals(1, register.getProfileDescriptions().size());
     288        assertNotNull(register.getMDProfile(description.getId()));
     289
     290        register.deleteMDProfile(description.getId(), PRINCIPAL);
     291
     292        assertEquals(0, register.getProfileDescriptions().size());
     293        assertNull(register.getMDProfile(description.getId()));
     294    }
     295
     296    @Test
     297    public void testDeleteComponent() throws Exception {
     298        ComponentRegistry register = getTestRegistry(getRegistryDir());
     299        ComponentDescription description = ComponentDescription.createNewDescription();
     300        description.setName("Aap");
     301        description.setCreatorName(PRINCIPAL.getName());
     302        description.setDescription("MyDescription");
     303        CMDComponentSpec testProfile = TestHelper.getTestProfile();
     304
     305        register.registerMDComponent(description, testProfile);
     306        try {
     307            register.deleteMDComponent(description.getId(), new DummyPrincipal("Fake User"));
     308            fail("Should have thrown exception");
     309        }catch(UserUnauthorizedException e) {}
     310
     311        assertEquals(1, register.getComponentDescriptions().size());
     312        assertNotNull(register.getMDComponent(description.getId()));
     313
     314        register.deleteMDComponent(description.getId(), PRINCIPAL);
     315
     316        assertEquals(0, register.getComponentDescriptions().size());
     317        assertNull(register.getMDProfile(description.getId()));
     318
     319    }
     320
    264321    private File getRegistryDir() {
    265322        if (tmpRegistryDir == null)
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java

    r130 r207  
    1212import java.util.List;
    1313
     14import javax.ws.rs.core.HttpHeaders;
    1415import javax.ws.rs.core.MediaType;
    1516import javax.xml.bind.JAXBException;
    1617
    17 import org.junit.AfterClass;
    18 import org.junit.BeforeClass;
     18import org.junit.After;
     19import org.junit.Before;
    1920import org.junit.Test;
    2021
     
    2627import clarin.cmdi.componentregistry.model.RegisterResponse;
    2728
     29import com.sun.jersey.api.client.ClientResponse;
    2830import com.sun.jersey.api.client.GenericType;
    2931import com.sun.jersey.api.client.UniformInterfaceException;
     32import com.sun.jersey.api.client.WebResource;
     33import com.sun.jersey.api.client.WebResource.Builder;
     34import com.sun.jersey.api.core.ResourceConfig;
     35import com.sun.jersey.core.util.Base64;
    3036import com.sun.jersey.multipart.FormDataMultiPart;
    3137import com.sun.jersey.test.framework.AppDescriptor;
     
    3339import com.sun.jersey.test.framework.LowLevelAppDescriptor;
    3440import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
    35 import com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory;
     41import com.sun.jersey.test.framework.spi.container.http.HTTPContainerFactory;
    3642
    3743public class ComponentRegistryRestServiceTest extends JerseyTest {
     
    4955    @Override
    5056    protected TestContainerFactory getTestContainerFactory() {
    51         return new InMemoryTestContainerFactory();
     57        return new HTTPContainerFactory();
    5258    }
    5359
    5460    @Override
    5561    protected AppDescriptor configure() {
    56         String packageName = ComponentRegistryRestService.class.getPackage().getName();
    57         return new LowLevelAppDescriptor.Builder(packageName).build();
     62        LowLevelAppDescriptor ad = new LowLevelAppDescriptor.Builder(ComponentRegistryRestService.class.getPackage().getName()).build();
     63        ResourceConfig resourceConfig = ad.getResourceConfig();
     64        resourceConfig.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, DummySecurityFilter.class.getName());
     65        return ad;
     66    }
     67
     68    private WebResource getResource() {
     69        return resource();
     70    }
     71
     72    private Builder getAuthenticatedResource(String path) {
     73        return getResource().path(path).header(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(DummyPrincipal.DUMMY_PRINCIPAL.getName()+":dummy")));
    5874    }
    5975
    6076    @Test
    6177    public void testGetRegisteredProfiles() throws Exception {
    62         List<ProfileDescription> response = resource().path("/registry/profiles").accept(MediaType.APPLICATION_XML).get(
     78        List<ProfileDescription> response = getResource().path("/registry/profiles").accept(MediaType.APPLICATION_XML).get(
    6379                PROFILE_LIST_GENERICTYPE);
    6480        assertEquals(2, response.size());
    65         response = resource().path("/registry/profiles").accept(MediaType.APPLICATION_JSON).get(PROFILE_LIST_GENERICTYPE);
     81        response = getResource().path("/registry/profiles").accept(MediaType.APPLICATION_JSON).get(PROFILE_LIST_GENERICTYPE);
    6682        assertEquals(2, response.size());
    6783    }
     
    6985    @Test
    7086    public void testGetRegisteredComponents() {
    71         List<ComponentDescription> response = resource().path("/registry/components").accept(MediaType.APPLICATION_XML).get(
     87        List<ComponentDescription> response = getResource().path("/registry/components").accept(MediaType.APPLICATION_XML).get(
    7288                COMPONENT_LIST_GENERICTYPE);
    7389        assertEquals(2, response.size());
    74         response = resource().path("/registry/components").accept(MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE);
     90        response = getResource().path("/registry/components").accept(MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE);
    7591        assertEquals(2, response.size());
    7692    }
     
    7894    @Test
    7995    public void testGetRegisteredComponent() {
    80         CMDComponentSpec component = resource().path("/registry/components/clarin.eu:cr1:component1").accept(MediaType.APPLICATION_JSON)
     96        CMDComponentSpec component = getResource().path("/registry/components/clarin.eu:cr1:component1").accept(MediaType.APPLICATION_JSON)
    8197                .get(CMDComponentSpec.class);
    8298        assertNotNull(component);
    8399        assertEquals("Access", component.getCMDComponent().get(0).getName());
    84         component = resource().path("/registry/components/clarin.eu:cr1:component2").accept(MediaType.APPLICATION_XML).get(
     100        component = getResource().path("/registry/components/clarin.eu:cr1:component2").accept(MediaType.APPLICATION_XML).get(
    85101                CMDComponentSpec.class);
    86102        assertNotNull(component);
     
    93109
    94110    @Test
     111    public void testDeleteRegisteredComponent() throws Exception {
     112        List<ComponentDescription> components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     113        assertEquals(2, components.size());
     114        CMDComponentSpec profile = getResource().path("/registry/components/clarin.eu:cr1:component1").get(CMDComponentSpec.class);
     115        assertNotNull(profile);
     116        ClientResponse response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").delete(ClientResponse.class);
     117        assertEquals(200, response.getStatus());
     118
     119        components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     120        assertEquals(1, components.size());
     121
     122        response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component2").delete(ClientResponse.class);
     123        assertEquals(200, response.getStatus());
     124
     125        components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     126        assertEquals(0, components.size());
     127
     128        response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").delete(ClientResponse.class);
     129        assertEquals(200, response.getStatus());
     130    }
     131
     132    @Test
    95133    public void testGetRegisteredProfile() throws Exception {
    96         CMDComponentSpec profile = resource().path("/registry/profiles/clarin.eu:cr1:profile1").accept(MediaType.APPLICATION_JSON).get(
     134        CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").accept(MediaType.APPLICATION_JSON).get(
    97135                CMDComponentSpec.class);
    98136        assertNotNull(profile);
    99137        assertEquals("Actor", profile.getCMDComponent().get(0).getName());
    100         profile = resource().path("/registry/profiles/clarin.eu:cr1:profile2").accept(MediaType.APPLICATION_XML)
    101                 .get(CMDComponentSpec.class);
     138        profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile2").accept(MediaType.APPLICATION_XML).get(
     139                CMDComponentSpec.class);
    102140        assertNotNull(profile);
    103141        assertEquals("Actor", profile.getCMDComponent().get(0).getName());
     
    108146
    109147        try {
    110             profile = resource().path("/registry/profiles/clarin.eu:cr1:profileXXXX").accept(MediaType.APPLICATION_XML).get(
     148            profile = getResource().path("/registry/profiles/clarin.eu:cr1:profileXXXX").accept(MediaType.APPLICATION_XML).get(
    111149                    CMDComponentSpec.class);
    112150            fail("Exception should have been thrown resouce does not exist, HttpStatusCode 204");
     
    118156    @Test
    119157    public void testGetRegisteredProfileRawData() throws Exception {
    120         String profile = resource().path("/registry/profiles/clarin.eu:cr1:profile1/xsd").accept(MediaType.TEXT_XML).get(String.class);
     158        String profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/xsd").accept(MediaType.TEXT_XML).get(String.class);
    121159        assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema"));
    122160        assertTrue(profile.endsWith("</xs:schema>"));
    123161
    124         profile = resource().path("/registry/profiles/clarin.eu:cr1:profile1/xml").accept(MediaType.TEXT_XML).get(String.class);
     162        profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/xml").accept(MediaType.TEXT_XML).get(String.class);
    125163        assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec"));
    126164        assertTrue(profile.endsWith("</CMD_ComponentSpec>\n"));
    127165
    128166        try {
    129             resource().path("/registry/components/clarin.eu:cr1:component1/xsl").accept(MediaType.TEXT_XML).get(String.class);
     167            getResource().path("/registry/components/clarin.eu:cr1:component1/xsl").accept(MediaType.TEXT_XML).get(String.class);
    130168            fail("Should have thrown exception, unsopported path parameter");
    131169        } catch (UniformInterfaceException e) {//server error
     
    134172
    135173    @Test
     174    public void testDeleteRegisteredProfile() throws Exception {
     175        List<ProfileDescription> profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
     176        assertEquals(2, profiles.size());
     177        CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").get(CMDComponentSpec.class);
     178        assertNotNull(profile);
     179
     180        ClientResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class);
     181        assertEquals(200, response.getStatus());
     182
     183        profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
     184        assertEquals(1, profiles.size());
     185
     186        response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile2").delete(ClientResponse.class);
     187        assertEquals(200, response.getStatus());
     188
     189        profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
     190        assertEquals(0, profiles.size());
     191
     192        response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class);
     193        assertEquals(200, response.getStatus());
     194    }
     195
     196    @Test
    136197    public void testGetRegisteredComponentRawData() throws Exception {
    137         String component = resource().path("/registry/components/clarin.eu:cr1:component1/xsd").accept(MediaType.TEXT_XML)
    138                 .get(String.class);
     198        String component = getResource().path("/registry/components/clarin.eu:cr1:component1/xsd").accept(MediaType.TEXT_XML).get(
     199                String.class);
    139200        assertTrue(component.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema"));
    140201        assertTrue(component.endsWith("</xs:schema>"));
    141202
    142         component = resource().path("/registry/components/clarin.eu:cr1:component1/xml").accept(MediaType.TEXT_XML).get(String.class);
     203        component = getResource().path("/registry/components/clarin.eu:cr1:component1/xml").accept(MediaType.TEXT_XML).get(String.class);
    143204        assertTrue(component.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec"));
    144205        assertTrue(component.endsWith("</CMD_ComponentSpec>\n"));
    145206
    146207        try {
    147             resource().path("/registry/components/clarin.eu:cr1:component1/jpg").accept(MediaType.TEXT_XML).get(String.class);
     208            getResource().path("/registry/components/clarin.eu:cr1:component1/jpg").accept(MediaType.TEXT_XML).get(String.class);
    148209            fail("Should have thrown exception, unsopported path parameter");
    149210        } catch (UniformInterfaceException e) {
     
    158219        form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1");
    159220        form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Profile");
    160         form.field(ComponentRegistryRestService.CREATOR_NAME_FORM_FIELD, "J. Unit");
    161         RegisterResponse response = resource().path("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    162                 form);
     221        RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     222                RegisterResponse.class, form);
    163223        assertTrue(response.isProfile());
    164224        ProfileDescription profileDesc = (ProfileDescription) response.getDescription();
     
    166226        assertEquals("ProfileTest1", profileDesc.getName());
    167227        assertEquals("My Test Profile", profileDesc.getDescription());
    168         assertEquals("J. Unit", profileDesc.getCreatorName());
     228        assertEquals("J.Unit", profileDesc.getCreatorName());
    169229        assertTrue(profileDesc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_"));
    170230        assertNotNull(profileDesc.getRegistrationDate());
     
    179239        form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ComponentTest1");
    180240        form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Component");
    181         form.field(ComponentRegistryRestService.CREATOR_NAME_FORM_FIELD, "J. Unit");
    182241        form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
    183         RegisterResponse response = resource().path("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post(
     242        RegisterResponse response = getAuthenticatedResource("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post(
    184243                RegisterResponse.class, form);
    185244        assertTrue(response.isRegistered());
     
    189248        assertEquals("ComponentTest1", desc.getName());
    190249        assertEquals("My Test Component", desc.getDescription());
    191         assertEquals("J. Unit", desc.getCreatorName());
     250        assertEquals("J.Unit", desc.getCreatorName());
    192251        assertEquals("TestGroup", desc.getGroupName());
    193252        assertTrue(desc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "c_"));
    194253        assertNotNull(desc.getRegistrationDate());
    195         String url = resource().getUriBuilder().build().toString();
     254        String url = getResource().getUriBuilder().build().toString();
    196255        assertEquals(url + "registry/components/" + desc.getId(), desc.getHref());
    197256    }
     
    205264        form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1");
    206265        form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Profile");
    207         form.field(ComponentRegistryRestService.CREATOR_NAME_FORM_FIELD, "J. Unit");
    208         RegisterResponse postResponse = resource().path("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     266        RegisterResponse postResponse = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
    209267                RegisterResponse.class, form);
    210268        assertTrue(postResponse.isProfile());
     
    233291        form.field("name", "");//Empty name so invalid
    234292        form.field("description", "My Test Profile");
    235         form.field("creatorName", "J. Unit");
    236         RegisterResponse response = resource().path("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    237                 form);
     293        RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     294                RegisterResponse.class, form);
    238295        assertFalse(response.isRegistered());
    239296        assertEquals(2, response.getErrors().size());
     
    249306        form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "t");
    250307        form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test");
    251         form.field(ComponentRegistryRestService.CREATOR_NAME_FORM_FIELD, "J. Unit");
    252         RegisterResponse response = resource().path("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    253                 form);
     308        RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     309                RegisterResponse.class, form);
    254310        assertFalse(response.isRegistered());
    255311        assertTrue(response.isProfile());
     
    258314    }
    259315
    260     @BeforeClass
    261     public static void setUpTestRegistry() throws ParseException, JAXBException {
     316    @Before
     317    public void setUpTestRegistry() throws ParseException, JAXBException {
    262318        registryDir = ComponentRegistryImplTest.createTempRegistryDir();
    263319        testRegistry = ComponentRegistryImplTest.getTestRegistry(registryDir);
     
    268324    }
    269325
    270     @AfterClass
    271     public static void deleteRegistry() {
     326    @After
     327    public void deleteAndRecreateEmptyRegistry() {
    272328        ComponentRegistryImplTest.cleanUpRegistryDir(registryDir);
    273 
    274329    }
    275330
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/TestHelper.java

    r136 r207  
    2828    }
    2929
    30     public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, String content) throws ParseException, JAXBException {
     30    public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, String content) throws ParseException,
     31            JAXBException {
    3132        return addComponent(testRegistry, id, new ByteArrayInputStream(content.getBytes()));
    3233    }
    33    
     34
    3435    private static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, InputStream content) throws ParseException,
    3536            JAXBException {
    3637        ComponentDescription desc = ComponentDescription.createNewDescription();
    37         desc.setCreatorName("J. Unit");
     38        desc.setCreatorName(DummyPrincipal.DUMMY_PRINCIPAL.getName());
    3839        desc.setName("testComponent");
    3940        desc.setRegistrationDate("" + SimpleDateFormat.getDateInstance(DateFormat.SHORT).parse("1/1/2009"));
     
    8182            JAXBException {
    8283        ProfileDescription desc = ProfileDescription.createNewDescription();
    83         desc.setCreatorName("J. Unit");
     84        desc.setCreatorName(DummyPrincipal.DUMMY_PRINCIPAL.getName());
    8485        desc.setName("testProfile");
    8586        desc.setRegistrationDate("" + SimpleDateFormat.getDateInstance(DateFormat.SHORT).parse("1/1/2009"));
Note: See TracChangeset for help on using the changeset viewer.