Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
fix(application): Archived applications must be in readonly mode
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGeraud committed Nov 6, 2019
1 parent 39b589f commit e234dc5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
@@ -0,0 +1,41 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed 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.
*/
package io.gravitee.management.service.exceptions;

import io.gravitee.common.http.HttpStatusCode;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public class ApplicationArchivedException extends AbstractManagementException {

private final String applicationName;

public ApplicationArchivedException(String applicationName) {
this.applicationName = applicationName;
}

@Override
public int getHttpStatusCode() {
return HttpStatusCode.BAD_REQUEST_400;
}

@Override
public String getMessage() {
return "Application [" + applicationName + "] is archived and cannot be modified.";
}
}
Expand Up @@ -333,6 +333,10 @@ public ApplicationEntity update(String applicationId, UpdateApplicationEntity up
throw new ApplicationNotFoundException(applicationId);
}

if (optApplicationToUpdate.get().getStatus().equals(ApplicationStatus.ARCHIVED)) {
throw new ApplicationArchivedException(optApplicationToUpdate.get().getName());
}

// Check that only one settings is defined
if (updateApplicationEntity.getSettings().getApp() != null && updateApplicationEntity.getSettings().getoAuthClient() != null) {
throw new InvalidApplicationTypeException();
Expand Down Expand Up @@ -431,6 +435,10 @@ public ApplicationEntity renewClientSecret(String applicationId) {
throw new ApplicationNotFoundException(applicationId);
}

if (ApplicationStatus.ARCHIVED.equals(optApplicationToUpdate.get().getStatus())) {
throw new ApplicationArchivedException(optApplicationToUpdate.get().getName());
}

// Check that client registration is enabled
checkClientRegistrationEnabled();

Expand Down
Expand Up @@ -32,6 +32,7 @@
import io.gravitee.repository.management.api.SubscriptionRepository;
import io.gravitee.repository.management.api.search.SubscriptionCriteria;
import io.gravitee.repository.management.api.search.builder.PageableBuilder;
import io.gravitee.repository.management.model.ApplicationStatus;
import io.gravitee.repository.management.model.ApplicationType;
import io.gravitee.repository.management.model.Audit;
import io.gravitee.repository.management.model.Subscription;
Expand Down Expand Up @@ -185,6 +186,9 @@ public SubscriptionEntity create(NewSubscriptionEntity newSubscriptionEntity) {
}

ApplicationEntity applicationEntity = applicationService.findById(application);
if (ApplicationStatus.ARCHIVED.name().equals(applicationEntity.getStatus())) {
throw new ApplicationArchivedException(applicationEntity.getName());
}

// Check existing subscriptions
List<Subscription> subscriptions = subscriptionRepository.search(
Expand Down

0 comments on commit e234dc5

Please sign in to comment.