Search in sources :

Example 1 with ApplicationPermissionDAO

use of com.netflix.spinnaker.front50.model.application.ApplicationPermissionDAO in project front50 by spinnaker.

the class ApplicationPermissionsService method deleteApplicationPermission.

public void deleteApplicationPermission(@Nonnull String appName) {
    Permission oldPerm;
    try {
        oldPerm = applicationPermissionDAO().findById(appName);
    } catch (NotFoundException e) {
        // Nothing to see here, we're all done already.
        return;
    }
    performWrite(supportingEventListeners(Type.PRE_DELETE), supportingEventListeners(Type.POST_DELETE), (unused, newPerm) -> {
        applicationPermissionDAO().delete(appName);
        syncUsers(null, oldPerm);
        return newPerm;
    }, oldPerm, null);
}
Also used : Permission(com.netflix.spinnaker.front50.model.application.Application.Permission) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException)

Example 2 with ApplicationPermissionDAO

use of com.netflix.spinnaker.front50.model.application.ApplicationPermissionDAO in project front50 by spinnaker.

the class ApplicationPermissionsService method getAllApplicationPermissions.

public Set<Permission> getAllApplicationPermissions() {
    Map<String, Permission> actualPermissions = applicationPermissionDAO().all().stream().map(permission -> new SimpleEntry<>(permission.getName().toLowerCase(), permission)).collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue));
    applicationDAO.all().stream().filter(app -> !actualPermissions.containsKey(app.getName().toLowerCase())).forEach(app -> {
        Permission p = new Permission();
        p.setName(app.getName());
        p.setLastModified(-1L);
        p.setLastModifiedBy("auto-generated");
        actualPermissions.put(app.getName().toLowerCase(), p);
    });
    return new HashSet<>(actualPermissions.values());
}
Also used : ApplicationDAO(com.netflix.spinnaker.front50.model.application.ApplicationDAO) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) ApplicationPermissionEventListener(com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) FiatService(com.netflix.spinnaker.fiat.shared.FiatService) Type(com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener.Type) FiatClientConfigurationProperties(com.netflix.spinnaker.fiat.shared.FiatClientConfigurationProperties) ApplicationPermissionDAO(com.netflix.spinnaker.front50.model.application.ApplicationPermissionDAO) SimpleEntry(java.util.AbstractMap.SimpleEntry) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) FiatConfigurationProperties(com.netflix.spinnaker.front50.config.FiatConfigurationProperties) Collection(java.util.Collection) Set(java.util.Set) Permission(com.netflix.spinnaker.front50.model.application.Application.Permission) Collectors(java.util.stream.Collectors) SystemException(com.netflix.spinnaker.kork.exceptions.SystemException) Permissions(com.netflix.spinnaker.fiat.model.resources.Permissions) List(java.util.List) Component(org.springframework.stereotype.Component) RetrofitError(retrofit.RetrofitError) Optional(java.util.Optional) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) SimpleEntry(java.util.AbstractMap.SimpleEntry) Permission(com.netflix.spinnaker.front50.model.application.Application.Permission) HashSet(java.util.HashSet)

Example 3 with ApplicationPermissionDAO

use of com.netflix.spinnaker.front50.model.application.ApplicationPermissionDAO in project front50 by spinnaker.

the class GcsConfig method applicationPermissionDAO.

@Bean
public ApplicationPermissionDAO applicationPermissionDAO(Storage storage, StorageServiceConfigurationProperties storageServiceConfigurationProperties, Registry registry, CircuitBreakerRegistry circuitBreakerRegistry, GcsProperties gcsProperties) {
    GcsStorageService service = googleCloudStorageService(storage, APPLICATION_PERMISSION_DATA_FILENAME, gcsProperties);
    ObjectKeyLoader keyLoader = new DefaultObjectKeyLoader(service);
    return new DefaultApplicationPermissionDAO(service, Schedulers.from(Executors.newFixedThreadPool(storageServiceConfigurationProperties.getApplicationPermission().getThreadPool())), keyLoader, storageServiceConfigurationProperties.getApplicationPermission().getRefreshMs(), storageServiceConfigurationProperties.getApplicationPermission().getShouldWarmCache(), registry, circuitBreakerRegistry);
}
Also used : DefaultObjectKeyLoader(com.netflix.spinnaker.front50.model.DefaultObjectKeyLoader) DefaultObjectKeyLoader(com.netflix.spinnaker.front50.model.DefaultObjectKeyLoader) ObjectKeyLoader(com.netflix.spinnaker.front50.model.ObjectKeyLoader) DefaultApplicationPermissionDAO(com.netflix.spinnaker.front50.model.application.DefaultApplicationPermissionDAO) GcsStorageService(com.netflix.spinnaker.front50.model.GcsStorageService) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with ApplicationPermissionDAO

use of com.netflix.spinnaker.front50.model.application.ApplicationPermissionDAO in project front50 by spinnaker.

the class ApplicationPermissionsService method createApplicationPermission.

public Permission createApplicationPermission(@Nonnull Permission newPermission) {
    return performWrite(supportingEventListeners(Type.PRE_CREATE), supportingEventListeners(Type.POST_CREATE), (unused, newPerm) -> {
        Permission perm = applicationPermissionDAO().create(newPerm.getId(), newPerm);
        syncUsers(perm, null);
        return perm;
    }, null, newPermission);
}
Also used : Permission(com.netflix.spinnaker.front50.model.application.Application.Permission)

Example 5 with ApplicationPermissionDAO

use of com.netflix.spinnaker.front50.model.application.ApplicationPermissionDAO in project front50 by spinnaker.

the class ApplicationPermissionsService method update.

private Permission update(@Nonnull String appName, @Nonnull Permission newPermission) {
    try {
        Permission oldPerm = applicationPermissionDAO().findById(appName);
        applicationPermissionDAO().update(appName, newPermission);
        syncUsers(newPermission, oldPerm);
    } catch (NotFoundException e) {
        createApplicationPermission(newPermission);
    }
    return newPermission;
}
Also used : Permission(com.netflix.spinnaker.front50.model.application.Application.Permission) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException)

Aggregations

Permission (com.netflix.spinnaker.front50.model.application.Application.Permission)4 NotFoundException (com.netflix.spinnaker.kork.web.exceptions.NotFoundException)3 Permissions (com.netflix.spinnaker.fiat.model.resources.Permissions)1 FiatClientConfigurationProperties (com.netflix.spinnaker.fiat.shared.FiatClientConfigurationProperties)1 FiatService (com.netflix.spinnaker.fiat.shared.FiatService)1 FiatConfigurationProperties (com.netflix.spinnaker.front50.config.FiatConfigurationProperties)1 ApplicationPermissionEventListener (com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener)1 Type (com.netflix.spinnaker.front50.events.ApplicationPermissionEventListener.Type)1 DefaultObjectKeyLoader (com.netflix.spinnaker.front50.model.DefaultObjectKeyLoader)1 GcsStorageService (com.netflix.spinnaker.front50.model.GcsStorageService)1 ObjectKeyLoader (com.netflix.spinnaker.front50.model.ObjectKeyLoader)1 ApplicationDAO (com.netflix.spinnaker.front50.model.application.ApplicationDAO)1 ApplicationPermissionDAO (com.netflix.spinnaker.front50.model.application.ApplicationPermissionDAO)1 DefaultApplicationPermissionDAO (com.netflix.spinnaker.front50.model.application.DefaultApplicationPermissionDAO)1 SystemException (com.netflix.spinnaker.kork.exceptions.SystemException)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1