Package org.constretto

Examples of org.constretto.ConstrettoBuilder


public class AltinnAuthorizationDecisionPointExternalClientCallback implements CallbackHandler {

  String password;

  public AltinnAuthorizationDecisionPointExternalClientCallback() {
    ConstrettoConfiguration config = new ConstrettoBuilder().createPropertiesStore().addResource(new DefaultResourceLoader().getResource("classpath:application.properties")).done().getConfiguration();
    password = config.evaluateToString("altinn.systemPassword");
  }
View Full Code Here


        }

        try {
            lock.writeLock().lock();
            cacheMiss++;
            ConstrettoBuilder builder = new ConstrettoBuilder(includeSystemProperties);
            IniFileConfigurationStore iniFileConfigurationStore = new IniFileConfigurationStore();
            PropertiesStore propertyFileConfigurationStore = new PropertiesStore();

            for (String location : locations) {
                if (location.toLowerCase().endsWith(".ini")) {
                    iniFileConfigurationStore.addResource(Resource.create(location));
                } else if (location.toLowerCase().endsWith(".properties")) {
                    propertyFileConfigurationStore.addResource(Resource.create(location));
                }
            }
            builder = builder.addConfigurationStore(iniFileConfigurationStore);
            builder = builder.addConfigurationStore(propertyFileConfigurationStore);
            if(includeSystemProperties){
                builder = builder.createSystemPropertiesStore();
            }
            ConstrettoConfiguration configuration = builder.getConfiguration();
            cache.put(key, configuration);
            return configuration;
        } finally {
            lock.writeLock().unlock();
        }
View Full Code Here

public class JsonStoreTest {

    @Test
    public void jsonShouldParseCorrectly() {
        ConstrettoConfiguration conf = new ConstrettoBuilder()
                .createJsonConfigurationStore()
                .addResource(Resource.create("classpath:jsonTest.json"), "person")
                .done()
                .getConfiguration();
        Person person = conf.evaluateWith(new PersonJsonConverter(), "person");
View Full Code Here

        assertEquals(new Person("Kaare", 29), person);
    }

    @Test
    public void jsonShouldAllowNonExistingResources() {
        ConstrettoConfiguration conf = new ConstrettoBuilder()
                .createJsonConfigurationStore()
                .addResource(Resource.create("classpath:nonExisiting.json"), "person")
                .addResource(Resource.create("file:/nonExisiting.json"), "person")
                .addResource(Resource.create("http:/nonExisiting.com"), "person")
                .done()
View Full Code Here

    @Test
    public void testAsClassRule() throws Exception {
        String[] expected = {"purejunit", "test"};

        ConstrettoConfiguration configuration =
                new ConstrettoBuilder().createSystemPropertiesStore().getConfiguration();
        configuration.on(this);

        assertArrayEquals(expected, currentEnvironment.toArray(new String[0]));

View Full Code Here

        verify(attribute).get(eq(0));
        verify(attribute).get(eq(1));
    }

    private ConstrettoConfiguration createConfigurationForLdapConfigurationStore(LdapConfigurationStore ldapConfigurationStore) {
        return new ConstrettoBuilder(false)
                    .addConfigurationStore(ldapConfigurationStore)
                    .getConfiguration();
    }
View Full Code Here

        }


        @SuppressWarnings("unchecked")
        private ConstrettoConfiguration buildConfig(Element element, ConfigurationContextResolver configurationContextResolver) {
            ConstrettoBuilder builder = new ConstrettoBuilder(configurationContextResolver, true);
            Element storeElement = DomUtils.getChildElementByTagName(element, "stores");
            if (storeElement != null) {
                List<Element> stores = getAllChildElements(storeElement);
                for (Element store : stores) {
                    String tagName = store.getLocalName();
                    if ("properties-store".equals(tagName)) {
                        ConstrettoBuilder.PropertiesStoreBuilder propertiesBuilder = builder.createPropertiesStore();
                        List<Element> resources = DomUtils.getChildElementsByTagName(store, "resource");
                        for (Element resource : resources) {
                            String location = resource.getAttribute("location");
                            propertiesBuilder.addResource(Resource.create(location));
                        }
                        propertiesBuilder.done();
                    } else if ("encrypted-properties-store".equals(tagName)) {
                        ConstrettoBuilder.EncryptedPropertiesStoreBuilder propertiesBuilder = builder.createEncryptedPropertiesStore(store.getAttribute("password-property"));
                        List<Element> resources = DomUtils.getChildElementsByTagName(store, "resource");
                        for (Element resource : resources) {
                            String location = resource.getAttribute("location");
                            propertiesBuilder.addResource(Resource.create(location));
                        }
                        propertiesBuilder.done();
                    } else if ("ini-store".equals(tagName)) {
                        ConstrettoBuilder.IniFileConfigurationStoreBuilder iniBuilder = builder.createIniFileConfigurationStore();
                        List<Element> resources = DomUtils.getChildElementsByTagName(store, "resource");
                        for (Element resource : resources) {
                            String location = resource.getAttribute("location");
                            iniBuilder.addResource(Resource.create(location));
                        }
                        iniBuilder.done();
                    } else if ("system-properties-store".equals(tagName)) {
                        builder.createSystemPropertiesStore();
                    } else if ("object-store".equals(tagName)) {
                        ConstrettoBuilder.ObjectConfigurationStoreBuilder objectBuilder = builder.createObjectConfigurationStore();
                        List<Element> objects = DomUtils.getChildElementsByTagName(store, "object");
                        for (Element object : objects) {
                            String clazz = object.getAttribute("class");
                            try {
                                objectBuilder.addObject(Class.forName(clazz).newInstance());
                            } catch (Exception e) {
                                throw new IllegalStateException("Could not instantiate configuration source object with class [" + clazz + "]");
                            }
                        }
                        objectBuilder.done();
                    }
                }
            }

            return builder.getConfiguration();
        }
View Full Code Here

    @Test
    public void testDsnMultiValue() throws Exception {

        final InitialDirContext initialDirContext = new InitialDirContext(createLdapEnvironment());
        final ConstrettoConfiguration configuration = new ConstrettoBuilder(false)
                .createLdapConfigurationStore(initialDirContext)
                    .addDsn("cn=role_developer,ou=groups,dc=constretto,dc=org")
                .done()
                .getConfiguration();
        final List<String> members = configuration.evaluateToList(String.class, "uniquemember");
View Full Code Here

    }

    @Test
    public void testParseConfigurationUsingSearch() throws Exception {
        final InitialDirContext initialDirContext = new InitialDirContext(createLdapEnvironment());
        final ConstrettoConfiguration configuration = new ConstrettoBuilder(false)
                .createLdapConfigurationStore(initialDirContext)
                .addUsingSearch(
                        "dc=constretto,dc=org",
                        "(&(cn=K*)(objectClass=inetOrgPerson))",
                        "uid")
View Full Code Here

        initialDirContext.close();

    }

    private ConstrettoConfiguration createConfiguration(LdapConfigurationStore configurationStore) {
        return new ConstrettoBuilder(false).addConfigurationStore(
                configurationStore).getConfiguration();
    }
View Full Code Here

TOP

Related Classes of org.constretto.ConstrettoBuilder

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.