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

io.gravitee.rest.api.service.MembershipService Maven / Gradle / Ivy

There is a newer version: 3.10.0
Show newest version
/**
 * 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.rest.api.service;

import io.gravitee.common.data.domain.Page;
import io.gravitee.rest.api.model.*;
import io.gravitee.rest.api.model.api.ApiEntity;
import io.gravitee.rest.api.model.common.Pageable;
import io.gravitee.rest.api.model.pagedresult.Metadata;
import io.gravitee.rest.api.model.permissions.RoleScope;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
 * @author GraviteeSource Team
 */
public interface MembershipService {
    MemberEntity addRoleToMemberOnReference(MembershipReference reference, MembershipMember member, MembershipRole role);
    MemberEntity addRoleToMemberOnReference(
        MembershipReferenceType referenceType,
        String referenceId,
        MembershipMemberType memberType,
        String memberId,
        String role
    );
    MemberEntity addRoleToMemberOnReference(
        MembershipReferenceType referenceType,
        String referenceId,
        MembershipMemberType memberType,
        String memberId,
        String role,
        String source
    );
    void deleteMembership(String membershipId);
    void deleteReference(MembershipReferenceType referenceType, String referenceId);
    void deleteReferenceMember(MembershipReferenceType referenceType, String referenceId, MembershipMemberType memberType, String memberId);
    List findUserMembership(MembershipReferenceType referenceType, String userId);
    List findUserMembershipBySource(MembershipReferenceType referenceType, String userId, String sourceId);
    Metadata findUserMembershipMetadata(List memberships, MembershipReferenceType type);
    Page getMembersByReference(MembershipReferenceType referenceType, String referenceId, Pageable pageable);
    Set getMembersByReference(MembershipReferenceType referenceType, String referenceId);
    Page getMembersByReference(MembershipReferenceType referenceType, String referenceId, String role, Pageable pageable);
    Set getMembersByReference(MembershipReferenceType referenceType, String referenceId, String role);
    Page getMembersByReferenceAndRole(
        MembershipReferenceType referenceType,
        String referenceId,
        String role,
        Pageable pageable
    );
    Set getMembersByReferenceAndRole(MembershipReferenceType referenceType, String referenceId, String role);
    Page getMembersByReferencesAndRole(
        MembershipReferenceType referenceType,
        List referenceIds,
        String role,
        Pageable pageable
    );
    Set getMembersByReferencesAndRole(MembershipReferenceType referenceType, List referenceIds, String role);
    Set getMembershipsByMember(MembershipMemberType memberType, String memberId);
    Set getMembershipsByMemberAndReference(
        MembershipMemberType memberType,
        String memberId,
        MembershipReferenceType referenceType
    );
    Set getMembershipsByMemberAndReferenceAndRole(
        MembershipMemberType memberType,
        String memberId,
        MembershipReferenceType referenceType,
        String role
    );
    Set getMembershipsByMembersAndReference(
        MembershipMemberType memberType,
        List membersId,
        MembershipReferenceType referenceType
    );
    Set getMembershipsByReference(MembershipReferenceType referenceType, String referenceId);
    Set getMembershipsByReferenceAndRole(MembershipReferenceType referenceType, String referenceId, String role);
    Set getMembershipsByReferencesAndRole(MembershipReferenceType referenceType, List referenceIds, String role);
    MembershipEntity getPrimaryOwner(MembershipReferenceType referenceType, String referenceId);
    Set getRoles(MembershipReferenceType referenceType, String referenceId, MembershipMemberType memberType, String memberId);
    MemberEntity getUserMember(MembershipReferenceType referenceType, String referenceId, String userId);
    Map getUserMemberPermissions(MembershipReferenceType referenceType, String referenceId, String userId);
    Map getUserMemberPermissions(ApiEntity api, String userId);
    Map getUserMemberPermissions(ApplicationEntity application, String userId);
    Map getUserMemberPermissions(GroupEntity group, String userId);
    Map getUserMemberPermissions(EnvironmentEntity environment, String userId);
    void removeRole(
        MembershipReferenceType referenceType,
        String referenceId,
        MembershipMemberType memberType,
        String memberId,
        String roleId
    );
    void removeRoleUsage(String oldRoleId, String newRoleId);
    void removeMemberMemberships(MembershipMemberType memberType, String memberId);
    void transferApiOwnership(String apiId, MembershipMember member, List newPrimaryOwnerRoles);
    void transferApplicationOwnership(String applicationId, MembershipMember member, List newPrimaryOwnerRoles);
    MemberEntity updateRoleToMemberOnReference(MembershipReference reference, MembershipMember member, MembershipRole role);
    List updateRolesToMemberOnReference(
        MembershipReference reference,
        MembershipMember member,
        Collection roles,
        String source,
        boolean notify
    );
    List updateRolesToMemberOnReferenceBySource(
        MembershipReference reference,
        MembershipMember member,
        Collection roles,
        String source
    );

    class MembershipReference {

        private final MembershipReferenceType type;
        private final String id;

        public MembershipReference(MembershipReferenceType type, String id) {
            this.type = type;
            this.id = id;
        }

        public MembershipReferenceType getType() {
            return type;
        }

        public String getId() {
            return id;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            MembershipReference that = (MembershipReference) o;

            if (type != that.type) return false;
            return id.equals(that.id);
        }

        @Override
        public int hashCode() {
            int result = type.hashCode();
            result = 31 * result + id.hashCode();
            return result;
        }

        @Override
        public String toString() {
            return "MembershipReference{" + "type=" + type + ", id='" + id + '\'' + '}';
        }
    }

    class MembershipMember {

        private final String memberId;
        private final String reference;
        private final MembershipMemberType memberType;

        public MembershipMember(String memberId, String reference, MembershipMemberType memberType) {
            this.memberId = memberId;
            this.reference = reference;
            this.memberType = memberType;
        }

        public String getMemberId() {
            return memberId;
        }

        public String getReference() {
            return reference;
        }

        public MembershipMemberType getMemberType() {
            return memberType;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            MembershipMember that = (MembershipMember) o;

            if (memberId != null ? !memberId.equals(that.memberId) : that.memberId != null) return false;
            return reference != null ? reference.equals(that.reference) : that.reference == null;
        }

        @Override
        public int hashCode() {
            int result = memberId != null ? memberId.hashCode() : 0;
            result = 31 * result + (reference != null ? reference.hashCode() : 0);
            return result;
        }

        @Override
        public String toString() {
            return (
                "MembershipMember{" +
                "memberId='" +
                memberId +
                '\'' +
                ", reference='" +
                reference +
                '\'' +
                ", memberType=" +
                memberType +
                '}'
            );
        }
    }

    class MembershipRole {

        private final RoleScope scope;
        private final String name;

        public MembershipRole(RoleScope scope, String name) {
            this.scope = scope;
            this.name = name;
        }

        public RoleScope getScope() {
            return scope;
        }

        public String getName() {
            return name;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            MembershipRole that = (MembershipRole) o;

            if (scope != that.scope) return false;
            return name.equals(that.name);
        }

        @Override
        public int hashCode() {
            int result = scope.hashCode();
            result = 31 * result + name.hashCode();
            return result;
        }

        @Override
        public String toString() {
            return "MembershipRole{" + "scope=" + scope + ", name='" + name + '\'' + '}';
        }
    }

    class Membership {

        final MembershipReference reference;
        final MembershipMember member;
        final MembershipRole role;
        String source;

        public Membership(MembershipReference reference, MembershipMember member, MembershipRole role) {
            this.reference = reference;
            this.member = member;
            this.role = role;
        }

        public MembershipReference getReference() {
            return reference;
        }

        public MembershipMember getMember() {
            return member;
        }

        public MembershipRole getRole() {
            return role;
        }

        public String getSource() {
            return source;
        }

        public void setSource(String source) {
            this.source = source;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy