001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase.security;
011:
012: /**
013: * This class is a kind of enumeration (introduced before java 1.5 enumerations) of the operations
014: * possible within the security authorization.
015: * @author Eduard Witteveen
016: * @version $Id: Operation.java,v 1.13 2007/12/06 08:08:13 michiel Exp $
017: * @see Authorization
018: */
019: public final class Operation {
020: /** int value for the read Operation*/
021: public final static int READ_INT = 0;
022:
023: /** int value for the write Operation*/
024: public final static int WRITE_INT = 1;
025:
026: /** int value for the create Operation*/
027: public final static int CREATE_INT = 2;
028:
029: /** int value for the change relation Operation */
030: public final static int CHANGE_RELATION_INT = 3;
031:
032: /** int value for the remove Operation */
033: public final static int DELETE_INT = 4;
034:
035: /**
036: * int value for change context operation
037: * @since MMBase-1.7
038: */
039: public final static int CHANGE_CONTEXT_INT = 6;
040:
041: /**
042: * @deprecated use CHANGE_CONTEXT_INT
043: */
044: public final static int CHANGECONTEXT_INT = CHANGE_CONTEXT_INT;
045:
046: /**
047: * A 'read' operation is acquiring an MMBase Node. We have no field-level granularity for the
048: * authorization. Having a {@link org.mmbase.bridge.Node} means that you
049: */
050: public final static Operation READ = new Operation(READ_INT, "read");
051:
052: /**
053: * {@link Node#setValue} is an example of a write-operation.
054: */
055: public final static Operation WRITE = new Operation(WRITE_INT,
056: "write");
057:
058: /**
059: * Identifier for create operation, which is used for creating a new node.
060: * This only applies on NodeManagers (builders)
061: */
062: public final static Operation CREATE = new Operation(CREATE_INT,
063: "create");
064:
065: /**
066: * Identifier for changing the source and/or destination field of a
067: * relation.
068: */
069: public final static Operation CHANGE_RELATION = new Operation(
070: CHANGE_RELATION_INT, "change relation");
071:
072: /**
073: *Identifier for remove operation, which is used when removing a node */
074: public final static Operation DELETE = new Operation(DELETE_INT,
075: "delete");
076:
077: /**
078: * Identifier for change context operation, which is used when changing the context of a node
079: * @since MMBase-1.7
080: */
081: public final static Operation CHANGE_CONTEXT = new Operation(
082: CHANGE_CONTEXT_INT, "change context");
083:
084: /**
085: * Identifier for change context operation, which is used when changing the context of a node
086: * @deprecated Use CHANGE_CONTEXT
087: */
088: public final static Operation CHANGECONTEXT = CHANGE_CONTEXT;
089:
090: /**
091: * Private constructor, to prevent creation of new Operations
092: */
093: private Operation(int level, String description) {
094: this .level = level;
095: this .description = description;
096: }
097:
098: /**
099: * This method gives back the internal int value of the Operation,
100: * which can be used in switch statements
101: * @return the internal int value
102: */
103: public int getInt() {
104: return level;
105: }
106:
107: /**
108: * @return a string containing the description of the operation
109: */
110: public String toString() {
111: return description;
112: }
113:
114: /**
115: * the int value of the instance
116: */
117: private final int level;
118:
119: /**
120: * the description of this operation
121: */
122: private final String description;
123:
124: /** retrieve a Operation by a given string */
125: public static Operation getOperation(String operationString) {
126: if (READ.toString().equals(operationString))
127: return READ;
128: if (WRITE.toString().equals(operationString))
129: return WRITE;
130: if (CREATE.toString().equals(operationString))
131: return CREATE;
132: if (CHANGE_RELATION.toString().equals(operationString))
133: return CHANGE_RELATION;
134: if (DELETE.toString().equals(operationString))
135: return DELETE;
136: if (CHANGE_CONTEXT.toString().equals(operationString))
137: return CHANGE_CONTEXT;
138: throw new org.mmbase.security.SecurityException(
139: "Could not find a operation for the operation with name:"
140: + operationString);
141: }
142: }
|