Changeset 5872 for ComponentRegistry


Ignore:
Timestamp:
12/01/14 16:01:52 (10 years ago)
Author:
Twan Goosen
Message:

Made component and profile 'raw types' (expanded XML and XSD) available without authentication

Location:
ComponentRegistry/trunk/ComponentRegistry/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java

    r5802 r5872  
    4949    ComponentDescription getComponentDescriptionAccessControlled(String id) throws ComponentRegistryException, UserUnauthorizedException, AuthenticationRequiredException, ItemNotFoundException;
    5050
     51    ComponentDescription getComponentDescription(String id) throws ComponentRegistryException, ItemNotFoundException;
    5152    /**
    5253     *
     
    7475    ProfileDescription getProfileDescriptionAccessControlled(String id) throws ComponentRegistryException, UserUnauthorizedException, AuthenticationRequiredException, ItemNotFoundException;
    7576
     77    ProfileDescription getProfileDescription(String id) throws ComponentRegistryException, ItemNotFoundException;
     78   
    7679    CMDComponentSpec getMDProfileAccessControled(String id) throws ComponentRegistryException, UserUnauthorizedException, AuthenticationRequiredException, ItemNotFoundException;
    7780
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r5846 r5872  
    227227    }
    228228
    229     private ProfileDescription getProfileDescription(String id) throws ComponentRegistryException {
    230         try {
    231             return ComponentUtils.toProfile(componentDao.getByCmdId(id));
     229    @Override
     230    public ProfileDescription getProfileDescription(String id) throws ComponentRegistryException, ItemNotFoundException {
     231        try {
     232            final BaseDescription descr = componentDao.getByCmdId(id);
     233            if (descr == null) {
     234                throw new ItemNotFoundException("Profile not found:" + id);
     235            } else {
     236                return ComponentUtils.toProfile(descr);
     237            }
    232238        } catch (DataAccessException ex) {
    233239            throw new ComponentRegistryException("Database access error while trying to get profile description", ex);
     
    271277    }
    272278
    273     private ComponentDescription getComponentDescription(String id) throws ComponentRegistryException {
    274         try {
    275             return ComponentUtils.toComponent(componentDao.getByCmdId(id));
     279    @Override
     280    public ComponentDescription getComponentDescription(String id) throws ComponentRegistryException, ItemNotFoundException {
     281        try {
     282            final BaseDescription descr = componentDao.getByCmdId(id);
     283            if (descr == null) {
     284                throw new ItemNotFoundException("Component not found: " + id);
     285            } else {
     286                return ComponentUtils.toComponent(descr);
     287            }
    276288        } catch (DataAccessException ex) {
    277289            throw new ComponentRegistryException("Database access error while trying to get component description", ex);
     
    934946            if (spec != null && hasComponentId(componentId, spec.getCMDComponent())) {
    935947                LOG.debug("Component {} used in component {}", componentId, spec.getHeader().getID());
    936                 result.add(getComponentDescription(id));
     948                try {
     949                    result.add(getComponentDescription(id));
     950                } catch (ItemNotFoundException ex) {
     951                    throw new ComponentRegistryException("Component not found", ex);
     952                }
    937953            }
    938954        }
     
    951967            if (profile != null && hasComponentId(componentId, profile.getCMDComponent())) {
    952968                LOG.debug("Component {} used in profile {}", componentId, profile.getHeader().getID());
    953                 result.add(getProfileDescription(id));
     969                try {
     970                    result.add(getProfileDescription(id));
     971                } catch (ItemNotFoundException ex) {
     972                    throw new ComponentRegistryException("Profile not found", ex);
     973                }
    954974            }
    955975        }
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r5859 r5872  
    356356        try {
    357357            final ComponentRegistry registry = this.getBaseRegistry();
    358             try {
    359                 ComponentDescription desc = registry.getComponentDescriptionAccessControlled(componentId);
    360                 StreamingOutput result = null;
    361                 String fileName = desc.getName() + "." + rawType;
    362                 if ("xml".equalsIgnoreCase(rawType)) {
    363                     result = new StreamingOutput() {
    364                         @Override
    365                         public void write(OutputStream output) throws IOException,
    366                                 WebApplicationException {
     358            ComponentDescription desc = registry.getComponentDescription(componentId);
     359            StreamingOutput result = null;
     360            String fileName = desc.getName() + "." + rawType;
     361            if ("xml".equalsIgnoreCase(rawType)) {
     362                result = new StreamingOutput() {
     363                    @Override
     364                    public void write(OutputStream output) throws IOException,
     365                            WebApplicationException {
     366                        try {
    367367                            try {
    368368                                try {
    369                                     try {
    370                                         registry.getMDComponentAsXml(componentId, output);
    371                                     } catch (ItemNotFoundException e1) {
    372                                         LOG.warn("Could not retrieve component {}",
    373                                                 componentId);
    374                                         LOG.debug("Details", e1);
    375                                         throw new WebApplicationException(e1, Response
    376                                                 .serverError()
    377                                                 .status(Status.INTERNAL_SERVER_ERROR)
    378                                                 .build());
    379                                     }
    380                                 } catch (ComponentRegistryException e) {
     369                                    registry.getMDComponentAsXml(componentId, output);
     370                                } catch (ItemNotFoundException e1) {
    381371                                    LOG.warn("Could not retrieve component {}",
    382372                                            componentId);
    383                                     LOG.debug("Details", e);
    384                                     throw new WebApplicationException(e, Response
     373                                    LOG.debug("Details", e1);
     374                                    throw new WebApplicationException(e1, Response
    385375                                            .serverError()
    386376                                            .status(Status.INTERNAL_SERVER_ERROR)
    387377                                            .build());
    388378                                }
    389 
    390                             } catch (UserUnauthorizedException e2) {
    391                                 LOG.error(e2.toString());
     379                            } catch (ComponentRegistryException e) {
     380                                LOG.warn("Could not retrieve component {}",
     381                                        componentId);
     382                                LOG.debug("Details", e);
     383                                throw new WebApplicationException(e, Response
     384                                        .serverError()
     385                                        .status(Status.INTERNAL_SERVER_ERROR)
     386                                        .build());
    392387                            }
     388
     389                        } catch (UserUnauthorizedException e2) {
     390                            LOG.error(e2.toString());
    393391                        }
    394                     };
    395                     return createDownloadResponse(result, fileName);
    396                 } else if ("xsd".equalsIgnoreCase(rawType)) {
    397                     result = new StreamingOutput() {
    398                         @Override
    399                         public void write(OutputStream output) throws IOException,
    400                                 WebApplicationException {
     392                    }
     393                };
     394                return createDownloadResponse(result, fileName);
     395            } else if ("xsd".equalsIgnoreCase(rawType)) {
     396                result = new StreamingOutput() {
     397                    @Override
     398                    public void write(OutputStream output) throws IOException,
     399                            WebApplicationException {
     400                        try {
    401401                            try {
    402402                                try {
    403                                     try {
    404                                         registry.getMDComponentAsXsd(componentId, output);
    405                                     } catch (ItemNotFoundException e1) {
    406                                         LOG.warn("Could not retrieve component {}",
    407                                                 componentId);
    408                                         LOG.debug("Details", e1);
    409                                         throw new WebApplicationException(e1, Response
    410                                                 .serverError()
    411                                                 .status(Status.INTERNAL_SERVER_ERROR)
    412                                                 .build());
    413                                     }
    414                                 } catch (ComponentRegistryException e) {
     403                                    registry.getMDComponentAsXsd(componentId, output);
     404                                } catch (ItemNotFoundException e1) {
    415405                                    LOG.warn("Could not retrieve component {}",
    416406                                            componentId);
    417                                     LOG.debug("Details", e);
    418                                     throw new WebApplicationException(e, Response
     407                                    LOG.debug("Details", e1);
     408                                    throw new WebApplicationException(e1, Response
    419409                                            .serverError()
    420410                                            .status(Status.INTERNAL_SERVER_ERROR)
    421411                                            .build());
    422412                                }
    423                             } catch (UserUnauthorizedException e2) {
    424                                 LOG.error(e2.toString());
     413                            } catch (ComponentRegistryException e) {
     414                                LOG.warn("Could not retrieve component {}",
     415                                        componentId);
     416                                LOG.debug("Details", e);
     417                                throw new WebApplicationException(e, Response
     418                                        .serverError()
     419                                        .status(Status.INTERNAL_SERVER_ERROR)
     420                                        .build());
    425421                            }
    426 
     422                        } catch (UserUnauthorizedException e2) {
     423                            LOG.error(e2.toString());
    427424                        }
    428                     };
    429                     return createDownloadResponse(result, fileName);
    430                 } else {
    431                     return Response.status(Status.NOT_FOUND).entity("Usupported raw type " + rawType).build();
    432                 }
    433 
    434             } catch (UserUnauthorizedException e2) {
    435                 return Response.status(Status.FORBIDDEN).build();
     425
     426                    }
     427                };
     428                return createDownloadResponse(result, fileName);
     429            } else {
     430                return Response.status(Status.NOT_FOUND).entity("Usupported raw type " + rawType).build();
    436431            }
    437432        } catch (ItemNotFoundException e3) {
     
    11861181            final ComponentRegistry registry = this.getBaseRegistry();
    11871182
    1188             ProfileDescription desc = registry.getProfileDescriptionAccessControlled(profileId);
     1183            final ProfileDescription desc = registry.getProfileDescription(profileId);
    11891184            if (desc == null) {
    11901185                return Response.status(Status.NOT_FOUND).build();
     
    12331228            }
    12341229            return createDownloadResponse(result, fileName);
    1235         } catch (UserUnauthorizedException ex) {
    1236             return Response.status(Status.FORBIDDEN).build();
    12371230        } catch (ItemNotFoundException e) {
    12381231            return Response.serverError().status(Status.NOT_FOUND)
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RestGroupServiceTest.java

    r5832 r5872  
    4444 *
    4545 * Test groups:
    46  * 
     46 *
    4747 * A
    48  *      Owner: Dummy
    49  *      Members: -
    50  *      Items: profile-1, component-1, component-2
    51  *
     48 * Owner: Dummy Members: - Items: profile-1, component-1, component-2
     49 *
    5250 * B
    53  *      Owner: anotherPrincipal
    54  *      Members: Dummy
    55  *      Items: Bprofile-1, Bcomponent-1, Bcomponent-2
    56  *
     51 * Owner: anotherPrincipal Members: Dummy Items: Bprofile-1, Bcomponent-1,
     52 * Bcomponent-2
     53 *
    5754 * C
    58  *      Owner: anotherPrincipal
    59  *      Members: -
    60  *      Items: Cprofile-1, Ccomponent-1, Ccomponent-2
    61  *
     55 * Owner: anotherPrincipal Members: - Items: Cprofile-1, Ccomponent-1,
     56 * Ccomponent-2
     57 *
    6258 * D
    63  *      Owner: anotherPrincipal
    64  *      Members: Dummy, anotherPrincipal
    65  *      Items: Dprofile-1, Dcomponent-1, Dcomponent-2
    66  *
     59 * Owner: anotherPrincipal Members: Dummy, anotherPrincipal Items: Dprofile-1,
     60 * Dcomponent-1, Dcomponent-2
     61 *
    6762 * @author olhsha
    6863 * @author twagoo
     
    160155    }
    161156
    162      private void MakeGroupC() throws ItemNotFoundException{
     157    private void MakeGroupC() throws ItemNotFoundException {
    163158        groupService.createNewGroup("group C", "anotherPrincipal");
    164159    }
     
    189184    }
    190185
    191      private void MakeGroupD() throws ItemNotFoundException{
     186    private void MakeGroupD() throws ItemNotFoundException {
    192187        groupService.createNewGroup("group D", "anotherPrincipal");
    193188        groupService.makeMember("anotherPrincipal", "group D");
     
    220215    }
    221216
    222 
    223217//    List<Group> getGroupsTheCurrentUserIsAMemberOf();   
    224218    @Test
     
    239233//    Response transferItemOwnershipToGroup(String itemId, long groupId) throws IOException;   
    240234//   
     235
    241236    @Test
    242237    public void testTransferOwnership() throws Exception {
     
    278273    }
    279274
    280      
    281275    @Test
    282276    public void testTransferOwnershipBetweenGroups() throws Exception {
     
    288282        fillUpGroupD();
    289283        // test itself
    290        
     284
    291285        // this profile was created and moved into group D by someone else
    292286        String test_profile_id = ProfileDescription.PROFILE_PREFIX + "Dprofile-1";
     
    296290        // I am member of both groups, so should be allowed
    297291        assertEquals("Moving between groups should be allowed as long as user is member", 200, cr.getStatus());
    298        
     292
    299293        // this component was created and moved into group D by someone else
    300294        String test_component_id = ComponentDescription.COMPONENT_PREFIX + "Dcomponent-1";
     
    304298        // I am not a member of groups C, so should not be allowed
    305299        assertEquals("Moving between groups should not be allowed if user is not member", 403, cr.getStatus());
    306        
    307        
    308        // component in group C
     300
     301        // component in group C
    309302        test_component_id = ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1";
    310303        // try to move to group B (which I am a member of)
     
    313306        // I am not a member of group C, so should not be allowed
    314307        assertEquals("Moving between groups should not be allowed if user is not member", 403, cr.getStatus());
    315        
    316     }
    317    
     308
     309    }
     310
    318311    @Test
    319312    public void testGetGroupProfilesAndComponents() throws Exception {
     
    410403        (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1", ProfileDescription.PROFILE_PREFIX + "Cprofile-1", "anotherPrincipal");
    411404
    412                 // lists
     405        // lists
    413406        List<Comment> response = this.getAuthenticatedResource(getResource()
    414407                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/"))
     
    497490        fillUpGroupC();
    498491
    499          // lists of profiles and components
     492        // lists of profiles and components
    500493        Rss response = this.getAuthenticatedResource(getResource()
    501494                .path("/registry/profiles/rss").queryParam("registrySpace", REGISTRY_SPACE_GROUP).queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML)
     
    536529        (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1", ProfileDescription.PROFILE_PREFIX + "Cprofile-1", "anotherPrincipal");
    537530
    538                 // lists
     531        // lists
    539532        response = this.getAuthenticatedResource(getResource()
    540533                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/rss"))
     
    10991092                .path("/registry/components/" + id + "/xsd"))
    11001093                .accept(MediaType.TEXT_XML).get(ClientResponse.class);
    1101         assertEquals(403, resp.getStatus());
     1094        assertEquals("XSD should always be available", 200, resp.getStatus());
    11021095
    11031096        id = ProfileDescription.PROFILE_PREFIX + "Cprofile-1";
     
    11051098                .path("/registry/profiles/" + id + "/xsd"))
    11061099                .accept(MediaType.TEXT_XML).get(ClientResponse.class);
    1107         assertEquals(403, resp.getStatus());
     1100        assertEquals("XSD should always be available", 200, resp.getStatus());
    11081101
    11091102    }
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java

    r5568 r5872  
    276276                .path("/registry/components/" + id + "/xsd"))
    277277                .accept(MediaType.TEXT_XML).get( ClientResponse.class);
    278         assertEquals(403, resp.getStatus());
     278        assertEquals("XSD should always be available", 200, resp.getStatus());
    279279       
    280280        id = ProfileDescription.PROFILE_PREFIX + "Cprofile-1";
     
    282282                .path("/registry/profiles/" + id + "/xsd"))
    283283                .accept(MediaType.TEXT_XML).get( ClientResponse.class);
    284         assertEquals(403, resp.getStatus());
     284        assertEquals("XSD should always be available", 200, resp.getStatus());
    285285       
    286286       
Note: See TracChangeset for help on using the changeset viewer.