classes/hirondelle/web4j/security/PermittedCharactersImpl.java
author Tomas Zeman <tzeman@volny.cz>
Wed, 04 Dec 2013 17:00:31 +0100
changeset 0 3060119b1292
permissions -rw-r--r--
Imported web4j 4.10.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     1
package hirondelle.web4j.security;
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     2
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     3
/**
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     4
 Default implementation of {@link hirondelle.web4j.security.PermittedCharacters}.
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     5
 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     6
 <P>This class permits only those characters which return <tt>true</tt> for
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     7
 {@link Character#isValidCodePoint(int)}.
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     8
 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     9
 <P>Since {@link SafeText} already escapes a long list of special characters, those 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    10
 special characters are automatically safe for inclusion here.
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    11
 <em>That is, you can usually accept almost any special character, because 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    12
 <tt>SafeText</tt> already does so much escaping anyway.</em>
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    13
 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    14
 <P>Given the importance of this issue for web application security, however, 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    15
 WEB4J still allows you to define your own implementation of this interface, as 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    16
 desired. 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    17
 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    18
 <P>This is a very liberal implementation. Applications should consider replacing this 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    19
 implementation with something less liberal. For example, an alternate implementation 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    20
 might disallow carriage returns and line feeds, or might specify the characters of 
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    21
 some particular block of Unicode.
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    22
*/
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    23
public class PermittedCharactersImpl implements PermittedCharacters {
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    24
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    25
  /** See class comment. */
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    26
  public boolean isPermitted(int aCodePoint) {
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    27
    return Character.isValidCodePoint(aCodePoint);
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    28
  }
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    29
  
3060119b1292 Imported web4j 4.10.0
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    30
}