Added Immutable AccessList Object.
git-svn-id: https://svn.apache.org/repos/asf/incubator/photark/trunk@949810 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/photark-security/src/main/java/org/apache/photark/security/authorization/AccessList.java b/photark-security/src/main/java/org/apache/photark/security/authorization/AccessList.java
new file mode 100644
index 0000000..d410fc0
--- /dev/null
+++ b/photark-security/src/main/java/org/apache/photark/security/authorization/AccessList.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.photark.security.authorization;
+
+import java.util.Collections;
+import java.util.List;
+
+
+/**
+ * Immutable AccessList Object responsible for storing permissions of the user.
+ *
+ */
+public class AccessList {
+ /** */
+ private String userId;
+ /** */
+ private List<String> permissions;
+
+
+ /**
+ *
+ * @param userId String
+ *
+ * @param permissions List<String>
+ */
+ public AccessList(String userId, List<String> permissions){
+ this.permissions = Collections.unmodifiableList(permissions);
+ this.userId = userId;
+ }
+
+
+ /**
+ *
+ * @return List<String>
+ */
+ public List<String> getPermissions(){
+ return permissions;
+ }
+
+
+ /**
+ *
+ * @return String
+ */
+ public String getUserId(){
+ return userId;
+ }
+
+
+ /**
+ *
+ */
+ public boolean equals(Object obj){
+ if(!(obj instanceof AccessList))
+ return false;
+
+ AccessList accessList = (AccessList)obj;
+ if(accessList.userId.equals(userId) && isPermissionsEqual(accessList.permissions))
+ return true;
+
+ return false;
+ }
+
+
+ /**
+ *
+ * @param permissionList List<String>
+ *
+ * @return boolean
+ */
+ private boolean isPermissionsEqual(List<String> permissionList){
+ if(permissionList != null && permissions != null){
+ if(permissionList.size() == permissions.size()){
+ for(String permission : permissionList){
+ if(!permissions.contains(permission))
+ return false;
+ }
+ return true;
+ }
+ else
+ return false;
+ }
+ return false;
+ }
+
+
+ /**
+ *
+ */
+ public int hashCode(){
+ int hash = 1;
+ hash = hash * 7 + userId == null ? 0 : userId.hashCode();
+ for(String permission : permissions){
+ hash = hash * 7 + (permission == null ? 0 : permission.hashCode());
+ }
+ return hash;
+ }
+}
\ No newline at end of file