Skip to content

Commit a9d7e67

Browse files
working on #155
1 parent dcc793f commit a9d7e67

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,10 @@
8080
<groupId>org.springframework.boot</groupId>
8181
<artifactId>spring-boot-starter-integration</artifactId>
8282
</dependency>
83-
<!--
8483
<dependency>
8584
<groupId>org.springframework.boot</groupId>
8685
<artifactId>spring-boot-starter-security</artifactId>
8786
</dependency>
88-
-->
8987
<dependency>
9088
<groupId>org.springframework.boot</groupId>
9189
<artifactId>spring-boot-starter-mobile</artifactId>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.woehlke.twitterwall.conf;
2+
3+
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
10+
11+
@Configuration
12+
@EnableWebSecurity
13+
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
14+
15+
@Override
16+
protected void configure(HttpSecurity http) throws Exception {
17+
http
18+
.authorizeRequests()
19+
.antMatchers("/", "/tweet/all","/user/tweets","/hashtag/overview","/imprint","/user/*","/hashtag/*","/css/**","/favicon/**","/js","/map-icons","/webjars/**").permitAll()
20+
.anyRequest().authenticated()
21+
.and()
22+
.formLogin()
23+
.loginPage("/login")
24+
.permitAll()
25+
.and()
26+
.logout()
27+
.permitAll();
28+
}
29+
30+
@Autowired
31+
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
32+
auth
33+
.inMemoryAuthentication()
34+
.withUser("user").password("password").roles("USER");
35+
}
36+
}

src/main/java/org/woehlke/twitterwall/frontend/controller/PagesController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ public ModelAndView index(Model model) {
2626
return new ModelAndView("redirect:/tweet/all");
2727
}
2828

29+
@RequestMapping("/login")
30+
public String login(Model model) {
31+
log.info("-----------------------------------------");
32+
String symbol = Symbols.LEAF.toString();
33+
String title = "Login";
34+
String subtitle = "Enter your Credentials";
35+
model = controllerHelper.setupPage(model, title, subtitle, symbol);
36+
log.info("-----------------------------------------");
37+
return "login";
38+
}
39+
2940
@RequestMapping("/imprint")
3041
public String imprint(Model model) {
3142
log.info("-----------------------------------------");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
3+
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
4+
<head>
5+
<title>Spring Security Example </title>
6+
</head>
7+
<body>
8+
<div th:if="${param.error}">
9+
Invalid username and password.
10+
</div>
11+
<div th:if="${param.logout}">
12+
You have been logged out.
13+
</div>
14+
<form th:action="@{/login}" method="post">
15+
<div><label> User Name : <input type="text" name="username"/> </label></div>
16+
<div><label> Password: <input type="password" name="password"/> </label></div>
17+
<div><input type="submit" value="Sign In"/></div>
18+
</form>
19+
</body>
20+
</html>

0 commit comments

Comments
 (0)