001: /*
002: * This program is free software; you can redistribute it and/or modify
003: * it under the terms of the GNU General Public License as published by
004: * the Free Software Foundation; either version 2 of the License, or
005: * (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU Library General Public License for more details.
011: *
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015: */
016: package web.security.impl;
017:
018: import java.io.Serializable;
019: import java.util.List;
020: import java.util.Vector;
021:
022: import web.security.Privilege;
023: import web.security.Role;
024:
025: /**
026: * 角色的实现类
027: * @author liudong
028: */
029: public class RoleImpl implements Role, Serializable {
030:
031: protected List privileges;
032: protected String name;
033: protected String desc;
034:
035: public RoleImpl() {
036: this (null, null);
037: }
038:
039: public RoleImpl(String name, String desc) {
040: this .name = name;
041: this .desc = desc;
042: this .privileges = new Vector();
043: }
044:
045: /* (non-Javadoc)
046: * @see com.clickcom.web.security.Role#privileges()
047: */
048: public Privilege[] privileges() {
049: if (privileges == null)
050: return null;
051: return (Privilege[]) privileges
052: .toArray(new Privilege[privileges.size()]);
053: }
054:
055: /* (non-Javadoc)
056: * @see com.clickcom.web.security.Role#canDo(com.clickcom.web.security.Privilege)
057: */
058: public boolean canDo(Privilege pvg) {
059: for (int i = 0; privileges != null && i < privileges.size(); i++) {
060: Privilege p = (Privilege) privileges.get(i);
061: boolean bEqual = p.equals(pvg);
062: //System.out.println(getClass().getName()+"("+name+"): " + p.getResource()+","+p.getOperation()+","+p.getRange()+","+bEqual);
063: if (bEqual)
064: return true;
065: break;
066: }
067: return false;
068: }
069:
070: /* (non-Javadoc)
071: * @see com.clickcom.web.security.Role#getName()
072: */
073: public String getName() {
074: return name;
075: }
076:
077: /* (non-Javadoc)
078: * @see com.clickcom.web.security.Role#getDesc()
079: */
080: public String getDesc() {
081: return desc;
082: }
083:
084: public void setDesc(String desc) {
085: this .desc = desc;
086: }
087:
088: public void setName(String name) {
089: this .name = name;
090: }
091:
092: public List getPrivileges() {
093: return privileges;
094: }
095:
096: public void setPrivileges(List privileges) {
097: this .privileges = privileges;
098: }
099:
100: public String toString() {
101: return "ROLE:(" + name + ',' + desc + ')';
102: }
103: }
|