incubator-photark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r949810 - /incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/AccessList.java
Date Mon, 31 May 2010 17:30:29 GMT
Author: avd
Date: Mon May 31 17:30:28 2010
New Revision: 949810

URL: http://svn.apache.org/viewvc?rev=949810&view=rev
Log:
Added Immutable AccessList Object.

Added:
    incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/AccessList.java

Added: incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/AccessList.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/AccessList.java?rev=949810&view=auto
==============================================================================
--- incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/AccessList.java
(added)
+++ incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/AccessList.java
Mon May 31 17:30:28 2010
@@ -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



Mime
View raw message