我对Spring模拟用户没有任何了解.
我已经通过一些示例代码来模拟用户,并注意到SwitchUserFilter用于此实现.
如何使用Spring SwitchUserFilter Filter实现模拟用户以及它是如何工作的?冒充用户的内部流程是什么?
在我的应用程序中,我也使用spring security.
任何人都可以通过简单的描述或任何示例来帮助我实现这一目标吗?
我需要一种加密算法,我可以将数据加密为简单的纯文本。
目前我正在使用AES 加密算法,该算法转换为包含特殊字符的加密字符串。
在这里,如果我通过 url 中的查询字符串发送这个字符串,我会丢失一些像“+”这样的字符。
所以我需要一个安全且仅包含字母表的加密逻辑。
这是我的加密逻辑:
public static String encrypt(String Data) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encVal = c.doFinal(Data.getBytes());
String encryptedValue = new BASE64Encoder().encode(encVal);
return encryptedValue;
}
@SuppressWarnings("restriction")
public static String decrypt(String encryptedData) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.DECRYPT_MODE, key);
byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData);
byte[] decValue = c.doFinal(decordedValue);
String decryptedValue = new String(decValue);
return decryptedValue;
}
Run Code Online (Sandbox Code Playgroud)
在这里我得到一个加密的字符串“ TEj+TWBQExpz8/p5SAjIhA== …
当我运行mvn安装时,我能够找到上面的错误.
这是我配置JUnit的POM.xml.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这是服务测试类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ServiceTestCase {
protected static final Logger LOG = Logger.getLogger(ServiceTestCase.class);
@Configuration
static class AccountServiceTestContextConfiguration {
....
....
....
}
Run Code Online (Sandbox Code Playgroud)
在编译上面的错误时,我得到了.这个我在src/test/java中创建的Test类
任何人都可以建议.怎么解决这个?
当我删除我收到错误,因为@Test无法识别.
这是我的文件夹结构 -
![Project explorer][1]
--project>
--src
--main
--java
--resource
--target
pom.xml
Run Code Online (Sandbox Code Playgroud)
这是我的 Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mkyong</groupId>
<artifactId>spring-security-loginform-xml</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>SpringSecurity Custom Login Form XML</name>
<url>http://www.mkyong.com/tutorials/spring-security-tutorials/</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>mkyong</id>
<name>Yong Mook Kim</name>
<email>mkyong2002@gmail.com</email>
</developer>
</developers>
<properties>
<jdk.version>1.6</jdk.version>
<spring.version>3.2.8.RELEASE</spring.version>
<spring.security.version>3.2.3.RELEASE</spring.security.version>
<jstl.version>1.2</jstl.version>
</properties>
<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency> …Run Code Online (Sandbox Code Playgroud) 我正在使用 spring 提供的切换用户过滤器来模拟用户。
如何获取在 SwitchUserFilter 中模拟的原始用户。
我正在做的步骤:
前任。
1. Log in with User1
2. Impersonting to the User2. (user1 impersonate User2)
3. In Filter I am getting **authentication.getName()** as **User2**
4. While switching back to Original I am getiing **authentication.getName()** as **Null**
Run Code Online (Sandbox Code Playgroud)
现在我的需要是我想在 swtichback 时在过滤器中获取原始用户(User1)。
有没有可能。
请建议。让我知道有人需要更多输入。请给出意见。
提前致谢。
/Login如果用户没有输入有效凭据,它如何重定向URL ?我有一个名为
public class Customer implements Auditable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "SellerID")
private Long id;
@Embedded
private AuditSection auditSection = new AuditSection();
......
......
}
@Embeddable
public class AuditSection implements Serializable {
private static final long serialVersionUID = -1934446958975060889L;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DateCreated")
private Date dateCreated;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DateModified")
private Date dateModified;
......
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 criteriaBuilder 和谓词进行搜索
predicates.add(criteriaBuilder.and(criteriaBuilder.notEqual(root.get("modifiedDate"), new Date)));
Run Code Online (Sandbox Code Playgroud)
在这里我得到了异常
org.springframework.dao.InvalidDataAccessApiUsageException: Unable to locate Attribute with the the given name [modifiedDate] on this ManagedType [unknown]; nested …Run Code Online (Sandbox Code Playgroud) maven ×2
aes ×1
criteria-api ×1
encryption ×1
hibernate ×1
java ×1
junit4 ×1
magnolia ×1
spring ×1
spring-mvc ×1