01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity;
17:
18: import org.acegisecurity.context.SecurityContextHolder;
19:
20: /**
21: * Represents a secured object.
22: *
23: * @author Ben Alex
24: * @version $Id: TargetObject.java 1496 2006-05-23 13:38:33Z benalex $
25: */
26: public class TargetObject implements ITargetObject {
27: //~ Methods ========================================================================================================
28:
29: public Integer computeHashCode(String input) {
30: return new Integer(input.hashCode());
31: }
32:
33: public int countLength(String input) {
34: return input.length();
35: }
36:
37: /**
38: * Returns the lowercase string, followed by security environment information.
39: *
40: * @param input the message to make lowercase
41: *
42: * @return the lowercase message, a space, the <code>Authentication</code> class that was on the
43: * <code>SecurityContext</code> at the time of method invocation, and a boolean indicating if the
44: * <code>Authentication</code> object is authenticated or not
45: */
46: public String makeLowerCase(String input) {
47: Authentication auth = SecurityContextHolder.getContext()
48: .getAuthentication();
49:
50: if (auth == null) {
51: return input.toLowerCase() + " Authentication empty";
52: } else {
53: return input.toLowerCase() + " "
54: + auth.getClass().getName() + " "
55: + auth.isAuthenticated();
56: }
57: }
58:
59: /**
60: * Returns the uppercase string, followed by security environment information.
61: *
62: * @param input the message to make uppercase
63: *
64: * @return the uppercase message, a space, the <code>Authentication</code> class that was on the
65: * <code>SecurityContext</code> at the time of method invocation, and a boolean indicating if the
66: * <code>Authentication</code> object is authenticated or not
67: */
68: public String makeUpperCase(String input) {
69: Authentication auth = SecurityContextHolder.getContext()
70: .getAuthentication();
71:
72: return input.toUpperCase() + " " + auth.getClass().getName()
73: + " " + auth.isAuthenticated();
74: }
75:
76: /**
77: * Delegates through to the {@link #makeLowerCase(String)} method.
78: *
79: * @param input the message to be made lower-case
80: *
81: * @return DOCUMENT ME!
82: */
83: public String publicMakeLowerCase(String input) {
84: return this.makeLowerCase(input);
85: }
86: }
|