View Javadoc
1   package io.oasp.module.security.common.api.accesscontrol;
2   
3   import java.io.Serializable;
4   import java.util.Objects;
5   
6   import javax.xml.bind.annotation.XmlAccessType;
7   import javax.xml.bind.annotation.XmlAccessorType;
8   import javax.xml.bind.annotation.XmlAttribute;
9   import javax.xml.bind.annotation.XmlID;
10  import javax.xml.bind.annotation.XmlSchemaType;
11  import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
12  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
13  
14  /**
15   * This is the abstract base class for a node of the {@link AccessControlSchema} that represents a tree of
16   * {@link AccessControlGroup}s and {@link AccessControlPermission}s. If a {@link java.security.Principal} "has" a
17   * {@link AccessControl} he also "has" all {@link AccessControl}s with according permissions in the spanned sub-tree.
18   *
19   * @author hohwille
20   */
21  @XmlAccessorType(XmlAccessType.FIELD)
22  public abstract class AccessControl implements Serializable {
23  
24    /** UID for serialization. */
25    private static final long serialVersionUID = 1L;
26  
27    /** @see #getName() */
28    @XmlID
29    @XmlAttribute(name = "id", required = true)
30    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
31    @XmlSchemaType(name = "NCName")
32    private String id;
33  
34    /**
35     * The constructor.
36     */
37    public AccessControl() {
38  
39      super();
40    }
41  
42    /**
43     * The constructor.
44     *
45     * @param id the {@link #getId() ID}.
46     */
47    public AccessControl(String id) {
48  
49      super();
50      this.id = id;
51    }
52  
53    /**
54     * @return the unique identifier of this {@link AccessControl}. Has to be unique for all {@link AccessControl} in a
55     *         {@link AccessControlSchema}.
56     */
57    public String getId() {
58  
59      return this.id;
60    }
61  
62    /**
63     * @param id the new {@link #getId() id}.
64     */
65    public void setId(String id) {
66  
67      this.id = id;
68    }
69  
70    @Override
71    public int hashCode() {
72  
73      final int prime = 31;
74      int result = 1;
75      result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
76      return result;
77    }
78  
79    @Override
80    public boolean equals(Object obj) {
81  
82      if (this == obj) {
83        return true;
84      }
85      if (obj == null) {
86        return false;
87      }
88      if (getClass() != obj.getClass()) {
89        return false;
90      }
91      AccessControl other = (AccessControl) obj;
92      if (!Objects.equals(this.id, other.id)) {
93        return false;
94      }
95      return true;
96    }
97  
98    @Override
99    public String toString() {
100 
101     return this.id;
102   }
103 
104 }