From 0e9352150a8f326d51c8317c5e8eefe8408bd408 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 12 Jan 2021 23:36:37 +0100 Subject: [PATCH] Adding cache configuration --- .../v2/SecurityConfigurationService.java | 2 +- .../DefaultSecurityConfigurationService.java | 4 +- .../src/app/model/cache-configuration.spec.ts | 25 ++++++ .../src/app/model/cache-configuration.ts | 24 ++++++ .../security-configuration-routing.module.ts | 2 + .../security/security-configuration.module.ts | 4 +- .../cache-setting.component.html | 45 ++++++++++ .../cache-setting.component.scss | 18 ++++ .../cache-setting.component.spec.ts | 43 ++++++++++ .../cache-setting/cache-setting.component.ts | 82 +++++++++++++++++++ .../ldap-security.component.html | 8 +- .../ldap-security/ldap-security.component.ts | 3 + .../security-configuration.component.html | 3 + .../modules/shared/toast/toast.component.scss | 13 ++- .../modules/shared/toast/toast.component.ts | 13 ++- .../src/app/services/security.service.ts | 17 ++++ .../src/app/services/toast.service.ts | 2 +- .../main/archiva-web/src/assets/i18n/en.json | 18 ++++ 18 files changed, 312 insertions(+), 14 deletions(-) create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/cache-configuration.spec.ts create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/cache-configuration.ts create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.html create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.scss create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.spec.ts create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.ts diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java index 341b6b758..36dd46269 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java @@ -304,7 +304,7 @@ public interface SecurityConfigurationService content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ) } ) - Response updateCacheConfiguration( CacheConfiguration cacheConfiguration ) throws ArchivaRestServiceException; + CacheConfiguration updateCacheConfiguration( CacheConfiguration cacheConfiguration ) throws ArchivaRestServiceException; @Path("user_managers") diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java index f059613c0..d5a435bf9 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java @@ -596,7 +596,7 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio } @Override - public Response updateCacheConfiguration( CacheConfiguration cacheConfiguration ) throws ArchivaRestServiceException + public CacheConfiguration updateCacheConfiguration( CacheConfiguration cacheConfiguration ) throws ArchivaRestServiceException { if ( cacheConfiguration == null ) { @@ -610,7 +610,7 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio log.debug( "getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration ); updateConfig( cacheConfiguration, redbackRuntimeConfiguration ); redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration ); - return Response.ok( ).build( ); + return getCacheConfiguration( ); } catch ( RepositoryAdminException e ) { diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/cache-configuration.spec.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/cache-configuration.spec.ts new file mode 100644 index 000000000..42cf7c521 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/cache-configuration.spec.ts @@ -0,0 +1,25 @@ +/* + * 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 { CacheConfiguration } from './cache-configuration'; + +describe('CacheConfiguration', () => { + it('should create an instance', () => { + expect(new CacheConfiguration()).toBeTruthy(); + }); +}); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/cache-configuration.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/cache-configuration.ts new file mode 100644 index 000000000..56cd73b4b --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/cache-configuration.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + +export class CacheConfiguration { + time_to_idle_seconds:number=-1; + time_to_live_seconds:number=-1; + max_entries_in_memory:number = -1; + max_entries_on_disk:number=-1; +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration-routing.module.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration-routing.module.ts index edb681d61..34a6e6968 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration-routing.module.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration-routing.module.ts @@ -22,6 +22,7 @@ import {SecurityConfigurationComponent} from "./security-configuration/security- import {BaseSecurityComponent} from "./security-configuration/base-security/base-security.component"; import {LdapSecurityComponent} from "./security-configuration/ldap-security/ldap-security.component"; import {SecurityPropertiesComponent} from "@app/modules/security/security-configuration/security-properties/security-properties.component"; +import {CacheSettingComponent} from "@app/modules/security/security-configuration/cache-setting/cache-setting.component"; /** @@ -37,6 +38,7 @@ const routes: Routes = [ {path: 'base', component: BaseSecurityComponent}, {path: 'properties', component: SecurityPropertiesComponent}, {path: 'ldap', component: LdapSecurityComponent}, + {path: 'cache', component: CacheSettingComponent}, {path: '', redirectTo: 'base', pathMatch: 'full'} ] } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration.module.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration.module.ts index a36d79693..19001ca29 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration.module.ts +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration.module.ts @@ -25,6 +25,7 @@ import {SecurityConfigurationRoutingModule} from "@app/modules/security/security import { BaseSecurityComponent } from './security-configuration/base-security/base-security.component'; import { LdapSecurityComponent } from './security-configuration/ldap-security/ldap-security.component'; import { SecurityPropertiesComponent } from './security-configuration/security-properties/security-properties.component'; +import { CacheSettingComponent } from './security-configuration/cache-setting/cache-setting.component'; @NgModule({ @@ -32,7 +33,8 @@ import { SecurityPropertiesComponent } from './security-configuration/security-p SecurityConfigurationComponent, BaseSecurityComponent, LdapSecurityComponent, - SecurityPropertiesComponent + SecurityPropertiesComponent, + CacheSettingComponent ], exports: [ SecurityConfigurationComponent diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.html b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.html new file mode 100644 index 000000000..45de5eb22 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.html @@ -0,0 +1,45 @@ + + +
+

{{'security.config.cache.explain'|translate}}

+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.scss b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.scss new file mode 100644 index 000000000..343c3b1c0 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.scss @@ -0,0 +1,18 @@ +/*! + * 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. + */ + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.spec.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.spec.ts new file mode 100644 index 000000000..6c6edb209 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.spec.ts @@ -0,0 +1,43 @@ +/* + * 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 { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CacheSettingComponent } from './cache-setting.component'; + +describe('CacheSettingComponent', () => { + let component: CacheSettingComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ CacheSettingComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(CacheSettingComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.ts new file mode 100644 index 000000000..35578ca02 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/cache-setting/cache-setting.component.ts @@ -0,0 +1,82 @@ +/* + * 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 {Component, OnInit} from '@angular/core'; +import {EditBaseComponent} from "@app/modules/shared/edit-base.component"; +import {CacheConfiguration} from "@app/model/cache-configuration"; +import {ActivatedRoute} from "@angular/router"; +import {FormBuilder} from "@angular/forms"; +import {SecurityService} from "@app/services/security.service"; +import {ToastService} from "@app/services/toast.service"; +import {HttpResponse} from "@angular/common/http"; +import {ErrorResult} from "@app/model/error-result"; + +@Component({ + selector: 'app-cache-setting', + templateUrl: './cache-setting.component.html', + styleUrls: ['./cache-setting.component.scss'] +}) +export class CacheSettingComponent extends EditBaseComponent implements OnInit { + formFields = ['time_to_idle_seconds', 'time_to_live_seconds', 'max_entries_in_memory', 'max_entries_on_disk']; + submitError: ErrorResult = null; + + constructor(private route: ActivatedRoute, + public fb: FormBuilder, private securityService: SecurityService, private toastService: ToastService) { + super(fb); + super.init(fb.group({ + time_to_idle_seconds: [''], + time_to_live_seconds: [''], + max_entries_in_memory: [''], + max_entries_on_disk: [''], + }, {})); + } + + ngOnInit(): void { + this.securityService.getCacheConfiguration().subscribe( + (cacheConfig: CacheConfiguration) => { + this.copyToForm(this.formFields, cacheConfig); + } + ) + } + + createEntity(): CacheConfiguration { + return new CacheConfiguration(); + } + + onSubmit() { + if (this.userForm.valid && this.userForm.dirty) { + let cacheConfig = this.copyFromForm(this.formFields) + this.securityService.updateCacheConfiguration(cacheConfig).subscribe( + (httpCacheConfig: HttpResponse) => { + this.userForm.reset(); + if (httpCacheConfig.body!=null) { + this.copyToForm(this.formFields, httpCacheConfig.body); + } + this.toastService.showSuccessByKey('cache-settings','security.config.cache.submit_success'); + }, + (error: ErrorResult) => { + this.submitError=error; + this.toastService.showErrorByKey('cache-settings','security.config.cache.submit_error',{error:error.toString()}); + } + ); + } else { + console.log("No changes to update"); + } + } + +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/ldap-security/ldap-security.component.html b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/ldap-security/ldap-security.component.html index aa2d70615..9c23ac08e 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/ldap-security/ldap-security.component.html +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/ldap-security/ldap-security.component.html @@ -25,7 +25,7 @@ [openDelay]="500" [ngbTooltip]="'security.config.ldap.attdesc.'+attName|translate" placement="top" >{{'security.config.ldap.attributes.' + attName |translate}} -
+
-
- -