Skip to content

Commit 1696627

Browse files
author
eugenp
committed
security work
1 parent 56c520a commit 1696627

4 files changed

Lines changed: 51 additions & 20 deletions

File tree

spring-security-custom/src/main/java/org/baeldung/spring/MvcConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public MvcConfig() {
2323
public void addViewControllers(final ViewControllerRegistry registry) {
2424
super.addViewControllers(registry);
2525

26-
// registry.addViewController("/login.html");
26+
registry.addViewController("/login.html");
2727
registry.addViewController("/homepage.html");
2828
}
2929

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
3-
xmlns:sec="http://www.springframework.org/schema/security"
43
xsi:schemaLocation="
5-
http://www.springframework.org/schema/security
6-
http://www.springframework.org/schema/security/spring-security-3.1.xsd
7-
http://www.springframework.org/schema/beans
8-
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
4+
http://www.springframework.org/schema/security
5+
http://www.springframework.org/schema/security/spring-security-3.1.xsd
6+
http://www.springframework.org/schema/beans
7+
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
98

10-
<http use-expressions="true" entry-point-ref="restAuthenticationEntryPoint">
11-
<intercept-url pattern="/api/**" access="isAuthenticated()" />
9+
<http use-expressions="true">
10+
<intercept-url pattern="/anonymous*" access="isAnonymous()" />
11+
<intercept-url pattern="/login*" access="permitAll" />
12+
<intercept-url pattern="/**" access="isAuthenticated()" />
1213

13-
<sec:form-login authentication-success-handler-ref="mySuccessHandler" />
14+
<form-login login-page='/login.html' login-processing-url="/perform_login" default-target-url="/homepage.html" authentication-failure-url="/login.html?error=true"
15+
always-use-default-target="true" />
1416

15-
<logout />
1617
</http>
1718

18-
<beans:bean id="mySuccessHandler" class="org.baeldung.security.MySavedRequestAwareAuthenticationSuccessHandler" />
19-
2019
<authentication-manager>
21-
<authentication-provider ref="customAuthenticationProvider" />
20+
<authentication-provider>
21+
<user-service>
22+
<user name="user1" password="user1Pass" authorities="ROLE_USER" />
23+
</user-service>
24+
</authentication-provider>
2225
</authentication-manager>
2326

27+
<!-- <authentication-manager> -->
28+
<!-- <authentication-provider ref="customAuthenticationProvider" /> -->
29+
<!-- </authentication-manager> -->
30+
2431
</beans:beans>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<html>
2+
<head></head>
3+
4+
<body>
5+
<h1>Login</h1>
6+
7+
<form name='f' action="perform_login" method='POST'>
8+
9+
<table>
10+
<tr>
11+
<td>User:</td>
12+
<td><input type='text' name='j_username' value=''></td>
13+
</tr>
14+
<tr>
15+
<td>Password:</td>
16+
<td><input type='password' name='j_password' /></td>
17+
</tr>
18+
<tr>
19+
<td><input name="submit" type="submit" value="submit" /></td>
20+
</tr>
21+
</table>
22+
23+
</form>
24+
25+
</body>
26+
</html>

spring-security-login/src/main/resources/webSecurityConfig.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
<beans:beans xmlns="http://www.springframework.org/schema/security"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
44
xsi:schemaLocation="
5-
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
6-
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
5+
http://www.springframework.org/schema/security
6+
http://www.springframework.org/schema/security/spring-security-3.1.xsd
7+
http://www.springframework.org/schema/beans
8+
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
79

8-
<debug/>
9-
1010
<http use-expressions="true" >
1111
<intercept-url pattern="/anonymous*" access="isAnonymous()" />
12-
1312
<intercept-url pattern="/login*" access="permitAll" />
14-
1513
<intercept-url pattern="/**" access="isAuthenticated()" />
1614

1715
<form-login
@@ -28,7 +26,7 @@
2826

2927
</http>
3028

31-
<beans:bean name="customLogoutSuccessHandler" class="org.baeldung.spring.security.CustomLogoutSuccessHandler" />
29+
<beans:bean name="customLogoutSuccessHandler" class="org.baeldung.security.CustomLogoutSuccessHandler" />
3230

3331
<authentication-manager>
3432
<authentication-provider>

0 commit comments

Comments
 (0)