Package org.apache.archiva.admin.model.beans

Examples of org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration


    public void removeLdapMapping( String group )
        throws MappingException
    {
        try
        {
            RedbackRuntimeConfiguration redbackRuntimeConfiguration =
                redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
            boolean removed =
                redbackRuntimeConfiguration.getLdapGroupMappings().remove( new LdapGroupMapping( group ) );
            redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
            logger.debug( "removeLdapMapping ldapGroup: {}, removed: {}", group, removed );
        }
        catch ( RepositoryAdminException e )
        {
View Full Code Here


    public Map<String, Collection<String>> getLdapGroupMappings()
        throws MappingException
    {
        try
        {
            RedbackRuntimeConfiguration redbackRuntimeConfiguration =
                redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();

            List<LdapGroupMapping> ldapGroupMappings = redbackRuntimeConfiguration.getLdapGroupMappings();

            if ( ldapGroupMappings == null )
            {
                return Collections.emptyMap();
            }
View Full Code Here

    public void setLdapGroupMappings( Map<String, List<String>> mappings )
        throws MappingException
    {
        try
        {
            RedbackRuntimeConfiguration redbackRuntimeConfiguration =
                redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();

            List<LdapGroupMapping> ldapGroupMappings = new ArrayList<LdapGroupMapping>( mappings.size() );

            for ( Map.Entry<String, List<String>> entry : mappings.entrySet() )
            {
                ldapGroupMappings.add( new LdapGroupMapping( entry.getKey(), entry.getValue() ) );
            }

            redbackRuntimeConfiguration.setLdapGroupMappings( ldapGroupMappings );

            redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
        }
        catch ( RepositoryAdminException e )
        {
View Full Code Here

    public void initialize()
        throws UserConfigurationException
    {
        try
        {
            RedbackRuntimeConfiguration redbackRuntimeConfiguration = getRedbackRuntimeConfiguration();
            // migrate or not data from redback
            if ( !redbackRuntimeConfiguration.isMigratedFromRedbackConfiguration() )
            {
                // not migrated so build a new fresh one
                redbackRuntimeConfiguration = new RedbackRuntimeConfiguration();
                // so migrate if available
                String userManagerImpl =
                    userConfiguration.getConcatenatedList( UserConfigurationKeys.USER_MANAGER_IMPL, "jdo" );
                if ( StringUtils.isNotEmpty( userManagerImpl ) )
                {
                    String[] impls = StringUtils.split( userManagerImpl, ',' );
                    for ( String impl : impls )
                    {
                        redbackRuntimeConfiguration.getUserManagerImpls().add( impl );
                    }
                }

                String rbacManagerImpls =
                    userConfiguration.getConcatenatedList( UserConfigurationKeys.RBAC_MANAGER_IMPL, "jdo" );

                if ( StringUtils.isNotEmpty( rbacManagerImpls ) )
                {
                    String[] impls = StringUtils.split( rbacManagerImpls, ',' );
                    for ( String impl : impls )
                    {
                        redbackRuntimeConfiguration.getRbacManagerImpls().add( impl );
                    }
                }

                // now ldap

                LdapConfiguration ldapConfiguration = redbackRuntimeConfiguration.getLdapConfiguration();
                if ( ldapConfiguration == null )
                {
                    ldapConfiguration = new LdapConfiguration();
                    redbackRuntimeConfiguration.setLdapConfiguration( ldapConfiguration );
                }

                ldapConfiguration.setHostName(
                    userConfiguration.getString( UserConfigurationKeys.LDAP_HOSTNAME, null ) );
                ldapConfiguration.setPort( userConfiguration.getInt( UserConfigurationKeys.LDAP_PORT, -1 ) );
                ldapConfiguration.setSsl( userConfiguration.getBoolean( UserConfigurationKeys.LDAP_SSL, false ) );
                ldapConfiguration.setBaseDn(
                    userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_BASEDN, null ) );

                ldapConfiguration.setBaseGroupsDn(
                    userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_GROUPS_BASEDN,
                                                           ldapConfiguration.getBaseDn() ) );

                ldapConfiguration.setContextFactory(
                    userConfiguration.getString( UserConfigurationKeys.LDAP_CONTEX_FACTORY,
                                                 isSunContextFactoryAvailable()
                                                     ? "com.sun.jndi.ldap.LdapCtxFactory"
                                                     : "" ) );
                ldapConfiguration.setBindDn(
                    userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_BINDDN, null ) );
                ldapConfiguration.setPassword(
                    userConfiguration.getString( UserConfigurationKeys.LDAP_PASSWORD, null ) );
                ldapConfiguration.setAuthenticationMethod(
                    userConfiguration.getString( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD, null ) );

                ldapConfiguration.setWritable(
                    userConfiguration.getBoolean( UserConfigurationKeys.LDAP_WRITABLE, false ) );

                ldapConfiguration.setUseRoleNameAsGroup(
                    userConfiguration.getBoolean( UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME, false ) );

                boolean ldapBindAuthenticatorEnabled =
                    userConfiguration.getBoolean( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED, false );
                ldapConfiguration.setBindAuthenticatorEnabled( ldapBindAuthenticatorEnabled );

                // LDAP groups mapping reading !!
                // UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY
                // userConfiguration.getKeys()

                Collection<String> keys = userConfiguration.getKeys();

                List<LdapGroupMapping> ldapGroupMappings = new ArrayList<LdapGroupMapping>();

                for ( String key : keys )
                {
                    if ( key.startsWith( UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ) )
                    {
                        String group =
                            StringUtils.substringAfter( key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY );
                        String val = userConfiguration.getConcatenatedList( key, "" );
                        if ( !StringUtils.isEmpty( val ) )
                        {
                            String[] roles = StringUtils.split( val, ',' );
                            ldapGroupMappings.add( new LdapGroupMapping( group, roles ) );
                        }
                    }
                }

                redbackRuntimeConfiguration.setLdapGroupMappings( ldapGroupMappings );

                redbackRuntimeConfiguration.setMigratedFromRedbackConfiguration( true );

                updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );

            }
            // we must ensure userManagerImpls list is not empty if so put at least jdo one !
            if ( redbackRuntimeConfiguration.getUserManagerImpls().isEmpty() )
            {
                log.info(
                    "redbackRuntimeConfiguration with empty userManagerImpls so force at least jdo implementation !" );
                redbackRuntimeConfiguration.getUserManagerImpls().add( "jdo" );
                updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
            }

            // we ensure authorizerImpls is not empty if so put
            if ( redbackRuntimeConfiguration.getRbacManagerImpls().isEmpty() )
            {
                log.info(
                    "redbackRuntimeConfiguration with empty rbacManagerImpls so force at least cached implementation !" );
                redbackRuntimeConfiguration.getRbacManagerImpls().add( "cached" );
                updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
            }

            boolean save = false;

            // NPE free
            if ( redbackRuntimeConfiguration.getUsersCacheConfiguration() == null )
            {
                redbackRuntimeConfiguration.setUsersCacheConfiguration( new CacheConfiguration() );
            }
            // if -1 it means non initialized to take values from the spring bean
            if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() < 0 )
            {
                redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToIdleSeconds(
                    usersCache.getTimeToIdleSeconds() );
                save = true;

            }
            usersCache.setTimeToIdleSeconds(
                redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() );

            if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() < 0 )
            {
                redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToLiveSeconds(
                    usersCache.getTimeToLiveSeconds() );
                save = true;

            }
            usersCache.setTimeToLiveSeconds(
                redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() );

            if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsInMemory() < 0 )
            {
                redbackRuntimeConfiguration.getUsersCacheConfiguration().setMaxElementsInMemory(
                    usersCache.getMaxElementsInMemory() );
                save = true;
            }
            usersCache.setMaxElementsInMemory(
                redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsInMemory() );

            if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsOnDisk() < 0 )
            {
                redbackRuntimeConfiguration.getUsersCacheConfiguration().setMaxElementsOnDisk(
                    usersCache.getMaxElementsOnDisk() );
                save = true;
            }
            usersCache.setMaxElementsOnDisk(
                redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsOnDisk() );

            if ( save )
            {
                updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
            }
View Full Code Here

    }

    private RedbackRuntimeConfiguration build(
        org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration )
    {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration =
            new BeanReplicator().replicateBean( runtimeConfiguration, RedbackRuntimeConfiguration.class );

        if ( runtimeConfiguration.getLdapConfiguration() != null )
        {
            redbackRuntimeConfiguration.setLdapConfiguration(
                new BeanReplicator().replicateBean( runtimeConfiguration.getLdapConfiguration(),
                                                    LdapConfiguration.class ) );
        }

        if ( runtimeConfiguration.getUsersCacheConfiguration() != null )
        {
            redbackRuntimeConfiguration.setUsersCacheConfiguration(
                new BeanReplicator().replicateBean( runtimeConfiguration.getUsersCacheConfiguration(),
                                                    CacheConfiguration.class ) );
        }

        if ( redbackRuntimeConfiguration.getLdapConfiguration() == null )
        {
            // prevent NPE
            redbackRuntimeConfiguration.setLdapConfiguration( new LdapConfiguration() );
        }

        if ( redbackRuntimeConfiguration.getUsersCacheConfiguration() == null )
        {
            redbackRuntimeConfiguration.setUsersCacheConfiguration( new CacheConfiguration() );
        }

        List<org.apache.archiva.configuration.LdapGroupMapping> mappings = runtimeConfiguration.getLdapGroupMappings();

        if ( mappings != null && mappings.size() > 0 )
        {
            List<LdapGroupMapping> ldapGroupMappings = new ArrayList<LdapGroupMapping>( mappings.size() );

            for ( org.apache.archiva.configuration.LdapGroupMapping mapping : mappings )
            {
                ldapGroupMappings.add( new LdapGroupMapping( mapping.getGroup(), mapping.getRoleNames() ) );
            }

            redbackRuntimeConfiguration.setLdapGroupMappings( ldapGroupMappings );
        }

        cleanupProperties( redbackRuntimeConfiguration );

        return redbackRuntimeConfiguration;
View Full Code Here

            return getRedbackRuntimeConfiguration().getUserManagerImpls().get( 0 );
        }

        if ( StringUtils.startsWith( key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ) )
        {
            RedbackRuntimeConfiguration redbackRuntimeConfiguration = getRedbackRuntimeConfiguration();
            int index = redbackRuntimeConfiguration.getLdapGroupMappings().indexOf( new LdapGroupMapping(
                StringUtils.substringAfter( key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY ) ) );
            if ( index > -1 )
            {
                return StringUtils.join( redbackRuntimeConfiguration.getLdapGroupMappings().get( index ).getRoleNames(),
                                         ',' );
            }
        }

        RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();

        if ( conf.getConfigurationProperties().containsKey( key ) )
        {
            return conf.getConfigurationProperties().get( key );
        }

        String value = userConfiguration.getString( key );
        if ( value == null )
        {
            return null;
        }
        conf.getConfigurationProperties().put( key, value );

        try
        {
            updateRedbackRuntimeConfiguration( conf );
        }
View Full Code Here

        if ( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD.equals( key ) )
        {
            return getRedbackRuntimeConfiguration().getLdapConfiguration().getAuthenticationMethod();
        }

        RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();

        if ( conf.getConfigurationProperties().containsKey( key ) )
        {
            return conf.getConfigurationProperties().get( key );
        }

        String value = userConfiguration.getString( key, defaultValue );

        if ( value == null )
        {
            return null;
        }

        conf.getConfigurationProperties().put( key, value );
        try
        {
            updateRedbackRuntimeConfiguration( conf );
        }
        catch ( RepositoryAdminException e )
View Full Code Here

        return value;
    }

    public int getInt( String key )
    {
        RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();

        if ( conf.getConfigurationProperties().containsKey( key ) )
        {
            return Integer.valueOf( conf.getConfigurationProperties().get( key ) );
        }

        int value = userConfiguration.getInt( key );

        conf.getConfigurationProperties().put( key, Integer.toString( value ) );
        try
        {
            updateRedbackRuntimeConfiguration( conf );
        }
        catch ( RepositoryAdminException e )
View Full Code Here

        if ( UserConfigurationKeys.LDAP_PORT.equals( key ) )
        {
            return getRedbackRuntimeConfiguration().getLdapConfiguration().getPort();
        }

        RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();

        if ( conf.getConfigurationProperties().containsKey( key ) )
        {
            return Integer.valueOf( conf.getConfigurationProperties().get( key ) );
        }

        int value = userConfiguration.getInt( key, defaultValue );

        conf.getConfigurationProperties().put( key, Integer.toString( value ) );
        try
        {
            updateRedbackRuntimeConfiguration( conf );
        }
        catch ( RepositoryAdminException e )
View Full Code Here

        return value;
    }

    public boolean getBoolean( String key )
    {
        RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration();

        if ( UserConfigurationKeys.LDAP_WRITABLE.equals( key ) )
        {
            return conf.getLdapConfiguration().isWritable();
        }

        if ( UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME.equals( key ) )
        {
            return conf.getLdapConfiguration().isUseRoleNameAsGroup();
        }

        if ( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ENABLED.equals( key ) )
        {
            return conf.getLdapConfiguration().isBindAuthenticatorEnabled();
        }

        if ( conf.getConfigurationProperties().containsKey( key ) )
        {
            return Boolean.valueOf( conf.getConfigurationProperties().get( key ) );
        }

        boolean value = userConfiguration.getBoolean( key );

        conf.getConfigurationProperties().put( key, Boolean.toString( value ) );
        try
        {
            updateRedbackRuntimeConfiguration( conf );
        }
        catch ( RepositoryAdminException e )
View Full Code Here

TOP

Related Classes of org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration

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.