Tag: spring

使用spring安全性以编程方式login用户

与之相反的是: 如何用spring security手动注销用户? 在我的应用程序中,我已经注册了新的用户屏幕 ,它发布到一个控制器,在数据库中创build一个新的用户(并做了一些明显的检查)。然后,我希望这个新用户自动login…我有点想喜欢这个 : SecurityContextHolder.getContext().setPrincipal(MyNewUser); 编辑好我几乎已经实现了基于如何以编程方式用Spring Security 3.1login用户的答案 Authentication auth = new UsernamePasswordAuthenticationToken(MyNewUser, null); SecurityContextHolder.getContext().setPrincipal(MyNewUser); 但是,当部署时,jsp无法访问我的MyNewUser.getWhateverMethods()而在正常的login过程之后。 通常工作的代码,但是如上所示login时抛出错误如下: <sec:authentication property="principal.firstname" />

在spring引导中将属性放在application.yml或bootstrap.yml之间有什么不同?

在spring引导中将属性放在application.yml或bootstrap.yml之间有什么不同? 在logging.config的情况下,应用程序工作不同。

无法findXML模式命名空间的Spring NamespaceHandler

我正在开发我的第一个应用程序在春季安全。 我的applicationContext-security.xml文件看起来像这样: <?xml version="1.0" encoding="UTF-8"?> <!– – Namespace-based OpenID configuration –> <b:beans xmlns="http://www.springframework.org/schema/security" xmlns:b="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 http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> <http> <intercept-url pattern="/**" access="ROLE_USER"/> <intercept-url pattern="/index.xhtml*" filters="none"/> <logout/> <openid-login login-page="/index.xhtml" authentication-failure-url="/index.xhtml?login_error=true"> <attribute-exchange> <openid-attribute name="email" type="http://schema.openid.net/contact/email" required="true" count="2"/> <openid-attribute name="name" type="http://schema.openid.net/namePerson/friendly" /> </attribute-exchange> </openid-login> <remember-me token-repository-ref="tokenRepo"/> </http> <b:bean id="tokenRepo" class="org.springframework.security.web.authentication.rememberme.InMemoryTokenRepositoryImpl" /> <authentication-manager alias="authenticationManager"/> <user-service id="userService"> <user name="http://user.myopenid.com/" […]

在Spring MVC控制器中从安全上下文获取UserDetails对象

我正在使用Spring Security 3和Spring MVC 3.05。 我想打印当前login用户的用户名,我如何获取UserDetails在我的控制器? @RequestMapping(value="/index.html", method=RequestMethod.GET) public ModelAndView indexView(){ UserDetails user = ? mv.addObject("username", user.getUsername()); ModelAndView mv = new ModelAndView("index"); return mv; }

Spring – 基于注释的控制器 – 基于查询string的RequestMapping

在基于Spring注解的控制器中,是否可以使用@RequestMapping将不同的查询string映射到不同的方法? 例如 @RequestMapping("/test.html?day=monday") public void writeMonday() { } @RequestMapping("/test.html?day=tuesday") public void writeTuesday() { }

Spring RestTemplate超时

我想为我的Web应用程序使用的其他服务设置连接超时。 我正在使用Spring的RestTemplate与我的服务交谈。 我已经做了一些研究,我已经find并使用下面的XML(在我的应用程序的XML),我相信是用来设置超时。 我正在使用Spring 3.0。 我也看到了同样的问题在这里用RestTemplate的springwebservices超时configuration,但解决scheme似乎并不干净 ,我宁愿设置超时值通过Springconfiguration <bean id="RestOperations" class="org.springframework.web.client.RestTemplate"> <constructor-arg> <bean class="org.springframework.http.client.CommonsClientHttpRequestFactory"> <property name="readTimeout" value="${restURL.connectionTimeout}" /> </bean> </constructor-arg> </bean> 看来无论我设置readTimeout是我得到以下内容: 网线断开:等待约20秒,并报告以下exception: org.springframework.web.client.ResourceAccessExcep tion:I / O错误:没有路由到主机:连接; 嵌套exception是java.net.NoRouteToHostException:没有路由到主机:连接 Url不正确,所以404由rest服务返回:等待大约10秒,并报告以下exception: org.springframework.web.client.HttpClientErrorException:404 Not Found 我的要求要求更短的超时,所以我需要能够改变这些。 任何想法,我做错了什么? 非常感谢。

有没有办法来避免Tomcat的解除部署内存泄漏?

这个问题对于任何曾经testing过Tomcatpipe理器中的“Find leaks”button的人来说都是这样的: 以下Web应用程序已停止(重新加载,取消部署),但其以前运行的类仍然加载到内存中,从而导致内存泄漏(使用分析器进行确认): /漏的应用程序名称 我认为这与您经常重新部署时经常遇到的“Perm Gen空间”错误有关。 所以当我部署的时候我在jconsole中看到的是我的加载类从大约2k到5k。 那么你会认为一个部署会让他们回到2K,但他们仍然在5K。 我也试过使用下面的JVM选项: -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled 我看到使用Perm Gen空间的次数非常less,但不是我所期望的,而且加载的类数没有下降。 那么有没有一种方法来configurationTomcat或devise你的应用程序卸载更好地卸载? 还是我们坚持重新启动服务器后,一些主要的debugging会议? Tomcat版本输出: 服务器版本:Apache Tomcat / 6.0.29 build立的服务器:2010年7月19日1458 服务器号码:6.0.0.29 操作系统名称:Windows 7 操作系统版本:6.1 架构:x86 JVM版本:1.6.0_18-b07 JVM供应商:Sun Microsystems Inc. 更新: 感谢celias的回答,我决定做更多的挖掘工作,我想我已经确定了罪魁祸首是由于CXF,Spring和JAXB。 在学习了如何configurationJava应用程序之后,我将分析器指向了Tomcat,并采取了一些堆转储和快照来查看内存中对象和类的内容。 我发现在我的CXF / JAXB(wsdl2java)生成的类中使用的XML模式中的一些枚举在部署之后仍然存在。 根据我的堆转储它看起来像对象被绑定到一个地图。 免责声明:我承认我仍然有点绿色与分析和追踪对象的调用树可以在Java中具有挑战性。 另外我应该提到,我甚至没有调用服务,只是部署,然后取消部署。 这些对象本身似乎是通过部署时从Spring发起的reflection来加载的。 我相信我遵循了在春季build立CXF服务的惯例。 所以我不是100%确定这是Spring / CXF,JAXB还是reflection的错误。 作为一个方面的说明:有问题的应用程序是使用Spring / CXF的Web服务,而XML恰好是一个相当复杂的模式( NIEM的扩展)。

ApplicationContextAware在Spring中如何工作?

在spring,如果一个bean实现了ApplicationContextAware ,那么它就可以访问applicationContext 。 所以它能够得到其他的豆子。 例如 public class SpringContextUtil implements ApplicationContextAware { private static ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext context) throws BeansException { applicationContext = context; } public static ApplicationContext getApplicationContext() { return applicationContext; } } 然后SpringContextUtil.getApplicationContext.getBean("name")可以获得bean“name”。 为了做到这一点,我们应该把这个SpringContextUtil放在applications.xml ,例如 <bean class="com.util.SpringContextUtil" /> 这里bean SpringContextUtil不包含属性applicationContext 。 我猜Spring bean初始化的时候,这个属性是设置的。 但是,这是如何完成的? setApplicationContext如何被调用?

spring – 是否有可能在同一个应用程序中使用多个事务pipe理器?

我是Spring的新手,我想知道是否可以在同一个应用程序中使用众多的事务pipe理器? 我有两个数据访问层 – 一个用于两个数据库。 我想知道,你如何去使用一个事务pipe理器的一层和不同的事务pipe理器的另一层。 我不需要在两个数据库之间执行事务。 但我确实需要单独对每个数据库执行事务。 我已经创build了一个图像来帮助概述我的问题: 这是我的应用程序上下文configuration: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:component-scan base-package="cheetah.repositories" /> <tx:annotation-driven /> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="persistenceUnitName" value="accounts" /> </bean> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> </beans> 以下是使用此configuration的示例: @Repository public class JpaAccountRepository implements AccountRepository { @PersistenceContext(unitName = […]

Spring Data JPA通过embedded对象属性来查找

我想编写一个Spring Data JPA存储库接口方法签名,它使我能够在该实体中find具有embedded对象属性的实体。 有谁知道这是可能的,如果是的话,怎么样? 这是我的代码: @Entity @Table(name = "BOOK_UPDATE_QUEUE", indexes = { uniqueConstraints = @UniqueConstraint(columnNames = { "bookId", "region" }, name = "UK01_BOOK_UPDATE_QUEUE")) public class QueuedBook implements Serializable { @Embedded @NotNull private BookId bookId; … } @Embeddable public class BookId implements Serializable { @NotNull @Size(min=1, max=40) private String bookId; @NotNull @Enumerated(EnumType.STRING) private Region region; … […]