From ab34ca05de9960f102809baae38dcd3c1ba4ce2e Mon Sep 17 00:00:00 2001 From: maxcooper Date: Mon, 9 Jun 2003 10:59:42 +0000 Subject: [PATCH] added Constants class to facilitate testing the example app --- .../org/securityfilter/example/Constants.java | 81 ++++++++++++++++++++++ .../example/TrivialSecurityRealm.java | 17 ++--- web/share/loginForm.jsp | 31 +++++++-- web/share/securePage.jsp | 15 ++-- 4 files changed, 124 insertions(+), 20 deletions(-) create mode 100644 src/example/org/securityfilter/example/Constants.java diff --git a/src/example/org/securityfilter/example/Constants.java b/src/example/org/securityfilter/example/Constants.java new file mode 100644 index 0000000..024ef14 --- /dev/null +++ b/src/example/org/securityfilter/example/Constants.java @@ -0,0 +1,81 @@ +/* + * $Header: /cvsroot/securityfilter/securityfilter/src/example/org/securityfilter/example/Constants.java,v 1.1 2003/06/09 10:59:42 maxcooper Exp $ + * $Revision: 1.1 $ + * $Date: 2003/06/09 10:59:42 $ + * + * ==================================================================== + * The SecurityFilter Software License, Version 1.1 + * + * (this license is derived and fully compatible with the Apache Software + * License - see http://www.apache.org/LICENSE.txt) + * + * Copyright (c) 2002 SecurityFilter.org. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by + * SecurityFilter.org (http://www.securityfilter.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The name "SecurityFilter" must not be used to endorse or promote + * products derived from this software without prior written permission. + * For written permission, please contact license@securityfilter.org . + * + * 5. Products derived from this software may not be called "SecurityFilter", + * nor may "SecurityFilter" appear in their name, without prior written + * permission of SecurityFilter.org. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE SECURITY FILTER PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + */ + +package org.securityfilter.example; + +/** + * Constants - constants for the example applications to facilitate testing + * + * @author Max Cooper (max@maxcooper.com) + * @version $Revision: 1.1 $ $Date: 2003/06/09 10:59:42 $ + */ +public interface Constants { + + // shared constants + public static final String COMMON_TITLE_BASE = "SecurityFilter Example Application: "; + public static final String VALID_USERNAME = "username"; + public static final String VALID_PASSWORD = "password"; + public static final String VALID_ROLE = "inthisrole"; + + // login form constants + public static final String LOGIN_TITLE = COMMON_TITLE_BASE + "Login Page"; + public static final String LOGIN_FORM_ID = "login"; + public static final String LOGIN_FORM_ACTION = "j_security_check"; + public static final String LOGIN_USERNAME_FIELD = "j_username"; + public static final String LOGIN_PASSWORD_FIELD = "j_password"; + + // secure page constants + public static final String SECURE_TITLE = COMMON_TITLE_BASE + "Secure Page"; +} diff --git a/src/example/org/securityfilter/example/TrivialSecurityRealm.java b/src/example/org/securityfilter/example/TrivialSecurityRealm.java index 26f90b7..25bf409 100644 --- a/src/example/org/securityfilter/example/TrivialSecurityRealm.java +++ b/src/example/org/securityfilter/example/TrivialSecurityRealm.java @@ -1,7 +1,7 @@ /* - * $Header: /cvsroot/securityfilter/securityfilter/src/example/org/securityfilter/example/Attic/TrivialSecurityRealm.java,v 1.7 2003/02/07 11:17:23 maxcooper Exp $ - * $Revision: 1.7 $ - * $Date: 2003/02/07 11:17:23 $ + * $Header: /cvsroot/securityfilter/securityfilter/src/example/org/securityfilter/example/Attic/TrivialSecurityRealm.java,v 1.8 2003/06/09 10:59:42 maxcooper Exp $ + * $Revision: 1.8 $ + * $Date: 2003/06/09 10:59:42 $ * * ==================================================================== * The SecurityFilter Software License, Version 1.1 @@ -64,15 +64,12 @@ import org.securityfilter.realm.SimpleSecurityRealmBase; * And this user is in one role: 'inthisrole' * * @author Max Cooper (max@maxcooper.com) - * @version $Revision: 1.7 $ $Date: 2003/02/07 11:17:23 $ + * @version $Revision: 1.8 $ $Date: 2003/06/09 10:59:42 $ */ public class TrivialSecurityRealm extends SimpleSecurityRealmBase { - private static final String THE_USERNAME = "username"; - private static final String THE_PASSWORD = "password"; - private static final String THE_ROLE = "inthisrole"; private String exampleProperty; - + /** * Authenticate a user. * @@ -84,7 +81,7 @@ public class TrivialSecurityRealm extends SimpleSecurityRealmBase { * @return null if the user cannot be authenticated, otherwise a Pricipal object is returned */ public boolean booleanAuthenticate(String username, String password) { - return THE_USERNAME.equals(username) && THE_PASSWORD.equals(password); + return Constants.VALID_USERNAME.equals(username) && Constants.VALID_PASSWORD.equals(password); } /** @@ -97,7 +94,7 @@ public class TrivialSecurityRealm extends SimpleSecurityRealmBase { * @return true if the user is in the role, false otherwise */ public boolean isUserInRole(String username, String role) { - return THE_USERNAME.equals(username) && THE_ROLE.equals(role); + return Constants.VALID_USERNAME.equals(username) && Constants.VALID_ROLE.equals(role); } /** diff --git a/web/share/loginForm.jsp b/web/share/loginForm.jsp index e489fb8..4ca85f4 100644 --- a/web/share/loginForm.jsp +++ b/web/share/loginForm.jsp @@ -1,16 +1,35 @@ +<%@ page import="org.securityfilter.example.Constants"%> + -SecurityFilter Example Application: Login Form +<%=Constants.LOGIN_TITLE%> -

SecurityFilter Example Application: Login Form

+ +

<%=Constants.LOGIN_TITLE%>

+ <%@include file="/menu.jsp" %> -Login with username=username and password=password. -
-Username:

-Password:

+ +Login with username=<%=Constants.VALID_USERNAME%> +and password=<%=Constants.VALID_PASSWORD%>. + + + +Username: +

+ +Password: +

+ +

\ No newline at end of file diff --git a/web/share/securePage.jsp b/web/share/securePage.jsp index 1ace5c0..0deaa05 100644 --- a/web/share/securePage.jsp +++ b/web/share/securePage.jsp @@ -1,10 +1,17 @@ +<%@ page import="org.securityfilter.example.Constants"%> + - -SecurityFilter Example Application: Secure Page + +<%=Constants.SECURE_TITLE%> -

SecurityFilter Example Application: Secure Page

+ +

<%=Constants.SECURE_TITLE%>

+ <%@include file="/menu.jsp" %> -Welcome <%=request.getRemoteUser()%>, you are viewing a secure page. + +Welcome <%=request.getRemoteUser()%>, you are viewing a secure page. + + \ No newline at end of file -- 2.11.0