Skip to content

Commit a976c18

Browse files
author
chrisisbeef
committed
Fixes Issue 66
Removed System.out calls in code except where used in a Java process that can be launched from the command line.
1 parent 6977fff commit a976c18

7 files changed

Lines changed: 70 additions & 62 deletions

File tree

‎src/main/java/org/owasp/esapi/ESAPI.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,8 @@ public static void setSecurityConfiguration(
369369
if ( securityConfiguration != null ) {
370370
ESAPI.securityConfiguration = securityConfiguration;
371371
} else {
372-
// CHECKME: Alternately we could throw NullPointerException with meaningful message here.
373-
System.out.println("ESAPI.setSecurityConfiguration(): null passed in. Security configuration unchanged.");
374-
}
372+
throw new NullPointerException("ESAPI.setSecurityConfiguration(): null passed in. Security configuration unchanged.");
373+
}
375374
}
376375

377376
/**

‎src/main/java/org/owasp/esapi/PreparedString.java‎

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -136,50 +136,4 @@ public String toString() {
136136
}
137137
return sb.toString();
138138
}
139-
140-
141-
public static void main( String[] args ) {
142-
PreparedString ps1 = new PreparedString( "Test ? is ?", new HTMLEntityCodec() );
143-
ps1.set( 1, "[]<>;\"\'PreparedString" );
144-
ps1.set( 2, "cool" );
145-
System.out.println( ps1 );
146-
try {
147-
PreparedString ps2 = new PreparedString( "Test ? is ?", new HTMLEntityCodec() );
148-
ps2.set( 2, "cool" );
149-
System.out.println( ps2 );
150-
} catch( Exception e ) {
151-
e.printStackTrace();
152-
}
153-
154-
try {
155-
PreparedString ps3 = new PreparedString( "Test ? is ?", new HTMLEntityCodec() );
156-
ps3.set( 1, "[]<>;\"\'PreparedString" );
157-
ps3.set( 2, "cool" );
158-
ps3.set( 3, "cool" );
159-
System.out.println( ps3 );
160-
} catch( Exception e ) {
161-
e.printStackTrace();
162-
}
163-
164-
try {
165-
PreparedString ps4 = new PreparedString( "???", new HTMLEntityCodec() );
166-
ps4.set( 1, "1" );
167-
ps4.set( 2, "2" );
168-
ps4.set( 3, "3" );
169-
System.out.println( ps4 );
170-
} catch( Exception e ) {
171-
e.printStackTrace();
172-
}
173-
174-
try {
175-
PreparedString ps5 = new PreparedString( "??x", new HTMLEntityCodec() );
176-
ps5.set( 1, "1" );
177-
ps5.set( 2, "2" );
178-
System.out.println( ps5 );
179-
} catch( Exception e ) {
180-
e.printStackTrace();
181-
}
182-
183-
}
184-
185139
}

‎src/main/java/org/owasp/esapi/codecs/HashTrie.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,13 @@ Node<T> getNextNode(Character ch)
183183
* @param key The key being added.
184184
* @param pos The position in key that is being handled
185185
* at this level.
186-
* @param value The value for this key.
187186
*/
188187
T put(CharSequence key, int pos, T addValue)
189188
{
190189
Node<T> nextNode;
191190
Character ch;
192191
T old;
193192

194-
// System.out.println("add(key=" + key + ", pos=" + pos + ", value=" + value + ") key[pos]=" + (pos < key.length() ? key.charAt(pos) : '?'));
195193
if(key.length() == pos)
196194
{ // at terminating node
197195
old = value;

‎src/main/java/org/owasp/esapi/reference/FileBasedAuthenticator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ public synchronized void removeUser(String accountName) throws AuthenticationExc
663663
throw new AuthenticationAccountsException("Remove user failed", "Can't remove invalid accountName " + accountName);
664664
}
665665
userMap.remove(user.getAccountId());
666-
System.out.println("Removing user " + user.getAccountName());
666+
logger.info(Logger.SECURITY_SUCCESS, "Removing user " + user.getAccountName());
667667
passwordMap.remove(user);
668668
saveUsers();
669669
}

‎src/main/java/org/owasp/esapi/util/ObjFactory.java‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ public T make(String className, String typeName) throws ConfigurationException {
8383
}
8484

8585
Class<?> theClass = Class.forName(className);
86-
// System.out.println("DEBUG: class=" + className + ", typeName=" + typeName + ": Passed Class.forName()");
8786
obj = theClass.newInstance();
88-
// System.out.println("DEBUG: class=" + className + ", typeName=" + typeName + ": Passed Class.newInstance()");
8987

9088
return (T)obj; // Eclipse warning here if @SupressWarnings omitted.
9189

@@ -104,25 +102,23 @@ public T make(String className, String typeName) throws ConfigurationException {
104102
//
105103
// Good reference:
106104
// http://java.sun.com/docs/books/tutorial/reflect/member/ctorTrouble.html
105+
//
106+
// Issue 66 - Removed System.out calls as we are throwing an exception in each of these cases
107+
// anyhow.
107108
} catch( IllegalArgumentException ex ) {
108109
errMsg = ex.toString() + " " + typeName + " type name cannot be null or empty.";
109-
System.out.println(errMsg);
110110
throw new ConfigurationException(errMsg, ex);
111111
}catch ( ClassNotFoundException ex ) {
112112
errMsg = ex.toString() + " " + typeName + " class (" + className + ") must be in class path.";
113-
System.out.println(errMsg);
114113
throw new ConfigurationException(errMsg, ex);
115114
} catch( InstantiationException ex ) {
116115
errMsg = ex.toString() + " " + typeName + " class (" + className + ") must be concrete.";
117-
System.out.println(errMsg);
118116
throw new ConfigurationException(errMsg, ex);
119117
} catch( IllegalAccessException ex ) {
120118
errMsg = ex.toString() + " " + typeName + " class (" + className + ") must have a public, no-arg constructor.";
121-
System.out.println(errMsg);
122119
throw new ConfigurationException(errMsg, ex);
123120
} catch( ClassCastException ex ) {
124121
errMsg = ex.toString() + " " + typeName + " class (" + className + ") must be a subtype of T in ObjFactory<T>";
125-
System.out.println(errMsg);
126122
throw new ConfigurationException(errMsg, ex);
127123
} catch( Exception ex ) {
128124
// Because we are using reflection, we want to catch any checked or unchecked Exceptions and
@@ -135,7 +131,6 @@ public T make(String className, String typeName) throws ConfigurationException {
135131
// unaltered???
136132
//
137133
errMsg = ex.toString() + " " + typeName + " class (" + className + ") CTOR threw exception.";
138-
System.out.println(errMsg);
139134
throw new ConfigurationException(errMsg, ex);
140135
}
141136
}

‎src/main/java/org/owasp/esapi/waf/rules/BeanShellRule.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ public Action check(HttpServletRequest request,
9393

9494
} catch (EvalError e) {
9595
log(request,"Error running custom beanshell rule (" + id + ") - " + e.getMessage());
96-
e.printStackTrace();
97-
System.out.println(e.getScriptStackTrace());
9896
}
9997

10098
return new DoNothingAction();
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* OWASP Enterprise Security API (ESAPI)
3+
*
4+
* This file is part of the Open Web Application Security Project (OWASP)
5+
* Enterprise Security API (ESAPI) project. For details, please see
6+
* <a href="http://www.owasp.org/index.php/ESAPI">http://www.owasp.org/index.php/ESAPI</a>.
7+
*
8+
* Copyright (c) 2007 - The OWASP Foundation
9+
*
10+
* The ESAPI is published by OWASP under the BSD license. You should read and accept the
11+
* LICENSE before you use, modify, and/or redistribute this software.
12+
*
13+
* @author Jeff Williams <a href="http://www.aspectsecurity.com">Aspect Security</a>
14+
* @created 2009
15+
*/
16+
17+
package org.owasp.esapi;
18+
19+
import junit.framework.TestCase;
20+
import org.owasp.esapi.codecs.Codec;
21+
import org.owasp.esapi.codecs.HTMLEntityCodec;
22+
23+
public class PreparedStringTest extends TestCase {
24+
25+
private final static Codec htmlEntityCodec = new HTMLEntityCodec();
26+
27+
public void testPreparedString() {
28+
PreparedString ps1 = new PreparedString( "Test ? is ?", htmlEntityCodec );
29+
ps1.set( 1, "[]<>;\"\'PreparedString" );
30+
ps1.set( 2, "cool" );
31+
try {
32+
PreparedString ps2 = new PreparedString( "Test ? is ?", htmlEntityCodec );
33+
ps2.set( 2, "cool" );
34+
} catch( Exception e ) {
35+
fail(e.getMessage());
36+
}
37+
38+
try {
39+
PreparedString ps3 = new PreparedString( "Test ? is ?", htmlEntityCodec );
40+
ps3.set( 1, "[]<>;\"\'PreparedString" );
41+
ps3.set( 2, "cool" );
42+
ps3.set( 3, "cool" );
43+
} catch( Exception e ) {
44+
fail(e.getMessage());
45+
}
46+
47+
try {
48+
PreparedString ps4 = new PreparedString( "???", htmlEntityCodec );
49+
ps4.set( 1, "1" );
50+
ps4.set( 2, "2" );
51+
ps4.set( 3, "3" );
52+
} catch( Exception e ) {
53+
fail(e.getMessage());
54+
}
55+
56+
try {
57+
PreparedString ps5 = new PreparedString( "??x", htmlEntityCodec );
58+
ps5.set( 1, "1" );
59+
ps5.set( 2, "2" );
60+
} catch( Exception e ) {
61+
fail(e.getMessage());
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)