1 23 24 package org.dbforms.config; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import org.dbforms.util.StringUtil; 30 31 import java.util.Vector ; 32 33 import javax.servlet.http.HttpServletRequest ; 34 35 36 37 44 public class GrantedPrivileges implements java.io.Serializable { 45 private static Log logCat = LogFactory.getLog(GrantedPrivileges.class 46 .getName()); 48 49 public static final int PRIVILEG_SELECT = 0; 50 51 52 public static final int PRIVILEG_INSERT = 1; 53 54 55 public static final int PRIVILEG_UPDATE = 2; 56 57 58 public static final int PRIVILEG_DELETE = 3; 59 private Vector [] grantedRoles; 60 61 64 public GrantedPrivileges() { 65 grantedRoles = new Vector [4]; 66 67 } 69 70 75 public void setDelete(String delete) { 76 logCat.info("delete"); 77 grantedRoles[PRIVILEG_DELETE] = StringUtil.splitString(delete, ",;~"); 78 } 79 80 81 86 public void setInsert(String insert) { 87 logCat.info("insert"); 88 grantedRoles[PRIVILEG_INSERT] = StringUtil.splitString(insert, ",;~"); 89 } 90 91 92 97 public void setSelect(String select) { 98 logCat.info("select"); 99 grantedRoles[PRIVILEG_SELECT] = StringUtil.splitString(select, ",;~"); 100 } 101 102 103 108 public void setUpdate(String update) { 109 logCat.info("update"); 110 grantedRoles[PRIVILEG_UPDATE] = StringUtil.splitString(update, ",;~"); 111 } 112 113 114 122 public boolean hasUserPrivileg(HttpServletRequest request, 123 int privileg) { 124 if (grantedRoles[privileg] == null) { 125 return true; } 127 128 for (int i = 0; i < grantedRoles[privileg].size(); i++) { 129 String aGrantedRole = (String ) grantedRoles[privileg].elementAt(i); 130 131 if (request.isUserInRole(aGrantedRole)) { 132 return true; } 134 } 135 136 return false; } 138 } 139 | Popular Tags |