我使用的是Spring安全版3.1.4.RELEASE.如何访问当前登录的用户对象?
SecurityContextHolder.getContext().getAuthentication().getPrinciple()
Run Code Online (Sandbox Code Playgroud)
返回用户名,而不是用户对象.那么如何使用返回的用户名并获取UserDetails对象?
我试过以下代码:
public UserDetails getLoggedInUser(){
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null && auth.isAuthenticated() && !(auth instanceof AnonymousAuthenticationToken))
{
if(auth.getDetails() !=null)
System.out.println(auth.getDetails().getClass());
if( auth.getDetails() instanceof UserDetails)
{
System.out.println("UserDetails");
}
else
{
System.out.println("!UserDetails");
}
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
以下是结果:
[2015-08-17 19:44:46.738] INFO http-bio-8443-exec-423 System.out class org.springframework.security.web.authentication.WebAuthenticationDetails
[2015-08-17 19:44:46.738] INFO http-bio-8443-exec-423 System.out !UserDetails
Run Code Online (Sandbox Code Playgroud)
AuthenticationFilter类如下:
public class CustomUsernamePasswordAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
public static final String SPRING_SECURITY_FORM_USERNAME_KEY = "j_username";
public static final String SPRING_SECURITY_FORM_PASSWORD_KEY = "j_password";
public static final String …
Run Code Online (Sandbox Code Playgroud) 一旦Java Swing应用程序从Java 6 32位转移到Java 7 32位更新11,我们就会遇到性能问题.任何人都可以提供一些线索吗?
该应用程序使用Java Web-start技术,服务器是Tomcat 7.客户端应用程序占用1GB内存,因此屏幕冻结.
我们正在交换序列化对象,以下是代码:
Object object = connection.sendCommand(command); // exchanging serialized object
public class ConnectionImpl implements Connection {
public Object sendCommand(Command command) throws Exception {
URL url = new URL(System.getProperty("serverUrl"));
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
oos = new ObjectOutputStream(new BufferedOutputStream(connection
.getOutputStream()));
oos.writeObject(command);
oos.flush();
InputStream inputStream = connection.getInputStream();
ZipInputStream zip = new ZipInputStream(inputStream);
if (zip.getNextEntry() != null) {
ois = new ObjectInputStream(zip);
object = ois.readObject();
}
zip.close();
}
}
// The serialized class …
Run Code Online (Sandbox Code Playgroud) 我正在尝试按顺序实现乐观锁定以避免丢失更新情况.在我的应用程序中,两个用户获取相同的记录,第一个用户通过一些更改更新它.查看相同记录的第二个用户看不到此更改,他自己进行了一些更改并对其进行了更新.由此导致第一批人员失去了.为了防止这种情况,我写了以下内容,但问题仍然存在.我是这个概念的新手,无法识别问题.
我试图通过阅读doc 11.3.4 来实现这一目标.自定义自动版本控制部分.
配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>server.bo.Dept</value>
<value>server.bo.Emp</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="deptDAO" class="server.dao.DeptDAOImpl">
<property …
Run Code Online (Sandbox Code Playgroud)是否有任何开源java库可以解析ANSI X12和UN/EDIFACT标准中的EDI文件?我找到了smooks(http://www.smooks.org),它支持UN/EDIFACT标准但不确定这是否支持ANSI X12标准的EDI文件.
提前致谢.
我是单点登录概念的新手.我们已经有一个管理其用户的Java Web应用程序.现在要求验证将由客户端的SSO Idp(使用SAML)提供,之后请求将转发到我们的应用程序.由于我之前没有实现过这样的任何内容,因此我需要澄清以下查询以继续进行:
客户端有一个内部应用程序,它包含许多应用程序的链接,这些应用程序使用相同的SSO IdP.用户无法直接访问互联网.
任何有助于我理解从IdP方面发起的SSO的教程或起点都会有所帮助.
谢谢.
当我尝试.html()
在JQuery中使用方法插入空间时,我遇到了问题.以下是我的代码:
html += '<td >'+description+". "+location;
html += +" "+position;
html += +" "+side+'</td>';
$('#tempResult').html(html);
Run Code Online (Sandbox Code Playgroud)
我得到的结果如下:
Green Tint. 0FrontNaNRight