001: /* Copyright 2001, 2002 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.security.provider;
007:
008: import org.jasig.portal.AuthorizationException;
009: import org.jasig.portal.security.IAuthorizationPrincipal;
010: import org.jasig.portal.security.IAuthorizationService;
011: import org.jasig.portal.security.IPermission;
012: import org.jasig.portal.security.IPermissionPolicy;
013:
014: /**
015: * @author Dan Ellentuck
016: * @version $Revision: 34771 $
017: */
018: public class AuthorizationPrincipalImpl implements
019: IAuthorizationPrincipal {
020: private java.lang.String key;
021: private java.lang.Class type;
022: private org.jasig.portal.security.IAuthorizationService authorizationService;
023: private java.lang.String principalString;
024:
025: /**
026: * Constructor for ReferenceAuthorizationPrincipal.
027: */
028: public AuthorizationPrincipalImpl(String newKey, Class newType) {
029: this (newKey, newType, null);
030: }
031:
032: /**
033: * Constructor for ReferenceAuthorizationPrincipal.
034: */
035: public AuthorizationPrincipalImpl(String newKey, Class newType,
036: IAuthorizationService authService) {
037: super ();
038: key = newKey;
039: type = newType;
040: authorizationService = authService;
041: initialize();
042: }
043:
044: /**
045: * Answers if this <code>IAuthorizationPrincipal</code> has permission to publish.
046: * @return boolean
047: * @exception AuthorizationException thrown when authorization information could not be retrieved.
048: */
049: public boolean canPublish()
050: throws org.jasig.portal.AuthorizationException {
051: return getAuthorizationService().canPrincipalPublish(this );
052: }
053:
054: /**
055: * Answers if this <code>IAuthorizationPrincipal</code> has permission to render this channel.
056: * @return boolean
057: * @param channelPublishId int - the Channel publish ID
058: * @exception AuthorizationException thrown when authorization information could not be retrieved.
059: */
060: public boolean canRender(int channelPublishId)
061: throws org.jasig.portal.AuthorizationException {
062: return getAuthorizationService().canPrincipalRender(this ,
063: channelPublishId);
064: }
065:
066: /**
067: * Answers if this <code>IAuthorizationPrincipal</code> has permission to subscribe to this channel.
068: * @return boolean
069: * @param channelPublishId int - the Channel publish ID
070: * @exception AuthorizationException thrown when authorization information could not be retrieved.
071: */
072: public boolean canSubscribe(int channelPublishId)
073: throws org.jasig.portal.AuthorizationException {
074: return getAuthorizationService().canPrincipalSubscribe(this ,
075: channelPublishId);
076: }
077:
078: /**
079: * Compares two objects for equality. Returns a boolean that indicates
080: * whether this object is equivalent to the specified object. This method
081: * is used when an object is stored in a hashtable.
082: * @param obj the Object to compare with
083: * @return true if these Objects are equal; false otherwise.
084: * @see java.util.Hashtable
085: */
086: public boolean equals(Object obj) {
087: if (obj == null)
088: return false;
089: if (obj == this )
090: return true;
091: if (!(obj instanceof IAuthorizationPrincipal))
092: return false;
093:
094: IAuthorizationPrincipal otherAP = (IAuthorizationPrincipal) obj;
095: return this .getKey().equals(otherAP.getKey())
096: && this .getType() == otherAP.getType();
097: }
098:
099: /**
100: * Returns the <code>IPermissions</code> for this <code>IAuthorizationPrincipal</code>, including
101: * inherited <code>IPermissions</code>.
102: *
103: * @return org.jasig.portal.security.IPermission[]
104: * @exception AuthorizationException indicates authorization information could not
105: * be retrieved.
106: */
107: public IPermission[] getAllPermissions()
108: throws AuthorizationException {
109: return getAllPermissions(null, null, null);
110: }
111:
112: /**
113: * Returns the <code>IPermissions</code> for this <code>IAuthorizationPrincipal</code> for the
114: * specified <code>owner</code>, <code>activity</code> and <code>target</code>. Inherited
115: * <code>IPermissions</code> are included. Null parameters are ignored, so
116: * <code>getPermissions(null, null, null)</code> should retrieve all <code>IPermissions</code>
117: * for an <code>IAuthorizationPrincipal</code>.
118: *
119: * @return org.jasig.portal.security.IPermission[]
120: * @param owner java.lang.String
121: * @param activity java.lang.String
122: * @param target java.lang.String
123: * @exception AuthorizationException indicates authorization information could not
124: * be retrieved.
125: */
126: public IPermission[] getAllPermissions(String owner,
127: String activity, String target)
128: throws AuthorizationException {
129: return getAuthorizationService().getAllPermissionsForPrincipal(
130: this , owner, activity, target);
131: }
132:
133: /**
134: * @return org.jasig.portal.security.IAuthorization
135: */
136: IAuthorizationService getAuthorizationService() {
137: return authorizationService;
138: }
139:
140: /**
141: * Return a Vector of IChannels.
142: * @return a <code>java.util.Vector</code> of IChannels
143: * @exception AuthorizationException indicates authorization information could not be retrieved.
144: */
145: public java.util.Vector getAuthorizedChannels()
146: throws org.jasig.portal.AuthorizationException {
147: return getAuthorizationService().getAuthorizedChannels(this );
148: }
149:
150: /**
151: * @return java.lang.String
152: */
153: public java.lang.String getKey() {
154: return key;
155: }
156:
157: /**
158: * Returns the <code>IPermissions</code> for this <code>IAuthorizationPrincipal</code>.
159: *
160: * @return org.jasig.portal.security.IPermission[]
161: * @exception AuthorizationException indicates authorization information could not
162: * be retrieved.
163: */
164: public IPermission[] getPermissions() throws AuthorizationException {
165: return getPermissions(null, null, null);
166: }
167:
168: /**
169: * Returns the <code>IPermissions</code> for this <code>IAuthorizationPrincipal</code> for the
170: * specified <code>owner</code>, <code>activity</code> and <code>target</code>. Null parameters
171: * are ignored, so <code>getPermissions(null, null, null)</code> should retrieve all
172: * <code>IPermissions</code> for an <code>IAuthorizationPrincipal</code>.
173: *
174: * @return org.jasig.portal.security.IPermission[]
175: * @param owner java.lang.String
176: * @param activity java.lang.String
177: * @param target java.lang.String
178: * @exception AuthorizationException indicates authorization information could not
179: * be retrieved.
180: */
181: public IPermission[] getPermissions(String owner, String activity,
182: String target) throws AuthorizationException {
183: return getAuthorizationService().getPermissionsForPrincipal(
184: this , owner, activity, target);
185: }
186:
187: /**
188: * @return java.lang.String
189: */
190: public String getPrincipalString() {
191: return principalString;
192: }
193:
194: /**
195: * @return java.lang.Class
196: */
197: public java.lang.Class getType() {
198: return type;
199: }
200:
201: /**
202: * Generates a hash code for the receiver.
203: * This method is supported primarily for
204: * hash tables, such as those provided in java.util.
205: * @return an integer hash code for the receiver
206: * @see java.util.Hashtable
207: */
208: public int hashCode() {
209: return getKey().hashCode() + getType().hashCode();
210: }
211:
212: /**
213: * Answers if this <code>IAuthorizationPrincipal</code> has permission to perform the
214: * <code>activity</code> on the <code>target</code>. Params <code>owner</code> and
215: * <code>activity</code> must be non-null. If <code>target</code> is null, then the
216: * target is not checked.
217: *
218: * @return boolean
219: * @param owner java.lang.String
220: * @param activity java.lang.String
221: * @param target java.lang.String
222: * @exception AuthorizationException indicates authorization information could not
223: * be retrieved.
224: */
225: public boolean hasPermission(String owner, String activity,
226: String target)
227: throws org.jasig.portal.AuthorizationException {
228: return getAuthorizationService().doesPrincipalHavePermission(
229: this , owner, activity, target);
230: }
231:
232: /**
233: * Set the value of the principal string.
234: */
235: private void initialize() {
236: principalString = getAuthorizationService().getPrincipalString(
237: this );
238: }
239:
240: /**
241: * @param newAuthorizationService org.jasig.portal.security.IAuthorizationService
242: */
243: void setAuthorizationService(
244: IAuthorizationService newAuthorizationService) {
245: authorizationService = newAuthorizationService;
246: }
247:
248: /**
249: * Returns a String that represents the value of this object.
250: * @return a string representation of the receiver
251: */
252: public String toString() {
253: return getPrincipalString();
254: }
255:
256: /**
257: * Answers if this <code>IAuthorizationPrincipal</code> has permission to perform the
258: * <code>activity</code> on the <code>target</code>, as evaluated by the
259: * <code>policy</code>. Params <code>policy</code>, <code>owner</code> and
260: * <code>activity</code> must be non-null.
261: *
262: * @return boolean
263: * @param owner java.lang.String
264: * @param activity java.lang.String
265: * @param target java.lang.String
266: * @param policy org.jasig.portal.security.IPermissionPolicy
267: * @exception AuthorizationException indicates authorization information could not
268: * be retrieved.
269: */
270: public boolean hasPermission(String owner, String activity,
271: String target, IPermissionPolicy policy)
272: throws AuthorizationException {
273: return getAuthorizationService().doesPrincipalHavePermission(
274: this, owner, activity, target, policy);
275: }
276: }
|