1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity;
17
18 import org.acegisecurity.context.SecurityContextHolder;
19
20
21 /***
22 * Represents a secured object.
23 *
24 * @author Ben Alex
25 * @version $Id: TargetObject.java,v 1.8 2005/11/17 00:55:47 benalex Exp $
26 */
27 public class TargetObject implements ITargetObject {
28
29
30 public Integer computeHashCode(String input) {
31 return new Integer(input.hashCode());
32 }
33
34 public int countLength(String input) {
35 return input.length();
36 }
37
38 /***
39 * Returns the lowercase string, followed by security environment
40 * information.
41 *
42 * @param input the message to make lowercase
43 *
44 * @return the lowercase message, a space, the <code>Authentication</code>
45 * class that was on the <code>SecurityContext</code> at the time
46 * of method invocation, and a boolean indicating if the
47 * <code>Authentication</code> object is authenticated or not
48 */
49 public String makeLowerCase(String input) {
50 Authentication auth = SecurityContextHolder.getContext()
51 .getAuthentication();
52
53 if (auth == null) {
54 return input.toLowerCase() + " Authentication empty";
55 } else {
56 return input.toLowerCase() + " " + auth.getClass().getName() + " "
57 + auth.isAuthenticated();
58 }
59 }
60
61 /***
62 * Returns the uppercase string, followed by security environment
63 * information.
64 *
65 * @param input the message to make uppercase
66 *
67 * @return the uppercase message, a space, the <code>Authentication</code>
68 * class that was on the <code>SecurityContext</code> at the time
69 * of method invocation, and a boolean indicating if the
70 * <code>Authentication</code> object is authenticated or not
71 */
72 public String makeUpperCase(String input) {
73 Authentication auth = SecurityContextHolder.getContext()
74 .getAuthentication();
75
76 return input.toUpperCase() + " " + auth.getClass().getName() + " "
77 + auth.isAuthenticated();
78 }
79
80 /***
81 * Delegates through to the {@link #makeLowerCase(String)} method.
82 *
83 * @param input the message to be made lower-case
84 *
85 */
86 public String publicMakeLowerCase(String input) {
87 return this.makeLowerCase(input);
88 }
89 }