001package org.apache.archiva.redback.rest.api.model.v2;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020
021import io.swagger.v3.oas.annotations.media.Schema;
022
023import javax.xml.bind.annotation.XmlRootElement;
024import java.io.Serializable;
025import java.util.ArrayList;
026import java.util.List;
027
028/**
029 * @author Martin Stockhammer <martin_s@apache.org>
030 */
031@XmlRootElement(name="groupMapping")
032@Schema(name="GroupMap", description = "Mapping of a group to roles")
033public class GroupMapping implements Serializable
034{
035    private static final long serialVersionUID = 8327221676510149313L;
036
037    String groupName;
038    String uniqueGroupName;
039    List<String> roles;
040
041    public GroupMapping( )
042    {
043    }
044
045    public GroupMapping( String groupName, String uniqueGroupName, List<String> roles )
046    {
047        this.groupName = groupName;
048        this.uniqueGroupName = uniqueGroupName;
049        this.roles = roles;
050    }
051
052    @Schema(name="group_name", description = "The name of the mapped group")
053    public String getGroupName( )
054    {
055        return groupName;
056    }
057
058    public void setGroupName( String groupName )
059    {
060        this.groupName = groupName;
061    }
062
063    @Schema(name="unique_group_name", description = "The unique name of the mapped group. Dependent on the used repository backend.")
064    public String getUniqueGroupName( )
065    {
066        return uniqueGroupName;
067    }
068
069    public void setUniqueGroupName( String uniqueGroupName )
070    {
071        this.uniqueGroupName = uniqueGroupName;
072    }
073
074    @Schema(description = "The list of role ids mapped to this group")
075    public List<String> getRoles( )
076    {
077        return roles;
078    }
079
080    public void setRoles( List<String> roles )
081    {
082        this.roles = roles;
083    }
084
085    public void addRole(String role) {
086        if (roles==null) {
087            this.roles = new ArrayList<>( );
088        }
089        if (!this.roles.contains(role)) {
090            this.roles.add( role );
091        }
092    }
093}