Project

General

Profile

« Previous | Next » 

Revision 5104

handle multiple <principal> elements in the allow/deny blocks

View differences:

src/edu/ucsb/nceas/metacat/DocInfoHandler.java
26 26

  
27 27
package edu.ucsb.nceas.metacat;
28 28

  
29
import java.util.Stack;
29 30
import java.util.Vector;
30 31
import java.util.Hashtable;
31 32

  
......
50 51
	private String _docId;
51 52
	private boolean _inPrincipal = false;
52 53
	private boolean _inPermission = false;
54
	private boolean _inAllow = false;
55
	private boolean _inDeny = false;
53 56
  
54 57
	private Vector<XMLAccessDAO> xmlAccessDAOList = new Vector<XMLAccessDAO>();
58
	private Stack<XMLAccessDAO> xmlAccessDAOStack = new Stack<XMLAccessDAO>();
55 59
  
56 60
	public DocInfoHandler() {
57 61
	}
......
70 74
			if (_accessPermOrder == null) {
71 75
				_accessPermOrder = attributes.getValue("order");			
72 76
			}
77
		} else if (_currentTag.equals(AccessControlInterface.ALLOW)) {
78
			_inAllow = true;
79
		} else if (_currentTag.equals(AccessControlInterface.DENY)) {
80
			_inDeny = true;
81
		} else if (_currentTag.equals(AccessControlInterface.PERMISSION)) {
82
			_inPermission = true;			
83
		} else if (_currentTag.equals(AccessControlInterface.PRINCIPAL)) {
84
			// new principal means new DAO for storing it
85
			_inPrincipal = true;
73 86
			_currentAccessDAO = new XMLAccessDAO();
74 87
			_currentAccessDAO.setDocId(_docId);
75 88
			_currentAccessDAO.setPermOrder(_accessPermOrder);
76
		} else if (_currentTag.equals(AccessControlInterface.PRINCIPAL)) {
77
			_inPrincipal = true;
78
		} else if (_currentTag.equals(AccessControlInterface.PERMISSION)) {
79
			_inPermission = true;
89
			if (_inAllow) {
90
				_currentAccessDAO.setPermType(AccessControlInterface.ALLOW);
91
			}
92
			if (_inDeny) {
93
				_currentAccessDAO.setPermType(AccessControlInterface.DENY);
94
			}
80 95
		}
81 96
	}
82 97

  
83 98
	public void endElement(String uri, String localName, String qName)
84 99
			throws SAXException {
85
		if (localName.equals("access")) {			
86
			if (_currentAccessDAO != null) {
87
				xmlAccessDAOList.add(_currentAccessDAO);
88
			}			
89
			_currentAccessDAO = null;
90
		} else if (qName.equals(AccessControlInterface.ALLOW)) {
91
			if (_currentAccessDAO != null) {
92
				_currentAccessDAO.setPermType(AccessControlInterface.ALLOW);
93
			}
94
		} else if (qName.equals(AccessControlInterface.DENY)) {
95
			if (_currentAccessDAO != null) {
96
				_currentAccessDAO.setPermType(AccessControlInterface.DENY);
97
			}
100
		
101
		if (localName.equals(AccessControlInterface.ALLOW)) {
102
			_inAllow = false;
103
		} else if (localName.equals(AccessControlInterface.DENY)) {
104
			_inDeny = false;
98 105
		} else if (_currentTag.equals(AccessControlInterface.PRINCIPAL)) {
99 106
			_inPrincipal = false;
107
			xmlAccessDAOStack.push(_currentAccessDAO);
100 108
		} else if (_currentTag.equals(AccessControlInterface.PERMISSION)) {
101 109
			_inPermission = false;
102 110
		}
111
		//end of a section for allow/deny
112
		if (
113
			localName.equals(AccessControlInterface.ALLOW)
114
			||
115
			localName.equals(AccessControlInterface.DENY)
116
			) {
117
			//get all the DAOs for this section and add them to the overall list
118
			xmlAccessDAOList.addAll(xmlAccessDAOStack);
119
			xmlAccessDAOStack.clear();
120
		}
103 121
	}
104 122
  
105 123
  /**
......
118 136
		if (_currentAccessDAO != null) {
119 137
			String permString = new String(ch, start, length);
120 138
			Long permLong = Long.valueOf(AccessControlList.intValue(permString));
121
			_currentAccessDAO.addPermission(permLong);
139
			//add this permission for each DAO in the stack
140
			for (int i = 0; i < xmlAccessDAOStack.size(); i++) {
141
				xmlAccessDAOStack.get(i).addPermission(permLong);
142
			}
122 143
		}
123 144
	}
124 145
  }

Also available in: Unified diff