This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Spring JDBC --> | |
<dependency> | |
<groupId>mysql</groupId> | |
<artifactId>mysql-connector-java</artifactId> | |
<version>5.1.9</version> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
Class.forName("com.mysql.jdbc.Driver"); // Load driver | |
Connection con = DriverManager.getConnection( | |
"jdbc:mysql://localhost/db_name?useUnicode=true&characterEncoding=UTF-8", | |
"db_user", | |
"db_password" | |
); | |
Statement state = con.createStatement(); | |
String sql = "INSERT INTO `users` (`username`, `password`) VALUES ('hoge', 'fuga')"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Security --> | |
<dependency> | |
<groupId>org.springframework.security</groupId> | |
<artifactId>spring-security-core</artifactId> | |
<version>3.1.0.RELEASE</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.security</groupId> | |
<artifactId>spring-security-web</artifactId> | |
<version>3.1.0.RELEASE</version> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- <param-value>/WEB-INF/spring/root-context.xml</param-value> | |
+ <param-value>/WEB-INF/spring/root-context.xml, /WEB-INF/spring/appServlet/spring-security.xml</param-value> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<filter> | |
<filter-name>springSecurityFilterChain</filter-name> | |
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> | |
</filter> | |
<filter-mapping> | |
<filter-name>springSecurityFilterChain</filter-name> | |
<url-pattern>/*</url-pattern> | |
</filter-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans:beans xmlns="http://www.springframework.org/schema/security" | |
xmlns:beans="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans | |
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd | |
http://www.springframework.org/schema/security | |
http://www.springframework.org/schema/security/spring-security-3.1.xsd"> | |
<http auto-config="true"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<c:if test="${not empty userName}"> | |
<p>Logged in as: ${userName}</p> | |
</c:if> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping(value = "/", method = RequestMethod.GET) | |
public String home(Locale locale, Model model, Principal principal) { | |
//... | |
if (null != principal) { | |
model.addAttribute("userName", principal.getName()); | |
} | |
//... | |
return "home"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
System.out.println("Enter a string to encode:"); | |
Scanner scan = new Scanner(System.in); | |
String org = scan.next(); | |
System.out.println("Original String: "+ org); | |
StandardPasswordEncoder encoder = new StandardPasswordEncoder(); | |
String enc = encoder.encode(org); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `users` ( | |
user_id int(10) NOT NULL AUTO_INCREMENT, | |
user_name varchar(40) NOT NULL, | |
password text NOT NULL, | |
enabled tinyint( 1 ) NOT NULL DEFAULT '1', | |
PRIMARY KEY (user_id) | |
) |
OlderNewer