這廝

          observing

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            48 Posts :: 3 Stories :: 3 Comments :: 0 Trackbacks
          Using Spring Security in your Java web application

          Sample applications were developed and deployed in the environment described below:

          1. JDK 1.6.11
          2. JBoss Application Server 5.1.0
          3. Spring Framework 3.0.3
          4. Spring Security 3.0.3
          5. Eclipse IDE 3.5 (Galileo)
          6. JavaServer Faces 1.2 (JSF) – No separate implementations were used other than what's found with JBoss 5.1.0
          loading config - web.xml file:
          <?xml version="1.0" encoding="UTF-8"?>
          <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns="http://java.sun.com/xml/ns/javaee" 
              xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
              id="WebApp_ID" version="2.5">
              <display-name>JSFSpringNoSecurityWebApp</display-name>
          
              <!-- Spring configuration file location -->
              <context-param>
                  <param-name>contextConfigLocation</param-name>
                  <param-value>
                      /WEB-INF/applicationContext-business.xml
                  </param-value>
              </context-param>
          
              <!-- To start/stop Spring framework automatically. -->
              <listener>
                  <listener-class>
                      org.springframework.web.context.ContextLoaderListener
                  </listener-class>
              </listener>
          
              <welcome-file-list>
                  <welcome-file>index.html</welcome-file>
                  <welcome-file>index.htm</welcome-file>
                  <welcome-file>index.jsp</welcome-file>
                  <welcome-file>default.html</welcome-file>
                  <welcome-file>default.htm</welcome-file>
                  <welcome-file>default.jsp</welcome-file>
              </welcome-file-list>
          
              <servlet>
                  <servlet-name>Faces Servlet</servlet-name>
                  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                  <load-on-startup>1</load-on-startup>
              </servlet>
              <servlet-mapping>
                  <servlet-name>Faces Servlet</servlet-name>
                  <url-pattern>/faces/*</url-pattern>
              </servlet-mapping>
          </web-app>
           Spring config - applicationContext-business.xml:
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="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-3.0.xsd">
          
              <bean id="calculatorBean" class="org.swview.springsecuritytestapp.logic.CalculatorIpml">
              </bean>
          </beans>
          JSF config - 
          faces-config.xml
          <?xml version="1.0" encoding="UTF-8"?>
          
          <faces-config
              xmlns="http://java.sun.com/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                  http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
              version="1.2">
          
              <application>
                  <el-resolver>
                    org.springframework.web.jsf.el.SpringBeanFacesELResolver
                  </el-resolver>
              </application>
              
              <managed-bean>
                  <managed-bean-name>calculatorController</managed-bean-name>
                  <managed-bean-class>
                    org.swview.springsecuritytestapp.jsf.CalculatorController
                  </managed-bean-class>
                  <managed-bean-scope>request</managed-bean-scope>
                  <managed-property>
                      <property-name>calculator</property-name>
                      <value>#{calculatorBean}</value>
                  </managed-property>
              </managed-bean>
          </faces-config>
          

          page file - 
          calculator.jsp file
          <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
          <%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
          <%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
              "http://www.w3.org/TR/html4/loose.dtd">
          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
          <title>Calculator</title>
          </head>
          <body>
          <f:view>
          <h:form>
              <h:panelGrid border="1" columns="3">
                  <h:outputLabel value="Number 1:"></h:outputLabel>
                  <h:inputText value="#{calculatorController.number1}" id="number1Field">
                      <f:convertNumber />
                  </h:inputText>
                  <h:message for="number1Field"></h:message>
                  <h:outputText value="Number 2:"></h:outputText>
                  <h:inputText value="#{calculatorController.number2}" id="number2Field">
                      <f:convertNumber />
                  </h:inputText>
                  <h:message for="number2Field"></h:message>
                  <h:outputLabel value="Sum:"></h:outputLabel>
                  <h:outputLabel value="#{calculatorController.results}"></h:outputLabel>
              </h:panelGrid>
              <h:commandButton value="Add Again"
                  action="#{calculatorController.add}"></h:commandButton>
          </h:form>
          </f:view>
          </body>
          </html>

          Controller:

          package org.swview.springsecuritytestapp.jsf;
          
          import org.swview.springsecuritytestapp.logic.Calculator;
          
          public class CalculatorController {
              private double number1;
              private double number2;
              private double results;
              
              private Calculator calculator;
              
              public void setCalculator(Calculator calculator) {
                  this.calculator = calculator;
              }
          
              public double getNumber1() {
                  return number1;
              }
              public void setNumber1(double number1) {
                  this.number1 = number1;
              }
              public double getNumber2() {
                  return number2;
              }
              public void setNumber2(double number2) {
                  this.number2 = number2;
              }
              public double getResults() {
                  return results;
              }
              public void setResults(double results) {
                  this.results = results;
              }
          
              public String add() {
                  results = calculator.add(number1, number2);
                  return "success";
              }    
          }
          
          Spring bean implementation
          package org.swview.springsecuritytestapp.logic;
          
          public class CalculatorIpml implements Calculator {
              
              public double add(double a, double b) {
                  return a + b;
              }
              
              public double subtract(double a, double b) {
                  return a - b;
              }
          }

          ---testing.. to be continue


          posted on 2011-12-22 22:53 cnbarry 閱讀(365) 評論(1)  編輯  收藏 所屬分類: Java

          Feedback

          # re: 【hello world】Using Spring Security in JWA (1) - no security case 2011-12-22 22:55 cnbarry
          Note:
          From - http://www.swview.org/blog/using-spring-security-your-java-web-application  回復  更多評論
            

          主站蜘蛛池模板: 西平县| 绵阳市| 视频| 德惠市| 徐州市| 离岛区| 高淳县| 余江县| 岗巴县| 施甸县| 钦州市| 个旧市| 华宁县| 中山市| 九江县| 怀仁县| 洱源县| 博爱县| 阿尔山市| 旅游| 慈利县| 青河县| 阳信县| 合作市| 浮梁县| 沙雅县| 漳浦县| 龙陵县| 辽源市| 上思县| 和田市| 公主岭市| 古丈县| 布拖县| 高尔夫| 通辽市| 古田县| 永康市| 汪清县| 长岭县| 昌黎县|