ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

ZK login form with spring security 3 - store and retrieve last used user ID?

davout
8 Mar 2011 09:20:51 GMT
8 Mar 2011 09:20:51 GMT

I'm using spring security with ZK, and have the following login form built using ZK...

<?page title="Login" contentType="text/html;charset=UTF-8"?>
<zk xmlns:xhtml="http://www.w3.org/1999/xhtml"
	xmlns:zk="http://www.zkoss.org/2005/zk">

	<xhtml:form id="f" name="f" action="j_spring_security_check"
		method="post" xmlns:h="http://www.w3.org/1999/xhtml">
		<window title="Login" border="normal" width="500px">
			<grid>
			    <columns>
			         <column width="140px"/>
			         <column width="340px"/>
			    </columns>
				<rows>
					<row>
						<label value="User ID" />
						<textbox id="u" name="j_username" cols="60"/>
					</row>
					<row>
						<label value="Password" />
						<textbox id="p" type="password"
							name="j_password" cols="20"/>
					</row>
					<row>
						<space />
						<hlayout>
							<xhtml:input type="submit" value="Login" />
							<xhtml:input type="reset" value="Reset" />
						</hlayout>
					</row>
				</rows>
			</grid>
		</window>
	</xhtml:form>
</zk>


I want to enhance this form so that the last entered user id is stored as a cookie so that when the user starts a subsequent session they don't have to retype in their user id. Any suggestions for how to do this?

davout
8 Mar 2011 11:09:09 GMT
8 Mar 2011 11:09:09 GMT

I found the answer...

Add the 'remember-me' line to the spring security xml file...

	<http>
		<intercept-url pattern="/admin/*.zul" access="ROLE_SYS_ADMIN" />
		<intercept-url pattern="/user/*.zul" access="ROLE_USER" />
		<anonymous username="guest" granted-authority="ROLE_GUEST" />
		<remember-me key="eisBerthier"/>
		<form-login login-page="/spring_security_login.zul"/>
	</http>



and then add the following lines to your login.zul file...
<?page title="Login" contentType="text/html;charset=UTF-8"?>
<zk xmlns:xhtml="http://www.w3.org/1999/xhtml"
	xmlns:zk="http://www.zkoss.org/2005/zk">

	<xhtml:form id="f" name="f" action="j_spring_security_check"
		method="post" xmlns:h="http://www.w3.org/1999/xhtml">
		<window title="Login" border="normal" width="600px">
			<grid>
			    <columns>
			         <column width="140px"/>
			         <column width="340px"/>
			    </columns>
				<rows>
					<row>
						<label value="User ID" />
						<textbox id="u" name="j_username" cols="60"/>
					</row>
					<row>
						<space />
						<checkbox id="r" name="_spring_security_remember_me" label="Remember me?" checked="true"/>
					</row>
					<row>
						<label value="Password" />
						<textbox id="p" type="password"
							name="j_password" cols="20"/>
					</row>
					<row>
						<space />
						<hlayout>
							<xhtml:input type="submit" value="Login" />
							<xhtml:input type="reset" value="Reset" />
						</hlayout>
					</row>
				</rows>
			</grid>
		</window>
	</xhtml:form>
</zk>

vicmonmena
1 Jun 2011 09:46:42 GMT
1 Jun 2011 09:46:42 GMT

Hi davout!


Do you have some example about build applications with ZK and Spring Security 3?.


Thanks!

davout
1 Jun 2011 11:14:12 GMT
1 Jun 2011 11:14:12 GMT

What specifically are you after?

jaider2523
1 Jun 2011 15:11:35 GMT
1 Jun 2011 15:11:35 GMT

Hey, check my thread http://www.zkoss.org/forum/listComment/16301.

Here are all the only thing is that it will not let me enter the pages from the log files ... download and try it .... we can help each purchase to reach the solution, I too am very worried.

My email address is jaider2523@gmail.com .....

If solutions or something I can write.

ajaidka
8 Feb 2012 09:34:13 GMT
8 Feb 2012 09:34:13 GMT

I am also facing this issue, need help to fix it.

login.zul is

<?page id="testZul" title="Manage-Login"?>
<?link rel="stylesheet" type="text/css" href="/css/login.css?v=${desktop.webApp.build}"?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>

<window height="100%" width="100%">
<zk if="${sessionScope['UserInfoMap']!= null}">
<zscript>
Executions.sendRedirect("/manage/home.zul");
</zscript>
</zk>
<zk xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:zk="http://www.zkoss.org/2005/zk"/>
<zk if="${sessionScope['UserInfoMap'] == null}">


<style>
body{
background-color:#520608;
margin-left:auto;
margin-right:auto;
margin-top:0px;
padding:0px;
background-image:url(${c:encodeURL('/system_images/login-main-bg.jpg')}) ;
font-family:Calibri;
font-size:11px;
overflow:hidden;
}

.loginContainer{
width:298px;
height:318px;
background-image:url(${c:encodeURL('/system_images/login-bg.png')}) ;
background-repeat:no-repeat;
margin-left:auto;
margin-right:auto;
margin-top:150px;;
padding-top:75px;
}

.loginContent{
margin-left:40px;
margin-right:auto;
font-size:15px;

}

.remember {
display:inline-block
margin: 9px 0 0;
vertical-align:top;
}
.remember strong {
moz-user-select: none;
color: #666666;
font-weight: normal;
line-height: 0;
padding: 0 0 0 0.4em
}

.btndiv .z-button-cr, .btndiv .z-button-cl,
.btndiv .z-button-bl, .btndiv .z-button-bm,
.btndiv .z-button-br, .btndiv .z-button-tl,
.btndiv .z-button-tm, .btndiv .z-button-tr {
background-image: none;
}
.btndiv .z-button-cm {
background : transparent url('') no-repeat 0 0 ;
}
.btndiv table {
width: 100%;
height: 100%;
}
.myWhite, .myBlack, .myGreen {
width: 110px;
height: 39px;
height: 37px\9;
}
.myWhite .z-button-cm,
.myBlack .z-button-cm,
.myGreen .z-button-cm {
height: 31px;
color: black;
}
.myWhite .z-button-cm {
background-image : url(${c:encodeURL('/system_images/button1.png')});
}
.myBlack .z-button-cm {
background-image : url(${c:encodeURL('/system_images/button2.png')});
color: white;
}
.myGreen .z-button-cm {
background-image : url(${c:encodeURL('/system_images/button3.png')});
}
.z-button-focus .z-button-cm {
background-position: 0 -62px
}
.z-button-over .z-button-cm {
background-position: 0 -31px
}
.z-button-clk .z-button-cm {
background-position: 0 -93px
}
</style>

<div class="loginContainer">
<div class="loginContent">
<html style="color:red" if="${param.login_error == 1}">
<![CDATA[
The user name or password you entered is incorrect. <br/>
]]>
</html>
<h:form id="f" name="f" action="j_spring_security_check" method="POST"
xmlns:h="http://www.w3.org/1999/xhtml">
<div>User:</div>
<div>
<textbox id="u" name="j_username"
style="border: 1px solid #100506; height:21px; width:210px;" />
</div>
<separator height="10px"/>
<div>Password:</div>
<div>
<textbox id="p" type="password" name="j_password"
style="border: 1px solid #100506; height:21px; width:210px;"/>
</div>
<separator height="10px"/>
<div class="remember">
<div>
<checkbox id="r" name="_spring_security_remember_me" checked="true"/>
<label class="remember-label" value="Stay signed in"></label>
</div>
</div>
<separator height="10px"/>
<div>
<div class="btndiv">
<button id="btn" label="Login" type="submit" sclass="myBlack" mold="trendy"/>
<button id="btn1" label="Reset" type="reset" sclass="myBlack" mold="trendy"/>
</div>
</div>
<separator height="10px"/>
<div><a href="/reset_password.zul">Forgot password?</a></div>
</h:form>
</div>
</div>
</zk>

</window>

and here is security xml


<?xml version="1.0" encoding="UTF-8"?>


<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">

<global-method-security secured-annotations="enabled">
</global-method-security>

<http auto-config="true">
<intercept-url pattern="/secure/extreme/**" access="ROLE_SUPERVISOR"/>
<intercept-url pattern="/manage/jlogout" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/manage/**" access="ROLE_ADMIN"/>
<!-- <intercept-url pattern="/home.zul**" access="ROLE_ADMIN"/> -->
<intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<remember-me key="myKey"/>
<form-login login-page="/login.zul"
default-target-url="/manage/home.zul"
authentication-failure-url="/login.zul?login_error=1"/>
<logout logout-success-url="/login.zul" logout-url="/manage/jlogout"/>
</http>

<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
id="jdbcUserService"
authorities-by-username-query="SELECT u.emailaddress as username, r.roll_name as authority
FROM user u, roll r, group_roll gr
WHERE u.emailaddress = ?
AND r.group_roll_id=u.group_roll_id
AND gr.group_roll_id=u.group_roll_id"
users-by-username-query="SELECT emailaddress as username, password, enabled FROM user WHERE emailaddress=? AND group_roll_id != 8"
group-authorities-by-username-query="SELECT r.roll_id as id, r.group_roll_id as group_name, r.roll_name
FROM roll r, user u LEFT OUTER JOIN user_realm_default urd ON urd.cust_detail_id = u.cust_det_id
WHERE u.emailaddress=?
AND (r.group_roll_id = u.group_roll_id OR r.group_roll_id=urd.role_id)"
/>
</authentication-provider>
</authentication-manager>


</beans:beans>

creata87
15 Feb 2012 11:24:57 GMT
15 Feb 2012 11:24:57 GMT

..neata :p

instead of this

<xhtml:input type="submit" value="Login" />

i use this
<xhtml:input type="image" id="login_image" alt="Login" />

and the controller applied to the login.zul page gives null pointer exception on it (does not see the login_image, like it's hidden). how can an xhtml be wired to the controller?

iulia