You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by 滕训华 <te...@magic-sw.com.cn> on 2008/06/04 05:34:55 UTC
login page error (T5&Acegi)
Login.tml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<link href="${asset:context:css/style.css}" rel="stylesheet"
type="text/css" />
<title>YOUR TITLE HERE!</title>
</head>
<body scroll="no">
<div class="header">
<div class="header_interior"><img src="${asset:context:/images/logo.gif}"
alt="Logo" width="44" height="44" style="float:left; margin-right:10px;" />
<h1 class="title">Call Center for JILIN Tax Revenue </h1>
</div>
</div>
<div class="header_shadow"> </div>
<div class="content_interior">
<div class="login_table">
<br />
<br/>
<br/>
<t:form t:id="loginForm">
<t:errors/>
<table>
<tr>
<td>UserName:</td>
<td><input t:type="TextField" type="text" t:id="j_username"
/></td>
</tr>
<tr>
<td>Password:</td>
<td><input t:type="PasswordField" type="password"
t:id="j_password" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" t:type="submit" t:id="loginButton"
/></td>
</tr>
</table>
</t:form>
</div>
</div>
<div class="footer"><div class="footer-inner">
<br clear="all" />
<hr width="100%" noshade="noshade" style="border-top:1px solid #FFFFFF;
border-bottom: none; margin-bottom:5px;" />
<div style="text-align:center;">Copyright ? 2008 YourName
<!-- Thanks Again --> </div>
</div><br clear="all" /></div>
</body>
</html>
login.java
package com.callcenter.web.pages;
import org.apache.tapestry.services.RequestGlobals;
import org.apache.tapestry.ioc.annotations.*;
import org.apache.tapestry.services.Response;
import
org.springframework.security.providers.UsernamePasswordAuthenticationToken;
import org.springframework.security.Authentication;
import org.springframework.security.AuthenticationManager;
import org.springframework.security.AuthenticationException;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.security.ui.savedrequest.SavedRequest;
import org.springframework.security.ui.AbstractProcessingFilter;
import java.io.IOException;
public class Login {
private String j_username;
private String j_password;
public String getJ_username() {
return j_username;
}
public void setJ_username(String j_username) {
this.j_username = j_username;
}
public String getJ_password() {
return j_password;
}
public void setJ_password(String j_password) {
this.j_password = j_password;
}
/*
* Process the event from login button
*/
@Inject
private RequestGlobals requestGlobals;
@Inject
private AuthenticationManager authenticationManager;
Object onSelectedFromLoginButton() throws IOException{
//requestGlobals.getResponse().sendRedirect("j_spring_security_check?j_usern
ame="+j_username+"&j_password="+j_password);
UsernamePasswordAuthenticationToken authRequest=new
UsernamePasswordAuthenticationToken(getJ_username(),getJ_password());
Authentication authResult;
/**
*
*/
try{
authResult=authenticationManager.authenticate(authRequest);
}
catch(final AuthenticationException failed){
return null;
}
SecurityContextHolder.getContext().setAuthentication(authResult);
SavedRequest
savedRequest=(SavedRequest)requestGlobals.getRequest().getSession(false).get
Attribute(AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY);
if(savedRequest!=null){
requestGlobals.getResponse().sendRedirect(savedRequest.getFullRequestUrl());
return null;
}
else{
return "/login";
}
}
}
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
CallCenter
</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml
/WEB-INF/applicationContext-security.xml</param-value>
</context-param>
<context-param>
<param-name>tapestry.app-package</param-name>
<param-value>com.callcenter.web</param-value>
</context-param>
<!-- Integration with acegi start -->
<filter>
<filter-name>AcegiFilterChainProxy</filter-name>
<filter-class>org.springframework.security.util.FilterToBeanProxy</filter-cl
ass>
<init-param>
<param-name>targetClass</param-name>
<param-value>org.springframework.security.util.FilterChainProxy</param-value
>
</init-param>
</filter>
<filter-mapping>
<filter-name>AcegiFilterChainProxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Integration with acegi end -->
<!-- Integration with spring start -->
<filter>
<filter-name>app</filter-name>
<filter-class>org.apache.tapestry.spring.TapestrySpringFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>app</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Integration with spring end -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</liste
ner-class>
</listener>
<!-- Integration with spring end -->
<listener>
<listener-class>org.springframework.security.ui.session.HttpSessionEventPubl
isher</listener-class>
</listener>
</web-app>
ApplicationContext-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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.1.xsd">
<http auto-config='true'>
<intercept-url pattern="/login*"
access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/css/**" filters="none"/>
<intercept-url pattern="/images/**" filters="none"/>
<intercept-url pattern="/**" access="ROLE_TEST" />
<form-login login-page="/login" />
</http>
<!-- Set the authentication users source start -->
<!-- the simple config
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"/>
</authentication-provider>
-->
<!-- Set the authentication users source end -->
</beans:beans>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Set the jdbc source start -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="url"
value="jdbc:sqlserver://localhost:1433;databaseName=pubs"></property>
<property name="username" value="sa"></property>
<property name="password" value=""></property>
</bean>
<!-- Config authentication provider -->
<bean id="daoAuthenticationProvider"
class="org.springframework.security.providers.dao.DaoAuthenticationProvider"
>
<property name="userDetailsService" ref="userDetailsService"
/>
</bean>
<bean id="userDetailsService"
class="org.springframework.security.userdetails.jdbc.JdbcDaoImpl">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- Config the authentication manager -->
<bean id="authenticationManager"
class="org.springframework.security.providers.ProviderManager">
<property name="providers">
<list>
<ref local="daoAuthenticationProvider" />
</list>
</property>
</bean>
</beans>
Above are the relative files, and when I load login page,it give me an
error:
An unexpected application exception has occurred.
java.lang.ClassNotFoundException: caught an exception while obtaining a
class file for com.callcenter.web.pages.Login
and I try to get rid of the code “@Inject
private RequestGlobals requestGlobals;” and the relative code in the
onSelectedFromLoginButton method of login.java
then the login page can display in IE.
Please help me to find the reasons,thanks everybody.