All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.corbel.iam.eventbus.DomainPublicScopesNotPublishedEventHandler Maven / Gradle / Ivy

There is a newer version: 1.44.0
Show newest version
package io.corbel.iam.eventbus;

import io.corbel.event.DomainPublicScopesNotPublishedEvent;
import io.corbel.eventbus.EventHandler;
import io.corbel.iam.model.Domain;
import io.corbel.iam.model.Scope;
import io.corbel.iam.repository.DomainRepository;
import io.corbel.iam.service.ScopeService;
import io.corbel.lib.ws.auth.DefaultPublicAccessService;

import java.util.Collections;
import java.util.Set;

public class DomainPublicScopesNotPublishedEventHandler implements EventHandler {

    private final ScopeService scopeService;
    private final DomainRepository domainRepository;

    public DomainPublicScopesNotPublishedEventHandler(ScopeService scopeService, DomainRepository domainRepository) {
        this.scopeService = scopeService;
        this.domainRepository = domainRepository;
    }

    @Override
    public void handle(DomainPublicScopesNotPublishedEvent domainPublicScopesNotPublishedEvent) {
        Domain domain = domainRepository.findOne(domainPublicScopesNotPublishedEvent.getDomain());
        String key = domainPublicScopesNotPublishedEvent.getDomain() + DefaultPublicAccessService.PUBLIC_SCOPES_SUFFIX;

        Set publicScopes = domain != null ? scopeService.getScopes(domain.getPublicScopes()) : Collections.emptySet();
        scopeService.addAuthorizationRulesForPublicAccess(key, publicScopes);
    }

    @Override
    public Class getEventType() {
        return DomainPublicScopesNotPublishedEvent.class;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy