# LoginController.jpf Sample

This topic inludes the source code for the LoginController.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/shoppingCartLogin/login/

## Sample Source Code

`001 package security.shoppingCartLogin.login; 002 003 import com.bea.wlw.netui.pageflow.FormData; 004 import com.bea.wlw.netui.pageflow.Forward; 005 import com.bea.wlw.netui.pageflow.PageFlowController; 006 import javax.security.auth.login.LoginException; 007 008 /** 009 * @jpf:controller nested="true" 010 * @jpf:view-properties view-properties:: 011 * <!-- This data is auto-generated. Hand-editing this section is not recommended. --> 012 * <view-properties> 013 * <pageflow-object id="pageflow:/login/shoppingCartLogin/login/loginController.jpf"/> 014 * <pageflow-object id="action:begin.do"> 015 * <property value="100" name="x"/> 016 * <property value="180" name="y"/> 017 * </pageflow-object> 018 * <pageflow-object id="action:doLogin.do#login.shoppingCartLogin.login.loginController.LoginForm"> 019 * <property value="380" name="x"/> 020 * <property value="140" name="y"/> 021 * </pageflow-object> 022 * <pageflow-object id="action:cancel.do"> 023 * <property value="380" name="x"/> 024 * <property value="240" name="y"/> 025 * </pageflow-object> 026 * <pageflow-object id="action-call:@page:index.jsp@#@action:cancel.do@"> 027 * <property value="276,310,310,344" name="elbowsX"/> 028 * <property value="183,183,232,232" name="elbowsY"/> 029 * <property value="East_2" name="fromPort"/> 030 * <property value="West_1" name="toPort"/> 031 * </pageflow-object> 032 * <pageflow-object id="action-call:@page:index.jsp@#@action:doLogin.do#login.shoppingCartLogin.login.loginController.LoginForm@"> 033 * <property value="276,310,310,344" name="elbowsX"/> 034 * <property value="172,172,132,132" name="elbowsY"/> 035 * <property value="East_1" name="fromPort"/> 036 * <property value="West_1" name="toPort"/> 037 * </pageflow-object> 038 * <pageflow-object id="page:index.jsp"> 039 * <property value="240" name="x"/> 040 * <property value="180" name="y"/> 041 * </pageflow-object> 042 * <pageflow-object id="forward:path#success#index.jsp#@action:begin.do@"> 043 * <property value="136,170,170,204" name="elbowsX"/> 044 * <property value="172,172,172,172" name="elbowsY"/> 045 * <property value="East_1" name="fromPort"/> 046 * <property value="West_1" name="toPort"/> 047 * <property value="success" name="label"/> 048 * </pageflow-object> 049 * <pageflow-object id="exit:loginSuccess"> 050 * <property value="500" name="x"/> 051 * <property value="140" name="y"/> 052 * </pageflow-object> 053 * <pageflow-object id="forward:return-action#success#loginSuccess#@action:doLogin.do#login.shoppingCartLogin.login.loginController.LoginForm@"> 054 * <property value="416,440,440,464" name="elbowsX"/> 055 * <property value="132,132,132,132" name="elbowsY"/> 056 * <property value="East_1" name="fromPort"/> 057 * <property value="West_1" name="toPort"/> 058 * <property value="success" name="label"/> 059 * </pageflow-object> 060 * <pageflow-object id="exit:loginCancel"> 061 * <property value="500" name="x"/> 062 * <property value="240" name="y"/> 063 * </pageflow-object> 064 * <pageflow-object id="forward:return-action#cancel#loginCancel#@action:cancel.do@"> 065 * <property value="416,440,440,464" name="elbowsX"/> 066 * <property value="232,232,232,232" name="elbowsY"/> 067 * <property value="East_1" name="fromPort"/> 068 * <property value="West_1" name="toPort"/> 069 * <property value="cancel" name="label"/> 070 * </pageflow-object> 071 * <pageflow-object id="formbeanprop:login.shoppingCartLogin.login.loginController.LoginForm#password#java.lang.String"/> 072 * <pageflow-object id="formbeanprop:login.shoppingCartLogin.login.loginController.LoginForm#username#java.lang.String"/> 073 * <pageflow-object id="formbean:login.shoppingCartLogin.login.loginController.LoginForm"/> 074 * </view-properties> 075 * :: 076 * 077 */ 078 public class loginController extends PageFlowController 079 { 080 /** 081 * @jpf:action 082 * @jpf:forward name="success" path="index.jsp" 083 */ 084 protected Forward begin() 085 { 086 return new Forward( "success" ); 087 } 088 089 /** 090 * Note that the return-action attribute always refers to an action in the parent, or "nesting" 091 * page flow. In this case the parent page flow is shoppingController.jpf. 092 * 093 * @jpf:action 094 * @jpf:catch type="LoginException" path="index.jsp" 095 * @jpf:forward name="success" return-action="loginSuccess" 096 */ 097 protected Forward doLogin( LoginForm form ) 098 throws LoginException 099 { 100 /* 101 * The login method below is a method of the com.bea.wlw.netui.pageflow.FlowController 102 * class (a class extended by PageFlowController). It logs in the user against WebLogic Server's current authentication provider. 103 * 104 * If the login succeeds (if user is known to the authentication provider), then 105 * the method returns void and the user is returned to the save Action on 106 * the nesting page flow /shopping/shoppingController.jpf. 107 * Note that the user is returned to the save Action via the "loginSuccess" method on the 108 * nesting page flow /shopping/shoppingController.jpf. 109 * 110 * If the login fails, a LoginException is returned and the user is returned to the 111 * login page. 112 */ 113 login( form.getUsername(), form.getPassword() ); 114 return new Forward( "success" ); 115 } 116 117 /** 118 * @jpf:action 119 * @jpf:forward name="cancel" return-action="loginCancel" 120 */ 121 protected Forward cancel() 122 { 123 /* 124 * This will raise the "loginCancel" method on the nesting page flow. 125 * In this case, the nesting page flow is /shopping/shoppingController.jpf 126 */ 127 return new Forward( "cancel" ); 128 } 129 130 /** 131 * FormData get and set methods may be overwritten by the Form Bean editor. 132 */ 133 public static class LoginForm extends FormData 134 { 135 private String username; 136 137 private String password; 138 139 140 public void setPassword(String password) 141 { 142 this.password = password; 143 } 144 145 public String getPassword() 146 { 147 return this.password; 148 } 149 150 public void setUsername(String username) 151 { 152 this.username = username; 153 } 154 155 public String getUsername() 156 { 157 return this.username; 158 } 159 } 160 }`