001package org.apache.archiva.redback.rbac.jpa.model; 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 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.archiva.redback.rbac.AbstractUserAssignment; 023import org.apache.archiva.redback.rbac.UserAssignment; 024 025import javax.persistence.CollectionTable; 026import javax.persistence.Column; 027import javax.persistence.ElementCollection; 028import javax.persistence.Entity; 029import javax.persistence.FetchType; 030import javax.persistence.Id; 031import javax.persistence.JoinColumn; 032import javax.persistence.OrderColumn; 033import javax.persistence.Table; 034import java.io.Serializable; 035import java.util.ArrayList; 036import java.util.Date; 037import java.util.List; 038 039/** 040 * Created by Martin Stockhammer <martin_s@apache.org> on 26.09.16. 041 */ 042@Entity 043@Table(name="SECURITY_USER_ASSIGNMENTS") 044public class JpaUserAssignment extends AbstractUserAssignment implements UserAssignment,Serializable { 045 046 047 @Id 048 @Column(name="PRINCIPAL") 049 private String principal; 050 @ElementCollection(fetch = FetchType.EAGER) 051 @Column(name="STRING_ELE") 052 @OrderColumn(name="INTEGER_IDX", nullable = false) 053 @CollectionTable( 054 name="SECURITY_USERASSIGNMENT_ROLENAMES", 055 joinColumns = { 056 @JoinColumn(name = "PRINCIPAL_OID", referencedColumnName = "PRINCIPAL", nullable = false) 057 } 058 ) 059 private List<String> roleIds = new ArrayList<>( ); 060 061 @Column(name="PERMANENT", nullable = false) 062 private Boolean permanent = false; 063 064 @Column(name="LAST_UPDATED") 065 private Date timestamp; 066 067 @Override 068 public String getPrincipal() { 069 return principal; 070 } 071 072 @Override 073 public List<String> getRoleNames( ) 074 { 075 return roleIds; 076 } 077 078 @Override 079 public void setPrincipal(String principal) { 080 this.principal = principal; 081 } 082 083 @Override 084 public void setRoleNames( List<String> roles ) 085 { 086 this.roleIds = roles; 087 } 088 089 @Override 090 public List<String> getRoleIds() { 091 return roleIds; 092 } 093 094 @Override 095 public void setRoleIds( List<String> roleIds ) { 096 this.roleIds = roleIds; 097 } 098 099 @Override 100 public boolean isPermanent() { 101 return permanent; 102 } 103 104 @Override 105 public void setPermanent(boolean permanent) { 106 this.permanent = permanent; 107 } 108 109 @Override 110 public boolean equals(Object o) { 111 if (this == o) return true; 112 if (o == null || getClass() != o.getClass()) return false; 113 114 JpaUserAssignment that = (JpaUserAssignment) o; 115 116 return principal.equals(that.principal); 117 118 } 119 120 @Override 121 public int hashCode() { 122 return principal.hashCode(); 123 } 124 125 126 public Date getTimestamp() { 127 return timestamp; 128 } 129 130 public void setTimestamp(Date timestamp) { 131 this.timestamp = timestamp; 132 } 133 134}