Skip to content

Commit 87e7b66

Browse files
SeunMattpivovarit
authored andcommitted
Added Complete Source Code for VRaptor BAEL-1214 (eugenp#3237)
* added updated example codes * updated example code StringToCharStream * deleted StringToCharStream.java locally * removed redundant file * added code for apache commons collection SetUtils * refactored example code * added example code for bytebuddy * added example code for PCollections * update pom * refactored tests for PCollections * spring security xml config * spring security xml config * remove redundant comment * example code for apache-shiro * updated example code for Vavr Collections * updated Vavr's Collection example * updated Vavr Collection file * updated example code for Apache Shiro * updated Vavr Collections example * added example code for N1QL * update example code for N1QL * added integration test for N1QL * update N1QL Example code * update the N1QL example Code * rename module to couchbase * rename module to couchbase * change module name in parent module and pom * added cas-server module * added cas secured app for Spring SSO with CAS * refactor cas modules into cas folder * updated files * removed redundant files * refactor the config for cas-server * added sql file to generate tables and database * added source code for VRaptor * update source code for VRaptor article * update pom and reformat code
1 parent 3bcff46 commit 87e7b66

82 files changed

Lines changed: 29937 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
<module>deeplearning4j</module>
265265
<module>spring-boot-admin</module>
266266
<module>lucene</module>
267+
<module>vraptor</module>
267268
</modules>
268269

269270
<dependencies>

‎vraptor/.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
/target/
3+
/.idea/
4+
/src/main/webapp/WEB-INF/classes/

‎vraptor/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# VRaptor blank project
2+
3+
This is a blank project to help you to use VRaptor. You can easily import in you IDE as Maven project.
4+
5+
Este é um projeto em branco para ajudar você a usar o VRaptor. Você pode facilmente importá-lo na sua IDE favorita como um projeto Maven.
6+
7+
Após criar seu projeto você pode rodá-lo com um tomcat7 ou +:
8+
9+
```
10+
mvn tomcat7:run
11+
```
12+
13+
Cuidado para *jamais* executar `mvn tomcat:run` pois ele usará um tomcat6 (incompatível).

‎vraptor/pom.xml‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>vraptor</artifactId>
6+
<version>1.0.0</version>
7+
<packaging>war</packaging>
8+
9+
<description>A demo project to start using VRaptor 4</description>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<weld.version>2.1.2.Final</weld.version>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>br.com.caelum</groupId>
19+
<artifactId>vraptor</artifactId>
20+
<version>4.2.0.Final</version>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>org.jboss.weld.servlet</groupId>
25+
<artifactId>weld-servlet-core</artifactId>
26+
<version>2.1.2.Final</version>
27+
<exclusions>
28+
<exclusion>
29+
<groupId>org.jboss.spec.javax.el</groupId>
30+
<artifactId>jboss-el-api_3.0_spec</artifactId>
31+
</exclusion>
32+
</exclusions>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.jboss.weld</groupId>
37+
<artifactId>weld-core-impl</artifactId>
38+
<version>2.1.2.Final</version>
39+
<exclusions>
40+
<exclusion>
41+
<groupId>org.jboss.spec.javax.el</groupId>
42+
<artifactId>jboss-el-api_3.0_spec</artifactId>
43+
</exclusion>
44+
</exclusions>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>javax.el</groupId>
49+
<artifactId>el-api</artifactId>
50+
<version>2.2</version>
51+
<scope>provided</scope>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>org.hibernate</groupId>
56+
<artifactId>hibernate-validator-cdi</artifactId>
57+
<version>5.1.1.Final</version>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>javax.servlet</groupId>
62+
<artifactId>jstl</artifactId>
63+
<version>1.2</version>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>javax.servlet</groupId>
68+
<artifactId>javax.servlet-api</artifactId>
69+
<version>3.1.0</version>
70+
<scope>provided</scope>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>org.slf4j</groupId>
75+
<artifactId>slf4j-log4j12</artifactId>
76+
<version>1.7.5</version>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>br.com.caelum.vraptor</groupId>
81+
<artifactId>vraptor-freemarker</artifactId>
82+
<version>4.1.0-RC3</version>
83+
</dependency>
84+
85+
<dependency>
86+
<groupId>br.com.caelum.vraptor</groupId>
87+
<artifactId>vraptor-hibernate</artifactId>
88+
<version>4.0.4</version>
89+
</dependency>
90+
91+
<dependency>
92+
<groupId>mysql</groupId>
93+
<artifactId>mysql-connector-java</artifactId>
94+
<version>8.0.8-dmr</version>
95+
</dependency>
96+
97+
<dependency>
98+
<groupId>org.mindrot</groupId>
99+
<artifactId>jbcrypt</artifactId>
100+
<version>0.4</version>
101+
</dependency>
102+
103+
<dependency>
104+
<groupId>org.freemarker</groupId>
105+
<artifactId>freemarker</artifactId>
106+
<version>2.3.27-incubating</version>
107+
</dependency>
108+
109+
</dependencies>
110+
111+
<build>
112+
<finalName>vraptor</finalName>
113+
<outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
114+
<plugins>
115+
<plugin>
116+
<groupId>org.apache.maven.plugins</groupId>
117+
<artifactId>maven-compiler-plugin</artifactId>
118+
<version>3.1</version>
119+
<configuration>
120+
<source>1.8</source>
121+
<target>1.8</target>
122+
</configuration>
123+
</plugin>
124+
<plugin>
125+
<groupId>org.apache.tomcat.maven</groupId>
126+
<artifactId>tomcat7-maven-plugin</artifactId>
127+
<version>2.1</version>
128+
<configuration>
129+
<path>/</path>
130+
</configuration>
131+
</plugin>
132+
</plugins>
133+
</build>
134+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.config;
2+
3+
import com.baeldung.models.User;
4+
5+
import javax.enterprise.context.SessionScoped;
6+
import java.io.Serializable;
7+
8+
@SessionScoped
9+
public class UserInfo implements Serializable {
10+
11+
private User user;
12+
13+
14+
public UserInfo() {}
15+
16+
public User getUser() {
17+
return user;
18+
}
19+
20+
public void setUser(User user) {
21+
this.user = user;
22+
}
23+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.baeldung.controllers;
2+
3+
import br.com.caelum.vraptor.*;
4+
import br.com.caelum.vraptor.freemarker.FreemarkerView;
5+
import br.com.caelum.vraptor.validator.Validator;
6+
import com.baeldung.config.UserInfo;
7+
import com.baeldung.daos.UserDao;
8+
import com.baeldung.models.User;
9+
import org.mindrot.jbcrypt.BCrypt;
10+
11+
import javax.inject.Inject;
12+
import javax.servlet.http.HttpServletRequest;
13+
import java.util.Objects;
14+
import java.util.logging.Logger;
15+
16+
@Controller
17+
public class AuthController {
18+
19+
private Validator validator;
20+
private UserDao userDao;
21+
private Result result;
22+
private UserInfo userInfo;
23+
private Logger logger = Logger.getLogger(getClass().getName());
24+
25+
public AuthController() {
26+
this(null, null, null, null);
27+
}
28+
29+
@Inject
30+
public AuthController(Validator validator, UserDao userDao, Result result, UserInfo userInfo) {
31+
this.validator = validator;
32+
this.userDao = userDao;
33+
this.result = result;
34+
this.userInfo = userInfo;
35+
}
36+
37+
@Get("/register")
38+
public void registrationForm() {
39+
result.use(FreemarkerView.class).withTemplate("auth/register");
40+
}
41+
42+
@Post("/register")
43+
public void register(User user, HttpServletRequest request) {
44+
45+
validator.validate(user);
46+
47+
if(validator.hasErrors()) {
48+
result.include("errors", validator.getErrors());
49+
}
50+
51+
validator.onErrorRedirectTo(this).registrationForm();
52+
53+
if(!user.getPassword()
54+
.equals(request.getParameter("password_confirmation"))) {
55+
result.include("error", "Passwords Do Not Match");
56+
result.redirectTo(this).registrationForm();
57+
}
58+
59+
user.setPassword(
60+
BCrypt.hashpw(user.getPassword(), BCrypt.gensalt()));
61+
62+
Object resp = userDao.add(user);
63+
64+
if(resp != null) {
65+
result.include("status", "Registration Successful! Now Login");
66+
result.redirectTo(this).loginForm();
67+
} else {
68+
result.include("error", "There was an error during registration");
69+
result.redirectTo(this).registrationForm();
70+
}
71+
}
72+
73+
@Get("/login")
74+
public void loginForm() {
75+
result.use(FreemarkerView.class).withTemplate("auth/login");
76+
}
77+
78+
@Post("/login")
79+
public void login(HttpServletRequest request) {
80+
81+
String password = request.getParameter("user.password");
82+
String email = request.getParameter("user.email");
83+
84+
if(email.isEmpty() || password.isEmpty()) {
85+
result.include("error", "Email/Password is Required!");
86+
result.redirectTo(AuthController.class).loginForm();
87+
}
88+
89+
User user = userDao.findByEmail(email);
90+
if(user != null && BCrypt.checkpw(password, user.getPassword())) {
91+
userInfo.setUser(user);
92+
result.include("status", "Login Successful!");
93+
result.redirectTo(IndexController.class).index();
94+
} else {
95+
result.include("error", "Email/Password Does Not Match!");
96+
result.redirectTo(AuthController.class).loginForm();
97+
}
98+
}
99+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.baeldung.controllers;
2+
3+
import br.com.caelum.vraptor.Controller;
4+
import br.com.caelum.vraptor.Path;
5+
import br.com.caelum.vraptor.Result;
6+
import br.com.caelum.vraptor.freemarker.FreemarkerView;
7+
import com.baeldung.daos.PostDao;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
11+
import javax.inject.Inject;
12+
13+
@Controller
14+
public class IndexController {
15+
16+
private PostDao postDao;
17+
private final Result result;
18+
private static final Logger logger = LoggerFactory.getLogger(IndexController.class);
19+
20+
public IndexController() {
21+
this(null, null);
22+
}
23+
24+
@Inject
25+
public IndexController(Result result, PostDao postDao) {
26+
this.result = result;
27+
this.postDao = postDao;
28+
}
29+
30+
@Path("/")
31+
public void index() {
32+
result.include("posts", postDao.all());
33+
result.use(FreemarkerView.class).withTemplate("index");
34+
}
35+
36+
37+
38+
39+
40+
}

0 commit comments

Comments
 (0)