001package org.apache.archiva.redback.rest.api.model.v2; 002/* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 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; 022import org.apache.archiva.redback.rest.api.model.v2.Resource; 023 024import javax.xml.bind.annotation.XmlRootElement; 025import java.io.Serializable; 026 027/** 028 * @author Olivier Lamy 029 * @since 1.4 030 */ 031@XmlRootElement( name = "permission" ) 032@Schema(name="Permission", description = "Permission that allows operation on resources") 033public class Permission 034 implements Serializable 035{ 036 private static final long serialVersionUID = 4243488525173718059L; 037 private String name; 038 039 private String description; 040 041 private String descriptionKey; 042 043 private Operation operation; 044 045 private Resource resource; 046 047 private boolean permanent; 048 049 public Permission() 050 { 051 // no op 052 } 053 054 public Permission( org.apache.archiva.redback.rbac.Permission permission ) 055 { 056 this.name = permission.getName(); 057 this.description = permission.getDescription(); 058 this.operation = permission.getOperation() == null ? null : new Operation( permission.getOperation() ); 059 this.resource = permission.getResource() == null ? null : new Resource( permission.getResource() ); 060 this.permanent = permission.isPermanent(); 061 } 062 063 public static Permission of( org.apache.archiva.redback.rbac.Permission perm ) { 064 return new Permission( perm ); 065 } 066 067 @Schema(name="name", description = "The identifier of the permission") 068 public String getName() 069 { 070 return name; 071 } 072 073 public void setName( String name ) 074 { 075 this.name = name; 076 } 077 078 @Schema(name="operation", description = "The operation that is assigned to this permission") 079 public Operation getOperation() 080 { 081 return operation; 082 } 083 084 public void setOperation( Operation operation ) 085 { 086 this.operation = operation; 087 } 088 089 @Schema(name="resource", description = "The resource this permission applies to") 090 public Resource getResource() 091 { 092 return resource; 093 } 094 095 public void setResource( Resource resource ) 096 { 097 this.resource = resource; 098 } 099 100 @Override 101 public String toString() 102 { 103 final StringBuilder sb = new StringBuilder(); 104 sb.append( "Permission" ); 105 sb.append( "{name='" ).append( name ).append( '\'' ); 106 sb.append( ", description='" ).append( description ).append( '\'' ); 107 sb.append( ", operation=" ).append( operation ); 108 sb.append( ", resource=" ).append( resource ); 109 sb.append( ", permanent=" ).append( permanent ); 110 sb.append( '}' ); 111 return sb.toString(); 112 } 113 114 @Schema(name="description_key",description = "The language key for the description") 115 public String getDescriptionKey( ) 116 { 117 return descriptionKey; 118 } 119 120 public void setDescriptionKey( String descriptionKey ) 121 { 122 this.descriptionKey = descriptionKey; 123 } 124}