0

Spring Security: Personal form-login page doesn't work when events are secured ???

asked 2009-07-22 10:03:44 +0800

dermaik81 gravatar image dermaik81
60 1

Hi guys and spring specialists,
Last week I secured my webapp with the spring framework. Everything works fine. The article found here works fine as well. But here is my big unsolved problem.

In the WEB-INF/applicationContext-security.xml I create a tag for my own login page like :

<http auto-config="true">
        <intercept-url pattern="/secure/extreme/**" access="ROLE_SUPERVISOR"/>
        <intercept-url pattern="/secure/**" access="IS_AUTHENTICATED_REMEMBERED" />
        <intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
 
        <!-- use own login page rather than the default one -->
        <form-login login-page="/login.zul"/>
    </http>

When I start my application my own login window is shown and the login-procedure works. Furthermore the url-based security is not accurate for my app. I also want to secure some events.
So I 've found a code as follows:
<zksp:zk-event login-template-close-delay="5">
<zksp:intercept-event event="onClick" path="//**/btn_*" access="ROLE_TELLER"/>
<zksp:intercept-event path="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
</zksp:zk-event>


When I add this code to my application, I get an http 404 error that my login.zul cannot be found. When I delete the code again everything works. Ok guys - thats not all.
I add the code for event security again. But then I delete the <form-login login-page="/login.zul"/> Tag in the applicationContext-security.xml. While starting my app I receive the SPring standard login Page and ... everything works. The url based security and the event based one. Thats hilarious.
Whats going wrong? Are I am not allowed to use an own login page when I want to secure some events?
Thanks a lot for any hint ,

Greetz, Maik (perhaps terry tornado could help me??)

delete flag offensive retag edit

2 Replies

Sort by » oldest newest

answered 2009-07-22 10:41:30 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-07-22 10:42:45 +0800

hohoho, Maik, i'm not sure if i can help you :-)

I done all security intercepts in the java code.

Here is a rest of my xml code but it doesn't use it:

<zksp:zk-event login-template-close-delay="5">
<zksp:intercept-event event="onClick" path="//**/btn_*" access="IS_AUTHENTICATED_REMEBERED"/>
<zksp:intercept-event path="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
</zksp:zk-event>

regards
Stephan

I'm not at place, so i can only in the evening post here the the zul- and java code for the LoginDialog. And yes you are right, it's a mix from html and zul. This is copied by a friend of mine from a jsp project.

Hope in 1-2 weeks i check out fully sourced sample in ZK Forge.

link publish delete flag offensive edit

answered 2009-07-22 16:37:22 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Attached my used code, But it works not alone.

Stephan

Maik beschreib mir das doch mal auf deutsch. das ist für mich einfacher zu verstehen.
sge(at)forsthaus(dot)de


ZKLoginDialog.zul

<?page id="loginZul" title="LOGIN"?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<zk xmlns="http://www.zkoss.org/2005/zul"
	xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">

	<window id="loginwin" border="none" width="350px"
		use="org.myfirm.ZkLoginDialogCtrl">


		<div style="background-color:#4944F9">
			<hbox width="100%">

				<h:div id="divNo" align="left">
					<image src="/images/zkoss3.gif" />
				</h:div>

				<h:div id="divNorthEast" align="right">
					<button id="button_ZKLoginDialog_Close"
						image="/images/icons/stop.gif"
						tooltiptext="${c:l('button_ZKLoginDialog_Close.tooltiptext')}" />
				</h:div>
			</hbox>
			<separator bar="true" style="background-color:silver" />
		</div>



		<groupbox if="${not empty param.login_error}">
			<label style="color:red"
				value="Login failed. Please try again." />
			<h:br />
			<label style="color:red"
				value="Reason: ${sessionScope.SPRING_SECURITY_LAST_EXCEPTION.message}" />
			<h:br />
		</groupbox>
		<groupbox>
			<caption>Login</caption>

			<div align="right" style="padding: 5px">
				<hbox align="end">
					<label id="lbl_ServerTime" />
					<button id="button_ZKLoginDialog_ServerTime"
						image="/images/icons/date.gif"
						tooltiptext="${c:l('button_ZKLoginDialog_ServerTime.tooltiptext')}" />
				</hbox>
				<separator bar="true" />
			</div>

			<div>
				<h:form id="f" name="f" action="j_spring_security_check"
					method="POST">

					<grid fixedLayout="true" style="border:0px">
						<columns>
							<column width="40%" />
							<column width="60%" />
						</columns>
						<rows>

							<row>
								<label id="label_ZKLoginDialog_user"
									value="${c:l('label_ZKLoginDialog_user.value')}" />
								<textbox id="u" name="j_username"
									width="99%" />
							</row>
							<row>
								<label id="label_ZKLoginDialog_pwd"
									value="${c:l('label_ZKLoginDialog_pwd.value')}" />
								<textbox id="p" type="password"
									name="j_password" width="99%" />
							</row>

							<row spans="2">
								<hbox>
									<h:input type="submit"
										value="Login" />
									<h:input type="reset" value="Reset" />
								</hbox>
							</row>
						</rows>
					</grid>
				</h:form>
			</div>

		</groupbox>
	</window>
</zk>[
/code]

<u >
ZkLoginDialogCtr</u>l

import java.io.IOException;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;
import org.myfirm.webui.util.BaseCtrl;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Label;
import org.zkoss.zul.Window;

public class ZkLoginDialogCtrl extends BaseCtrl implements Serializable {

private transient final static Logger logger = Logger.getLogger(ZkLoginDialogCtrl.class);
private static final long serialVersionUID = -71422545405325060L;

/*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Components from the zul-file that are autowired through extending this
* class from BaseCtrl.java
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
protected Window loginwin; // autowired
protected Label lbl_ServerTime; // autowired

/**
* constructor. <br>
*/
public ZkLoginDialogCtrl() {
super();

if (logger.isDebugEnabled()) {
logger.debug("--> super() ");
}
}

public void onCreate$loginwin(Event event) throws Exception {

if (logger.isDebugEnabled()) {
logger.debug("--> " + event.toString());
}

doOnCreateCommon(loginwin); // do the autowire

loginwin.doModal();

}

/**
* when the "close" button is clicked. <br>
*
* @throws IOException
*/
public void onClick$button_ZKLoginDialog_Close() throws IOException {

if (logger.isDebugEnabled()) {
logger.debug("-->");
}

Executions.sendRedirect("/j_spring_logout");
}

/**
* when the "getServerTime" button is clicked. <br>
*
* @throws IOException
*/
public void onClick$button_ZKLoginDialog_ServerTime() throws IOException {

if (logger.isDebugEnabled()) {
logger.debug("--> get the server date/time");
}

lbl_ServerTime.setValue("time on server: " + getDateTime());
}

/**
* Get the actual date/time on server. <br>
*
* @return String of date/time
*/
private String getDateTime() {
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date date = new Date();
return dateFormat.format(date);
}

}

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-07-22 10:03:44 +0800

Seen: 429 times

Last updated: Jul 22 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More