diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/CacheConfiguration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/CacheConfiguration.java new file mode 100644 index 000000000..20c18102e --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/CacheConfiguration.java @@ -0,0 +1,77 @@ +package org.apache.archiva.admin.model.beans; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.xml.bind.annotation.XmlRootElement; +import java.io.Serializable; + +/** + * @author Olivier Lamy + * @since 1.4-M4 + */ +@XmlRootElement( name = "cacheConfiguration" ) +public class CacheConfiguration + implements Serializable +{ + /** + * TimeToIdleSeconds. + */ + private int timeToIdleSeconds = -1; + + /** + * TimeToLiveSeconds. + */ + private int timeToLiveSeconds = -1; + + public CacheConfiguration() + { + // no op + } + + public int getTimeToIdleSeconds() + { + return timeToIdleSeconds; + } + + public void setTimeToIdleSeconds( int timeToIdleSeconds ) + { + this.timeToIdleSeconds = timeToIdleSeconds; + } + + public int getTimeToLiveSeconds() + { + return timeToLiveSeconds; + } + + public void setTimeToLiveSeconds( int timeToLiveSeconds ) + { + this.timeToLiveSeconds = timeToLiveSeconds; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "CacheConfiguration" ); + sb.append( "{timeToIdleSeconds=" ).append( timeToIdleSeconds ); + sb.append( ", timeToLiveSeconds=" ).append( timeToLiveSeconds ); + sb.append( '}' ); + return sb.toString(); + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultRedbackRuntimeConfigurationAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultRedbackRuntimeConfigurationAdmin.java index d8102738b..dcd137b89 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultRedbackRuntimeConfigurationAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultRedbackRuntimeConfigurationAdmin.java @@ -20,12 +20,14 @@ package org.apache.archiva.admin.repository.runtime; import net.sf.beanlib.provider.replicator.BeanReplicator; import org.apache.archiva.admin.model.RepositoryAdminException; +import org.apache.archiva.admin.model.beans.CacheConfiguration; import org.apache.archiva.admin.model.beans.LdapConfiguration; import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration; import org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.IndeterminateConfigurationException; +import org.apache.archiva.redback.components.cache.Cache; import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.configuration.UserConfiguration; import org.apache.archiva.redback.configuration.UserConfigurationException; @@ -58,6 +60,10 @@ public class DefaultRedbackRuntimeConfigurationAdmin @Named( value = "userConfiguration#redback" ) UserConfiguration userConfiguration; + @Inject + @Named( value = "cache#users" ) + private Cache usersCache; + @PostConstruct public void initialize() throws UserConfigurationException @@ -104,7 +110,6 @@ public class DefaultRedbackRuntimeConfigurationAdmin updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration ); } - // we must ensure userManagerImpls list is not empty if so put at least jdo one ! if ( redbackRuntimeConfiguration.getUserManagerImpls().isEmpty() ) { @@ -114,6 +119,39 @@ public class DefaultRedbackRuntimeConfigurationAdmin 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 ( save ) + { + updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration ); + } + } catch ( RepositoryAdminException e ) { @@ -129,8 +167,8 @@ public class DefaultRedbackRuntimeConfigurationAdmin public void updateRedbackRuntimeConfiguration( RedbackRuntimeConfiguration redbackRuntimeConfiguration ) throws RepositoryAdminException { - org.apache.archiva.configuration.RedbackRuntimeConfiguration - runtimeConfiguration = build( redbackRuntimeConfiguration ); + org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration = + build( redbackRuntimeConfiguration ); Configuration configuration = archivaConfiguration.getConfiguration(); configuration.setRedbackRuntimeConfiguration( runtimeConfiguration ); try @@ -147,7 +185,8 @@ public class DefaultRedbackRuntimeConfigurationAdmin } } - private RedbackRuntimeConfiguration build( org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration ) + private RedbackRuntimeConfiguration build( + org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration ) { RedbackRuntimeConfiguration redbackRuntimeConfiguration = new BeanReplicator().replicateBean( runtimeConfiguration, RedbackRuntimeConfiguration.class ); @@ -159,24 +198,42 @@ public class DefaultRedbackRuntimeConfigurationAdmin 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() ); + } + return redbackRuntimeConfiguration; } - private org.apache.archiva.configuration.RedbackRuntimeConfiguration build( RedbackRuntimeConfiguration archivaRuntimeConfiguration ) + private org.apache.archiva.configuration.RedbackRuntimeConfiguration build( + RedbackRuntimeConfiguration archivaRuntimeConfiguration ) { org.apache.archiva.configuration.RedbackRuntimeConfiguration redbackRuntimeConfiguration = - new BeanReplicator().replicateBean( archivaRuntimeConfiguration, org.apache.archiva.configuration.RedbackRuntimeConfiguration.class ); + new BeanReplicator().replicateBean( archivaRuntimeConfiguration, + org.apache.archiva.configuration.RedbackRuntimeConfiguration.class ); redbackRuntimeConfiguration.setLdapConfiguration( new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getLdapConfiguration(), org.apache.archiva.configuration.LdapConfiguration.class ) ); + redbackRuntimeConfiguration.setUsersCacheConfiguration( + new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getUsersCacheConfiguration(), + org.apache.archiva.configuration.CacheConfiguration.class ) ); + return redbackRuntimeConfiguration; } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java index 3959a4209..b4d68d721 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java @@ -78,38 +78,6 @@ public class DefaultRedbackRuntimeConfigurationService @Named( value = "cache#users" ) private Cache usersCache; - @PostConstruct - public void initialize() - throws RepositoryAdminException - { - RedbackRuntimeConfiguration redbackRuntimeConfiguration = - redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration(); - - // 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() ); - - } - usersCache.setTimeToIdleSeconds( - redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() ); - - if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() < 0 ) - { - redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToLiveSeconds( - usersCache.getTimeToLiveSeconds() ); - - } - usersCache.setTimeToLiveSeconds( - redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() ); - - } public RedbackRuntimeConfiguration getRedbackRuntimeConfiguration() throws ArchivaRestServiceException