Package org.fao.geonet.domain

Examples of org.fao.geonet.domain.User


      this.userProfile = this.context.getUserSession().getProfile();
    }
   
    private void login() {
        UserSession session = new UserSession();
        session.loginAs(new User().setUsername(this.userName).setId(this.userId).setProfile(this.userProfile));
        this.context.setUserSession(session);
    }
View Full Code Here


    @Test
    public void testCreateMetadataWithTemplateMetadata() throws Exception {
        final ServiceContext serviceContext = createServiceContext();
        loginAsAdmin(serviceContext);

        final User principal = serviceContext.getUserSession().getPrincipal();

        final GroupRepository bean = serviceContext.getBean(GroupRepository.class);
        Group group = bean.findAll().get(0);

        MetadataCategory category = serviceContext.getBean(MetadataCategoryRepository.class).findAll().get(0);

        final SourceRepository sourceRepository = serviceContext.getBean(SourceRepository.class);
        Source source = sourceRepository.save(new Source().setLocal(true).setName("GN").setUuid("sourceuuid"));

        final Element sampleMetadataXml = super.getSampleMetadataXml();
        final Metadata metadata = new Metadata();
        metadata.setDataAndFixCR(sampleMetadataXml)
            .setUuid(UUID.randomUUID().toString());
        metadata.getCategories().add(category);
        metadata.getDataInfo().setSchemaId("iso19139");
        metadata.getSourceInfo().setSourceId(source.getUuid());

        final Metadata templateMd = _metadataRepository.save(metadata);
        final String newMetadataId = _dataManager.createMetadata(serviceContext, "" + metadata.getId(), "" + group.getId(), source.getUuid(),
                principal.getId(), templateMd.getUuid(), MetadataType.METADATA.codeString, true);

        Metadata newMetadata = _metadataRepository.findOne(newMetadataId);
        assertEquals(1, newMetadata.getCategories().size());
        assertEquals(category, newMetadata.getCategories().iterator().next());
        assertEqualsText(metadata.getUuid(), newMetadata.getXmlData(false), "gmd:parentIdentifier/gco:CharacterString");
View Full Code Here

        params.getChild("site").getChild("ownerId").detach();
    }

    @Override
    protected void performExtraAssertions(AbstractHarvester harvester) {
        final User admin = _userRepo.findAllByProfile(Profile.Administrator).get(0);
        assertEquals(""+admin.getId(), harvester.getParams().ownerId);
    }
View Full Code Here

        final String testClassName = cl.getSimpleName();
        return new File(cl.getResource(testClassName + ".class").getFile());
    }

    public User loginAsAdmin(ServiceContext context) {
        final User admin = _userRepo.findAllByProfile(Profile.Administrator).get(0);
        UserSession userSession = new UserSession();
        userSession.loginAs(admin);
        context.setUserSession(userSession);
        return admin;
    }
View Full Code Here

    }

    @Test(expected = UsernameNotFoundException.class)
    public void testUserNotFound() throws Exception{
        final User user = userFoundSetup(PasswordEncoding.CURRENT);

        _geonetworkAuthenticationProvider.retrieveUser(user.getUsername() + "not", authentication);
    }
View Full Code Here

     * Makes dbms find a user.
     *
     * @throws Exception
     */
    private User userFoundSetup(PasswordEncoding passwordEncoding) throws Exception {
        final User entity = UserRepositoryTest.newUser(_inc);
        switch (passwordEncoding) {
            case CURRENT:
                entity.getSecurity().setPassword(_encoder.encode(PASSWORD));
                break;
            case OLD:
                entity.getSecurity().getSecurityNotifications().add(UserSecurityNotification.UPDATE_HASH_REQUIRED);
                final Method method = PasswordUtil.class.getDeclaredMethod("oldScramble", String.class);
                method.setAccessible(true);
                final Object unsaltedScramble = method.invoke(null, PASSWORD);
                entity.getSecurity().setPassword(unsaltedScramble.toString());
                break;
            case UNSALTED:
                entity.getSecurity().getSecurityNotifications().add(UserSecurityNotification.UPDATE_HASH_REQUIRED);
                final Method method2 = PasswordUtil.class.getDeclaredMethod("unsaltedScramble", String.class);
                method2.setAccessible(true);
                final Object oldScramble = method2.invoke(null, PASSWORD);
                entity.getSecurity().setPassword(oldScramble.toString());
                break;
        }
        return _userRepo.save(entity);
    }
View Full Code Here

        return _userRepo.save(entity);
    }

    @Test
    public void testUserFound() throws Exception{
        final User user = userFoundSetup(PasswordEncoding.CURRENT);

        _geonetworkAuthenticationProvider.retrieveUser(user.getUsername(), authentication);
        TestCase.assertNotNull("User should be found",
                _geonetworkAuthenticationProvider.retrieveUser(user.getUsername(), authentication));
    }
View Full Code Here

                _geonetworkAuthenticationProvider.retrieveUser(user.getUsername(), authentication));
    }

    @Test
    public void testFindUserWithAuthenticationTokenUnsalted() throws Exception{
        final User user = userFoundSetup(PasswordEncoding.UNSALTED);

        mockAuthenticationSetup(user);

        final UserDetails userDetails = _geonetworkAuthenticationProvider.retrieveUser(user.getUsername(), authentication);
        TestCase.assertNotNull("User with authentication token should be found", userDetails);
    }
View Full Code Here

        TestCase.assertNotNull("User with authentication token should be found", userDetails);
    }

    @Test
    public void testFindUserWithAuthenticationTokenOldPasswordHash() throws Exception{
        final User user = userFoundSetup(PasswordEncoding.OLD);

        mockAuthenticationSetup(user);

        final UserDetails userDetails = _geonetworkAuthenticationProvider.retrieveUser(user.getUsername(), authentication);
        TestCase.assertNotNull("User with authentication token should be found", userDetails);
    }
View Full Code Here

        final UserDetails userDetails = _geonetworkAuthenticationProvider.retrieveUser(user.getUsername(), authentication);
        TestCase.assertNotNull("User with authentication token should be found", userDetails);
    }
    @Test
    public void testFindUserWithAuthenticationToken() throws Exception{
        final User user = userFoundSetup(PasswordEncoding.CURRENT);
        mockAuthenticationSetup(user);

        final UserDetails userDetails = _geonetworkAuthenticationProvider.retrieveUser(user.getUsername(), authentication);
        TestCase.assertNotNull("User with authentication token should be found", userDetails);
    }
View Full Code Here

TOP

Related Classes of org.fao.geonet.domain.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.