001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.core.impl.model.portal;
023:
024: import java.io.Serializable;
025: import java.util.HashSet;
026: import java.util.Iterator;
027: import java.util.Set;
028:
029: /**
030: * Binds a role and a set of actions together. This object is immutable. <p>A portal resource (portal, page, window,
031: * instance, portlet...) is secured via a set of security constraints. each security constraint holds the information
032: * about what roles are allowed what actions.</p>
033: *
034: * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>
035: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
036: * @version $Revision: 8786 $
037: */
038: public final class ObjectNodeSecurityConstraint implements Serializable {
039: /** The serialVersionUID */
040: private static final long serialVersionUID = -4506735776282080236L;
041:
042: private long id;
043:
044: /** The role of this contraint. */
045: private String role;
046:
047: /** The set of actions of this constraint. */
048: private Set actions;
049:
050: /** The cached toString value. */
051: private transient String toString;
052:
053: /** The ObjectNode to which this security constraint is attached to . */
054: private ObjectNode objectNode;
055:
056: public ObjectNodeSecurityConstraint() {
057: }
058:
059: /**
060: * Create a new constraint with the provided actions and the specified role.
061: *
062: * @param actions the set of actions
063: * @param role the role name
064: */
065: public ObjectNodeSecurityConstraint(Set actions, String role) {
066: if (role == null) {
067: throw new IllegalArgumentException("Role cannot be null");
068: }
069: if (actions == null) {
070: throw new IllegalArgumentException("Actions cannot be null");
071: }
072:
073: //
074: this .role = role;
075: this .actions = new HashSet(actions);
076: }
077:
078: /**
079: * Return a <code>java.util.Set<String></code> of allowed actions.
080: *
081: * @return the action set
082: */
083: public Set getActions() {
084: return actions;
085: }
086:
087: public void setActions(Set actions) {
088: this .actions = actions;
089: }
090:
091: /**
092: * Return the role of this constraint
093: *
094: * @return the role
095: */
096: public String getRole() {
097: return role;
098: }
099:
100: public void setRole(String role) {
101: this .role = role;
102: }
103:
104: public ObjectNode getObjectNode() {
105: return objectNode;
106: }
107:
108: public void setObjectNode(ObjectNode objectNode) {
109: this .objectNode = objectNode;
110: }
111:
112: protected void setKey(long key) {
113: id = key;
114: }
115:
116: protected long getKey() {
117: return id;
118: }
119:
120: /** @see Object#toString */
121: public String toString() {
122: if (toString == null) {
123: StringBuffer tmp = new StringBuffer(
124: "SecurityConstraint: actions [");
125: for (Iterator i = actions.iterator(); i.hasNext();) {
126: String action = (String) i.next();
127: if (i.hasNext()) {
128: tmp.append(", ");
129: }
130: tmp.append(action);
131: }
132: tmp.append("] role [").append(role).append("]");
133: toString = tmp.toString();
134: }
135: return toString;
136: }
137: }
|