# RoleBasedSecurityController.jpf Sample

This topic inludes the source code for the RoleBasedSecurityController.jpf Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebApp/security/roleBasedSecurity/

## Sample Source Code

`001 package security.roleBasedSecurity; 002 import com.bea.wlw.netui.pageflow.Forward; 003 import com.bea.wlw.netui.pageflow.PageFlowController; 004 005 /** 006 * This page flow demonstrates the use of the attributes 007 * 008 * jpf:action login-required 009 * 010 * and 011 * 012 * jpf:action roles-allowed 013 * 014 * To access the begin() method, a user must be logged in. 015 * To access the toAdminPage() method, a user must be logged in in the Administrator role. 016 * 017 * @jpf:controller 018 * @jpf:view-properties view-properties:: 019 * <!-- This data is auto-generated. Hand-editing this section is not recommended. --> 020 * <view-properties> 021 * <pageflow-object id="pageflow:/security/roleBasedSecurity/roleBasedSecurityController.jpf"/> 022 * <pageflow-object id="action:begin.do"> 023 * <property value="60" name="x"/> 024 * <property value="60" name="y"/> 025 * </pageflow-object> 026 * <pageflow-object id="action:toAdminPage.do"> 027 * <property value="320" name="x"/> 028 * <property value="60" name="y"/> 029 * </pageflow-object> 030 * <pageflow-object id="action:loginCancel.do"> 031 * <property value="180" name="x"/> 032 * <property value="180" name="y"/> 033 * </pageflow-object> 034 * <pageflow-object id="action:loginSuccess.do"> 035 * <property value="180" name="x"/> 036 * <property value="260" name="y"/> 037 * </pageflow-object> 038 * <pageflow-object id="action:doLogoutSamplesHome.do"> 039 * <property value="560" name="x"/> 040 * <property value="60" name="y"/> 041 * </pageflow-object> 042 * <pageflow-object id="action-call:@page:index.jsp@#@action:toAdminPage.do@"> 043 * <property value="236,260,260,284" name="elbowsX"/> 044 * <property value="52,52,52,52" name="elbowsY"/> 045 * <property value="East_1" name="fromPort"/> 046 * <property value="West_1" name="toPort"/> 047 * </pageflow-object> 048 * <pageflow-object id="page:index.jsp"> 049 * <property value="200" name="x"/> 050 * <property value="60" name="y"/> 051 * </pageflow-object> 052 * <pageflow-object id="action-call:@page:adminPage.jsp@#@action:doLogoutSamplesHome.do@"> 053 * <property value="476,500,500,524" name="elbowsX"/> 054 * <property value="52,52,52,52" name="elbowsY"/> 055 * <property value="East_1" name="fromPort"/> 056 * <property value="West_1" name="toPort"/> 057 * </pageflow-object> 058 * <pageflow-object id="page:adminPage.jsp"> 059 * <property value="440" name="x"/> 060 * <property value="60" name="y"/> 061 * </pageflow-object> 062 * <pageflow-object id="page:../index.jsp"> 063 * <property value="300" name="x"/> 064 * <property value="180" name="y"/> 065 * </pageflow-object> 066 * <pageflow-object id="external-jpf:/security/securityController.jpf"> 067 * <property value="560" name="x"/> 068 * <property value="180" name="y"/> 069 * </pageflow-object> 070 * <pageflow-object id="forward:path#success#index.jsp#@action:begin.do@"> 071 * <property value="96,130,130,164" name="elbowsX"/> 072 * <property value="52,52,52,52" name="elbowsY"/> 073 * <property value="East_1" name="fromPort"/> 074 * <property value="West_1" name="toPort"/> 075 * <property value="success" name="label"/> 076 * </pageflow-object> 077 * <pageflow-object id="forward:path#success#adminPage.jsp#@action:toAdminPage.do@"> 078 * <property value="356,380,380,404" name="elbowsX"/> 079 * <property value="52,52,52,52" name="elbowsY"/> 080 * <property value="East_1" name="fromPort"/> 081 * <property value="West_1" name="toPort"/> 082 * <property value="success" name="label"/> 083 * </pageflow-object> 084 * <pageflow-object id="forward:path#curPage#../index.jsp#@action:loginCancel.do@"> 085 * <property value="216,240,240,264" name="elbowsX"/> 086 * <property value="172,172,172,172" name="elbowsY"/> 087 * <property value="East_1" name="fromPort"/> 088 * <property value="West_1" name="toPort"/> 089 * <property value="curPage" name="label"/> 090 * </pageflow-object> 091 * <pageflow-object id="return-to:@forward:return-to#prevAction#previousAction#@action:loginSuccess.do@@"> 092 * <property value="300" name="x"/> 093 * <property value="260" name="y"/> 094 * </pageflow-object> 095 * <pageflow-object id="forward:return-to#prevAction#previousAction#@action:loginSuccess.do@"> 096 * <property value="216,240,240,264" name="elbowsX"/> 097 * <property value="252,252,252,252" name="elbowsY"/> 098 * <property value="East_1" name="fromPort"/> 099 * <property value="West_1" name="toPort"/> 100 * <property value="prevAction" name="label"/> 101 * </pageflow-object> 102 * <pageflow-object id="forward:path#success#/security/securityController.jpf#@action:doLogoutSamplesHome.do@"> 103 * <property value="560,560,560,560" name="elbowsX"/> 104 * <property value="104,120,120,136" name="elbowsY"/> 105 * <property value="South_1" name="fromPort"/> 106 * <property value="North_1" name="toPort"/> 107 * <property value="success" name="label"/> 108 * </pageflow-object> 109 * <pageflow-object id="action-call:@external-jpf:/security/shoppingCartLogin/login/loginController.jpf@#@action:loginCancel.do@"> 110 * <property value="116,130,130,144" name="elbowsX"/> 111 * <property value="212,212,172,172" name="elbowsY"/> 112 * <property value="East_1" name="fromPort"/> 113 * <property value="West_1" name="toPort"/> 114 * </pageflow-object> 115 * <pageflow-object id="action-call:@external-jpf:/security/shoppingCartLogin/login/loginController.jpf@#@action:loginSuccess.do@"> 116 * <property value="116,130,130,144" name="elbowsX"/> 117 * <property value="212,212,241,241" name="elbowsY"/> 118 * <property value="East_1" name="fromPort"/> 119 * <property value="West_0" name="toPort"/> 120 * </pageflow-object> 121 * <pageflow-object id="external-jpf:/security/shoppingCartLogin/login/loginController.jpf"> 122 * <property value="80" name="x"/> 123 * <property value="220" name="y"/> 124 * </pageflow-object> 125 * </view-properties> 126 * :: 127 */ 128 public class roleBasedSecurityController extends PageFlowController 129 { 130 /** 131 * If a non-logged in user calls this Action, a NotLoggedInException is thrown 132 * (this is because login-required is set to "true"). The exception is caught 133 * and the user is sent to the login page flow: /login/shoppingCartLogin/login/loginController.jpf 134 * (a nested page flow). 135 * 136 * If the user successfully logs in, he is returned to this Action, which executes normally. 137 * 138 * @jpf:action login-required="true" 139 * @jpf:catch type="com.bea.wlw.netui.pageflow.NotLoggedInException" path="/security/shoppingCartLogin/login/loginController.jpf" 140 * @jpf:forward name="success" path="index.jsp" 141 */ 142 protected Forward begin() 143 { 144 return new Forward( "success" ); 145 } 146 147 /** 148 * To access this Action, a user must be logged in and a member of the Administrator 149 * role. 150 * 151 * The Administrator role is declared in the WEB-INF/web.xml file by the 152 * <security-role> element. (The user 'weblogic' is made a member of this role 153 * in WEB-INF/weblogic.xml.) 154 * 155 * @jpf:action roles-allowed="Administrator" 156 * @jpf:forward name="success" path="adminPage.jsp" 157 */ 158 protected Forward toAdminPage() 159 { 160 return new Forward("success"); 161 } 162 163 /** 164 * @jpf:action 165 * @jpf:forward name="curPage" path="../index.jsp" 166 */ 167 protected Forward loginCancel() 168 { 169 return new Forward( "curPage" ); 170 } 171 172 /** 173 * @jpf:action 174 * @jpf:forward name="prevAction" return-to="previousAction" 175 */ 176 protected Forward loginSuccess() 177 { 178 return new Forward( "prevAction" ); 179 } 180 181 /** 182 * @jpf:action 183 * @jpf:forward name="success" path="/security/securityController.jpf" 184 */ 185 protected Forward doLogoutSamplesHome() 186 { 187 logout( true ); 188 return new Forward("success"); 189 } 190 }`