View Javadoc
1   /**
2    * Copyright 2014 Internet2
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /*
17    Copyright (C) 2004-2007 University Corporation for Advanced Internet Development, Inc.
18    Copyright (C) 2004-2007 The University Of Chicago
19  
20    Licensed under the Apache License, Version 2.0 (the "License");
21    you may not use this file except in compliance with the License.
22    You may obtain a copy of the License at
23  
24      http://www.apache.org/licenses/LICENSE-2.0
25  
26    Unless required by applicable law or agreed to in writing, software
27    distributed under the License is distributed on an "AS IS" BASIS,
28    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29    See the License for the specific language governing permissions and
30    limitations under the License.
31  */
32  
33  package edu.internet2.middleware.grouper.log;
34  
35  import org.apache.commons.lang.time.StopWatch;
36  import org.apache.commons.logging.Log;
37  
38  import edu.internet2.middleware.grouper.Composite;
39  import edu.internet2.middleware.grouper.Field;
40  import edu.internet2.middleware.grouper.GrouperSession;
41  import edu.internet2.middleware.grouper.internal.util.Quote;
42  import edu.internet2.middleware.grouper.misc.M;
43  import edu.internet2.middleware.grouper.privs.Privilege;
44  import edu.internet2.middleware.grouper.subj.SubjectHelper;
45  import edu.internet2.middleware.grouper.util.GrouperUtil;
46  import edu.internet2.middleware.subject.Subject;
47  
48  /** 
49   * Grouper API logging.
50   * <p/>
51   * @author  blair christensen.
52   * @version $Id: EventLog.java,v 1.10 2009-08-18 23:11:38 shilen Exp $
53   */
54  public class EventLog {
55  
56    private static final  Log                     LOG               = GrouperUtil.getLog(EventLog.class);
57  
58  
59    /**
60     * 
61     */
62    public EventLog() {
63      super();
64    } // protected EventLog()
65  
66  
67    // PROTECTED CLASS METHODS //
68  
69    /**
70     * @param s
71     * @param c
72     * @param sw
73     * @since 1.0
74     */
75    public void groupAddComposite(
76      GrouperSession s, Composite c, StopWatch sw
77    )
78    {
79      //note, no need for GrouperSession inverse of control
80      EventLog.info(
81        s
82        , 
83        M.COMP_ADD 
84        + Quote.single( c.internal_getOwnerName() )
85        + " type="  + Quote.single(c.getType().toString() )
86        + " left="  + Quote.single( c.internal_getLeftName() )
87        + " right=" + Quote.single( c.internal_getRightName() )
88        ,
89        sw
90      );
91    } // protected void groupAddComposite(s, c, sw)
92  
93    /**
94     * @param s
95     * @param c
96     * @param sw
97     * @since 1.0
98     */
99    public void groupDelComposite(
100     GrouperSession s, Composite c, StopWatch sw
101   )
102   {
103     EventLog.info(
104       s
105       , 
106       M.COMP_DEL 
107       + Quote.single( c.internal_getOwnerName() )
108       + " type="  + Quote.single(c.getType().toString()  )
109       + " left="  + Quote.single( c.internal_getLeftName() )
110       + " right=" + Quote.single( c.internal_getRightName() )
111       ,
112       sw
113     );
114     /*this.groupAddAndDelCompositeMembers(
115       s, c, mof.getSaves(), mof.getDeletes(), sw
116     );*/
117   } // protected void groupDelComposite(s, c, mof, sw)
118 
119   /**
120    * @since 1.0
121    * @param msg
122    */
123   public static void info(String msg) {
124     LOG.info(msg);
125   } // protected static void info(msg)
126 
127   /**
128    * @since 1.0
129    * @param s
130    * @param msg
131    */
132   public static void info(GrouperSession s, String msg) {
133     LOG.info(LogHelper.internal_formatSession(s) + msg);
134   } // protected static void info(s, msg)
135 
136   /**
137    * @since 1.0
138    * @param s
139    * @param msg
140    * @param sw
141    */
142   public static void info(GrouperSession s, String msg, StopWatch sw) {
143     EventLog.info(s.toString(), msg, sw);
144   } // protected static void info(log, sessionToString, msg, sw)
145 
146   /**
147    * @since 1.0
148    * @param sessionToString
149    * @param msg
150    * @param sw
151    */
152   public static void info(
153     String sessionToString, String msg, StopWatch sw
154   ) 
155   {
156     LOG.info(
157       LogHelper.internal_formatSession(sessionToString) + msg + LogHelper.internal_formatStopWatch(sw)
158     );
159   } // protected static void info(log, sessionToString, msg, sw)
160 
161 
162   // PROTECTED INSTANCE METHODS //
163 
164   /**
165    * @param s 
166    * @param group 
167    * @param subj 
168    * @param f 
169    * @param sw 
170    * 
171    */
172   public void groupAddMember(
173     GrouperSession s, String group, Subject subj, Field f, StopWatch sw
174   )
175   {
176     this._member(s, M.G_AM, group, subj, f, sw);
177   } // protected void groupAddMember(s, group, subj, f, sw)
178 
179   /**
180    * @param s
181    * @param group
182    * @param attr
183    * @param val
184    * @param sw
185    */
186   public void groupDelAttr(
187     GrouperSession s, String group, String attr, String val, StopWatch sw
188   )
189   {
190     this._setAttr(s, M.G_DA, group, attr, val, sw);
191   } // protected void groupDelAttr(s, group, attr, val, sw);
192 
193   /**
194    * @param s
195    * @param group
196    * @param subj
197    * @param f
198    * @param sw
199    */
200   public void groupDelMember(
201     GrouperSession s, String group, Subject subj, Field f, StopWatch sw
202   ) {
203     this._member(s, M.G_DM, group, subj, f, sw);
204   } // protected void groupDelMember(s, group, subj, f, sw)
205 
206   /**
207    * @param s
208    * @param group
209    * @param subj
210    * @param p
211    * @param sw
212    */
213   public void groupGrantPriv(
214     GrouperSession s, String group, Subject subj, Privilege p, StopWatch sw
215   ) {
216     this._grantPriv(s, M.G_GP, group, subj, p, sw);
217   } // protected void groupGrantPriv(s, group, subj, p, sw)
218 
219   /**
220    * @param s
221    * @param group
222    * @param p
223    * @param sw
224    */
225   public void groupRevokePriv(
226     GrouperSession s, String group, Privilege p, StopWatch sw
227   ) 
228   {
229     this._revokePriv(s, M.G_RP, group, p, sw);
230   } // protected void groupRevokePriv(s, group, p, sw)
231 
232   /**
233    * @param s
234    * @param group
235    * @param subj
236    * @param p
237    * @param sw
238    */
239   public void groupRevokePriv(
240     GrouperSession s, String group, Subject subj, Privilege p, StopWatch sw
241   ) 
242   {
243     this._revokePriv(s, M.G_RP, group, subj, p, sw);
244   } // protected void groupRevokePriv(s, group, subj, p, sw)
245 
246   /**
247    * @param s
248    * @param group
249    * @param attr
250    * @param val
251    * @param sw
252    */
253   public void groupSetAttr(
254     GrouperSession s, String group, String attr, String val, StopWatch sw
255   )
256   {
257     this._setAttr(s, M.G_SA, group, attr, val, sw);
258   } // protected void groupSetAttr(s, group, attr, val, sw);
259 
260   /**
261    * @param s
262    * @param stem
263    * @param subj
264    * @param p
265    * @param sw
266    */
267   public void stemGrantPriv(
268     GrouperSession s, String stem, Subject subj, Privilege p, StopWatch sw
269   )
270   {
271     this._grantPriv(s, M.S_GP, stem, subj, p, sw);
272   } // protected void stemGrantPriv(s, stem, subj, p, sw)
273 
274   /**
275    * @param s
276    * @param stem
277    * @param p
278    * @param sw
279    */
280   public void stemRevokePriv(
281     GrouperSession s, String stem, Privilege p, StopWatch sw
282   ) 
283   {
284     this._revokePriv(s, M.S_RP, stem, p, sw);
285   } // protected void stemRevokePriv(s, stem, p, sw)
286 
287   /**
288    * @param s
289    * @param stem
290    * @param subj
291    * @param p
292    * @param sw
293    */
294   public void stemRevokePriv(
295     GrouperSession s, String stem, Subject subj, Privilege p, StopWatch sw
296   ) 
297   {
298     this._revokePriv(s, M.S_RP, stem, subj, p, sw);
299   } // protected void stemRevokePriv(s, stem, subj, p, sw)
300 
301   /**
302    * @param s
303    * @param stem
304    * @param attr
305    * @param val
306    * @param sw
307    */
308   public void stemSetAttr(
309     GrouperSession s, String stem, String attr, String val, StopWatch sw
310   )
311   {
312     this._setAttr(s, M.S_SA, stem, attr, val, sw);
313   } // protected void stemSetAttr(s, stem, attr, val, sw);
314 
315 
316   // PRIVATE INSTANCE METHODS //
317 
318   private void _grantPriv(
319     GrouperSession s, String msg, String name, Subject subj, Privilege p, StopWatch sw
320   )
321   {
322     //note, no need for GrouperSession inverse of control
323     EventLog.info(
324       s,
325       msg + Quote.single(name) + " priv=" + Quote.single( p.getName() ) + " subject=" 
326       + SubjectHelper.getPretty(subj),
327       sw
328     );
329   } // private void _grantPriv(s, msg, name, subj, p, sw)
330 
331   private void _member(
332     GrouperSession s, String msg, String group, Subject subj, Field f, StopWatch sw
333   )
334   {
335     //note, no need for GrouperSession inverse of control
336     EventLog.info(
337       s,
338       msg + Quote.single(group) + " list=" + Quote.single( f.getName() ) + " subject=" 
339       + SubjectHelper.getPretty(subj),
340       sw
341     );
342   } // private void _member(s, msg, group, subj, f, sw)
343 
344   private void _revokePriv(
345     GrouperSession s, String msg, String name, Privilege p, StopWatch sw
346   )
347   {
348     //note, no need for GrouperSession inverse of control
349     EventLog.info(
350       s, msg + Quote.single(name) + " priv=" + Quote.single( p.getName() ), sw
351     );
352   } // private void _revokePriv(s, msg, name, p, sw)
353 
354   private void _revokePriv(
355     GrouperSession s, String msg, String name, Subject subj, Privilege p, StopWatch sw
356   )
357   {
358     //note, no need for GrouperSession inverse of control
359     EventLog.info(
360       s,
361       msg + Quote.single(name) + " priv=" + Quote.single( p.getName() ) + " subject=" 
362       + SubjectHelper.getPretty(subj),
363       sw
364     );
365   } // private void _revokePriv(s, msg, name, subj, p, sw)
366 
367   private void _setAttr(
368     GrouperSession s, String msg, String name, String attr, String val, StopWatch sw
369   )
370   {
371     EventLog.info(s, msg + Quote.single(name) + " attr=" + Quote.single(attr) + " value=" + Quote.single(val), sw);
372   } // private void _setAttr(s, msg, attr, val, sw)
373 }
374