Spring Security 与 Struts 的集成

2024-03-30

我正在尝试在一个简单的应用程序中将 spring security 与 struts1.2 (使用 LDAP)集成 我有 applicationContext-security.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:s="http://www.springframework.org/schema/security"
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
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">

<s:http>
    <s:intercept-url pattern="/secure/extreme/**" access="ROLE_SUPERVISOR"/>
    <s:intercept-url pattern="/secure/**" access="IS_AUTHENTICATED_REMEMBERED" />
    <s:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />

    <s:form-login />
    <s:anonymous />
    <s:logout />
</s:http>


<!-- Simple namespace-based configuration -->

<s:ldap-server ldif="classpath:users.ldif" port="33389"/>

<s:authentication-manager>
    <s:ldap-authentication-provider
        group-search-filter="member={0}"
        group-search-base="ou=groups"
        user-search-base="ou=people"
        user-search-filter="uid={0}"
    />
    <s:authentication-provider ref='secondLdapProvider' />
</s:authentication-manager>


<!-- Traditional Bean version of the same configuration -->

<!-- This bean points at the embedded directory server created by the ldap-server element above  -->
<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldap://localhost:33389/dc=springframework,dc=org"/>
</bean>

<bean id="secondLdapProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg>
        <bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
            <constructor-arg ref="contextSource" />
            <property name="userSearch">
                <bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
                  <constructor-arg index="0" value="ou=people"/>
                  <constructor-arg index="1" value="(uid={0})"/>
                  <constructor-arg index="2" ref="contextSource" />
                </bean>
            </property>
        </bean>
    </constructor-arg>
    <constructor-arg>
        <bean class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
            <constructor-arg ref="contextSource" />
            <constructor-arg value="ou=groups" />
            <property name="groupSearchFilter" value="(member={0})"/>
            <property name="rolePrefix" value="ROLE_"/>
            <property name="searchSubtree" value="true"/>
            <property name="convertToUpperCase" value="true"/>
        </bean>
    </constructor-arg>
</bean>

和 struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
 <struts-config>

<form-beans>
    <form-bean name="helloForm" type="com.form.HelloForm"/>
</form-beans>   

<action-mappings>
    <action path="/helloForm" type="com.action.HelloAction" name="helloForm">
        <forward name="success" path="/secure/helloForm.jsp" />
    </action>
</action-mappings> 
</struts-config>

和 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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" version="2.4">
<servlet>
    <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>                   
    <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>



<display-name>Spring Security LDAP Demo Application</display-name>

<!--
  - Location of the XML file that defines the root application context
  - Applied by ContextLoaderListener.
  -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/applicationContext-security.xml
        /WEB-INF/struts-config.xml
    </param-value>
</context-param>

<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>ldap.root</param-value>
</context-param>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

<!--
  - Loads the root application context of this web app at startup.
  - The application context is then available via
  - WebApplicationContextUtils.getWebApplicationContext(servletContext).
-->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> 
</web-app>

在我的index.jsp中

<p><a href="secure/index.jsp">Secure page</a></p>
<p><a href="secure/extreme/index.jsp">Extremely secure page</a></p>

所以当我尝试访问安全时 春季安全工作正常,当我成功登录但是 在安全/index.jsp 我用<jsp:forward page="/helloForm.do"></jsp:forward>

和 helloForm.jsp

<body>
<h1>
    <bean:write name="helloForm" property="message" />

</h1>
<h2>Hello and Welcome</h2>
</body>

当我运行它时

i show

您好,欢迎光临,但我无法收到在 FormAction 中设置的 actionForm 消息

public class HelloAction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // TODO Auto-generated method stub

    HelloForm helloForm = new HelloForm();
    helloForm.setMessage("Welcome this is secure page");

    return mapping.findForward("success");
}
}

你正在创建一个新的HelloForm,设置它的值,并且绝对不做任何其他事情——该表单将被垃圾收集,并且再也不会出现。

使用传递给操作的表单,form范围。将其投射到HelloForm,填写该值,并返回前向。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Security 与 Struts 的集成 的相关文章

  • 从SQLite列中获取所有数字字符串并进行总和计算

    我是 Android 和 SQLite 的新手 我在 SQLite 中有一个只有数字的 AMOUNT 列 我可以在 ListView 中显示它 但我无法找到任何我理解的方法来将它们全部添加并显示在 TextView 中 这是数据库助手 im
  • Spring MVC - 自动查找验证器

    假设我有一个像这样的示例实体类 public class Address 和相应的验证器 Component public AddressValidator implements Validator Override public bool
  • Mediaplayer 播放几次后停止播放

    我有一个按钮 按下它会播放一个随机声音剪辑 然后播放另一个声音剪辑 然后通过一个媒体播放器播放另一个声音剪辑 但是多次按下该按钮 15 20 次 后 所有音频都会停止 我在播放最后一个音频剪辑后释放媒体播放器 所以我不认为这是原因 有什么指
  • 如何访问EmbeddedSolrServer实例的管理界面?

    在我的网络应用程序中 我正在运行org apache solr client solrj embedded EmbeddedSolrServer出于调试目的 我想访问管理界面 这就是我实例化服务器的方式 new EmbeddedSolrSe
  • Java:等于和==

    让我们看看我们有 2 个对用户定义类实例的引用 即 Java 中的 a 和 b 会不会有一种情况 a b 但 a equals b 返回 false 当然 实施 equals 完全取决于班级 所以我可以写 class Foo public
  • JSF-2 应用程序中的服务器端计时器

    在我正在开发的 JSF 2 应用程序中 当用户执行操作时 我需要启动服务器端计时器 这个计时器必须与应用程序本身相关 因此它必须在用户会话关闭时继续存在 为了解决这个问题 我想使用 java util Timer 类在应用程序范围的 bea
  • Java:将二维字符串数组打印为右对齐表格

    是什么best打印a的单元格的方法String 数组作为右对齐表 例如 输入 x xxx yyy y zz zz 应该产生输出 x xxx yyy y zz zz 这似乎是一个should能够完成使用java util Formatter
  • Android Studio:如果设置项目的背景颜色,ListView OnClick 动画将不起作用

    在我的项目中 我在 ListView 内设置了项目 由插入 ConstraintLayout 中的多个元素组成 的背景颜色 但如果背景颜色不是至少一点透明 则单击和长按的默认动画会消失 事实上 随着透明度的降低 点击元素的效果越来越不明显
  • python 中的子进程调用以使用 JAVA_OPTS 调用 java jar 文件

    示例代码 import subprocess subprocess call java jar temp jar 如何在上面的命令中指定JAVA OPTS 当我使用上述命令时 我收到 java lang OutOfMemoryError 无
  • 如何组合 3 个或更多 CompletionStages?

    如果有 2 个 CompletionStages 我可以将它们与thenCombine method CompletionStage a aCompletionStage getA CompletionStage b bCompletion
  • Spring Boot 中 application.properties 可用的属性列表?

    Spring Boot文档说我们可以在application properties文件中设置属性 但我找不到列出可以设置的可用属性的文档 我在哪里可以找到这样的文档 例如 我想为嵌入式servlet设置documentRoot 我发现set
  • Java:如果数组大小未知,如何初始化?

    我要求用户输入 1 到 100 之间的一些数字并将它们分配到一个数组中 数组大小未初始化 因为它取决于用户输入数字的次数 我应该如何分配数组长度 如果用户输入 5 6 7 8 9 5 个数字 则 int list becomes int l
  • SwingUtilities.invokeLater

    我的问题与SwingUtilities invokeLater 我应该什么时候使用它 每次需要更新 GUI 组件时都必须使用吗 它到底有什么作用 是否有替代方案 因为它听起来不直观并且添加了看似不必要的代码 Do I have to use
  • Java/Hibernate - 异常:内部连接池已达到其最大大小,当前没有可用的连接

    我第一次在大学项目中使用 Hibernate 而且我还是个新手 我想我遵循了我的教授和我阅读的一些教程给出的所有指示 但我不断收到标题中的异常 Exception in thread main org hibernate Hibernate
  • 图标和导航视图之间的左边距

    我必须在图标和图标之间添加左边距NavigationView 如下图中箭头所示 我知道根据谷歌规范 这个边距必须有16dp但我需要改变它 我努力了
  • AWS SQS Batch SendMessageBatchRequest 非常慢

    我的应用程序使用 SendMessageBatchRequest 将每个请求发布 10 条消息到 AWS SQS 每条消息的大小小于250字节 该应用程序预计每天发布约一百万条记录 但要实现这一目标 消息发布的速度非常慢 AmazonSQS
  • 隐藏 JTable 临时列

    我正在使用 JTable 显示数据库中的数据 现在我想通过 Jcombobox 过滤我的 jtable 我正在使用 Jcombo 框 其中包含 030 024 045 等值 这些值已在 jtable 中设置为列标题 当我单击组合时 选定的列
  • Spring Data MongoDB 和批量更新

    我正在使用 Spring Data MongoDB 并且想要执行批量更新 就像此处描述的那样 http docs mongodb org manual reference method Bulk find update Bulk find
  • Swing GUI 出现 IntelliJ 错误“contentPane 无法设置为 null。”从终端编译时

    当我从 IntelliJ 编译我的项目时 没有任何问题 我的程序运行顺利 但是当我尝试使用 javac 从终端编译它时 警告 注意 Victor presentation TableControllerMenu java 使用未经检查或不安
  • 如何在 tomcat 上部署 Java Web 应用程序 (.war)?

    我有一个 warJava Web 应用程序的文件 现在我想将它上传到我的 ftp 服务器 以便我可以执行它 我应该执行哪些步骤来运行它 webapp的上下文路径是 mywebapp Edit 实际上 我的 ftp 服务器名称是ftp bil

随机推荐

  • 基于行内 NA 数量的条件行删除

    我希望根据以下两个条件从数据集中删除行 如果有 3 个连续单元格 则删除行NA or 如果有四个或更多单元格NA 我的样本数据 data lt rbind c 1 1 2 3 4 2 3 2 c NA 1 NA 4 1 1 NA 2 c 1
  • NSMenuItem 的选择器放置在哪里

    我试图理解 Cocoa 中的一些事情 但我陷入了一件事 我正在跟进简约的 Cocoa 编程 http cocoawithlove com 2010 09 minimalist cocoa programming html 那里有一个NSMe
  • 为什么我们要把一个mysql表分成许多更小的表?

    这似乎是一种常见的做法divide the data of one table into many databases many tables为了提高性能 我可以理解many databases部分原因是更多的数据库提供了更多的CPU 更多
  • matplotlib 补丁集合中的 Zorder 规范?

    我正在尝试绘制一系列矩形和圆形 其中圆形位于前景中 根据以下帖子 我必须设置 zorder 参数 我添加到图表中的补丁在 alpha 1 时不是不透明的 为什么 https stackoverflow com questions 53906
  • 使用复选框从 jquery 自动完成中选择多个选项

    我正在与jquery 自动完成 https jqueryui com autocomplete 我正在尝试以下代码 Html
  • 尝试保存其他实体时 Doctrine 事件侦听器中的无限循环

    我希望每次新的时候Distance保存实体 从 Place A 到 Place B 反向距离 从 Place B 到 Place A 也被插入到数据库中 https stackoverflow com q 30569463 2516943
  • 给定一个数字,找到与原始数字具有完全相同的数字组的下一个更高的数字

    我刚刚搞砸了一次面试 并且在面试问题上几乎取得了零进展 给定一个数字 找到下一个具有完全相同的数字 一组数字作为原始数字 例如 给出 38276 返回 38627 我想首先找到小于个位的第一个数字 从右侧 的索引 然后我会旋转子集中的最后一
  • android parse.com 保存安装错误。找不到要更新的对象

    我在下面收到此错误 但不知道该怎么办 我什至不知道要在这里发布什么代码 因为我似乎找不到代码中导致此错误的位置 还有一件更重要的事情要提 这个错误不会发生在我的第一个测试设备 运行 Android 4 0 4 的 HTC难以置信 上 但我的
  • Spring 返回 HTTP 406 的 JSON (NOT_ACCEPTABLE)

    Spring允许定义 ExceptionHandlers代替 RestControllerAdvice 我已经定义了很多其他的ExceptionHandlers其中适用于 HTTP 400 404 405 但是 HTTP 406 NOT A
  • 读取所有注册表值的快速方法

    我正在编写一个实用程序 需要创建 HKCR 中所有注册表值的列表 我使用递归函数来执行此操作 var list new Dictionary
  • jQuery 不调用 php

    由于某种原因 jQuery 没有加载我的 php 文件 单击该按钮 页面就会刷新 我已经验证 jQuery 可以正常工作 并且单击功能也可以正常工作 一旦到达 post它似乎没有调用该文件并经历暂停并回显结果 该目录对于 php 文件是正确
  • 获取最小时差

    我最近在一次编码面试中被问到这个问题 我得到了一系列 HH MM 格式的时间 我需要找到以分钟为单位的最小时差 时间本质上是循环的 因此 23 55 和 00 12 应该相差 17 该函数还需要将 00 00 处理为与 24 00 相同的东
  • 将文件从 HDFS 复制到本地计算机

    我在尝试将文件从 HDFS 文件系统 下载 到本地系统时遇到问题 即使相反的操作没有问题 注意 文件存在于 HDFS 文件系统的指定路径上 这是一个代码片段 Configuration conf new Configuration conf
  • 如何在 Typescript 中使用 Cytoscape.js 的 UI 扩展?

    是否可以在 Typescript 中使用 Cytoscape UI 扩展 可以使用布局扩展 但是当我需要时https github com cytoscape cytoscape js cxtmenu https github com cy
  • 在散景 vbar 工具提示中显示高度

    我想制作一些简单数据的条形图 例如像这样的 pandas 数据框 Cats 4 Dogs 3 Mice 27 我想要一个工具提示 当鼠标悬停在栏上时显示如下内容 Name Cats Count 4 对于条形图 这适用于 hover tool
  • 在 Java 中通过引用传递数组

    在Java中可以将数组作为参数传递吗 int 5 result 我想传递对数组的引用 因为我想更改调用函数中的数组 语法是什么 private void demo int array new int 5 System out println
  • 无法部署firebase功能

    Node js 命令提示符只是忽略此函数 而其他函数正在部署 我也没有收到任何错误 var database admin database var postsRef database ref posts postsRef on child
  • PyInstaller - FileNotFoundError:没有这样的文件或目录:“”

    我看过很多关于这个完全相同的错误代码的帖子 但有许多不同的答案 但我仍然无法解决我的问题 我的帖子与所有其他帖子的不同之处在于我得到以下内容 317 INFO Building PKG because PKG 00 toc is non e
  • 使用 pyodbc 从 Python 应用程序将值插入 Access 2003 数据库

    我过去经常检查 stackoverflow 并且总是能够找到我一直在寻找的东西 但我似乎无法让这个工作 所以我问我的第一个问题 我并不是一个真正的程序员 但我在工作中提到过Python 现在我有一个Python项目 实际上 我已经把一切都弄
  • Spring Security 与 Struts 的集成

    我正在尝试在一个简单的应用程序中将 spring security 与 struts1 2 使用 LDAP 集成 我有 applicationContext security xml