作者 朱兆平

spring security 用户登录部分完善

@@ -92,6 +92,12 @@ @@ -92,6 +92,12 @@
92 <artifactId>druid-spring-boot-starter</artifactId> 92 <artifactId>druid-spring-boot-starter</artifactId>
93 <version>1.1.9</version> 93 <version>1.1.9</version>
94 </dependency> 94 </dependency>
  95 + <!-- mysql-->
  96 + <dependency>
  97 + <groupId>mysql</groupId>
  98 + <artifactId>mysql-connector-java</artifactId>
  99 + </dependency>
  100 + <!-- oracle-->
95 <dependency> 101 <dependency>
96 <groupId>com.oracle</groupId> 102 <groupId>com.oracle</groupId>
97 <artifactId>ojdbc6</artifactId> 103 <artifactId>ojdbc6</artifactId>
@@ -11,11 +11,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -11,11 +11,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
11 import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; 11 import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
12 import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 12 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
13 import org.springframework.scheduling.annotation.EnableScheduling; 13 import org.springframework.scheduling.annotation.EnableScheduling;
14 -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;  
15 -  
16 @SpringBootApplication 14 @SpringBootApplication
17 @EnableScheduling 15 @EnableScheduling
18 -@EnableEurekaClient 16 +//@EnableEurekaClient
19 @MapperScan("com.tianbo.warehouse.dao") 17 @MapperScan("com.tianbo.warehouse.dao")
20 public class WarehouseApplication { 18 public class WarehouseApplication {
21 19
@@ -15,9 +15,8 @@ public class MainController { @@ -15,9 +15,8 @@ public class MainController {
15 UserService userService; 15 UserService userService;
16 16
17 @GetMapping("/error") 17 @GetMapping("/error")
18 - public List<USERS> error(){  
19 - List<USERS> usersList =userService.selectAllUser();  
20 - return usersList; 18 + public String error(){
  19 + return "error";
21 } 20 }
22 21
23 @GetMapping("/main") 22 @GetMapping("/main")
@@ -136,26 +136,47 @@ public class USERS implements UserDetails{ @@ -136,26 +136,47 @@ public class USERS implements UserDetails{
136 public void setPermissions(List<PERMISSION> permissions) { 136 public void setPermissions(List<PERMISSION> permissions) {
137 this.permissions = permissions; 137 this.permissions = permissions;
138 } 138 }
  139 +
  140 + /**
  141 + * 账户未过期
  142 + * @return
  143 + */
139 @Override 144 @Override
140 public boolean isAccountNonExpired(){ 145 public boolean isAccountNonExpired(){
141 return true; 146 return true;
142 } 147 }
143 148
  149 + /**
  150 + * 账户未锁定
  151 + * @return
  152 + */
144 @Override 153 @Override
145 public boolean isAccountNonLocked(){ 154 public boolean isAccountNonLocked(){
146 return true; 155 return true;
147 } 156 }
148 157
  158 + /**密码未过期
  159 + *
  160 + * @return
  161 + */
149 @Override 162 @Override
150 public boolean isCredentialsNonExpired(){ 163 public boolean isCredentialsNonExpired(){
151 return true; 164 return true;
152 } 165 }
153 166
  167 + /**
  168 + * //账户可用
  169 + * @return
  170 + */
154 @Override 171 @Override
155 public boolean isEnabled(){ 172 public boolean isEnabled(){
156 return true; 173 return true;
157 } 174 }
158 175
  176 + /**
  177 + * user的权限列表
  178 + * @return
  179 + */
159 @Override 180 @Override
160 public Collection<? extends GrantedAuthority> getAuthorities(){ 181 public Collection<? extends GrantedAuthority> getAuthorities(){
161 List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>(); 182 List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
@@ -3,6 +3,7 @@ package com.tianbo.warehouse.security; @@ -3,6 +3,7 @@ package com.tianbo.warehouse.security;
3 import com.tianbo.warehouse.model.USERS; 3 import com.tianbo.warehouse.model.USERS;
4 import com.tianbo.warehouse.service.UserService; 4 import com.tianbo.warehouse.service.UserService;
5 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.security.authentication.BadCredentialsException;
6 import org.springframework.security.core.userdetails.UserDetails; 7 import org.springframework.security.core.userdetails.UserDetails;
7 import org.springframework.security.core.userdetails.UserDetailsService; 8 import org.springframework.security.core.userdetails.UserDetailsService;
8 import org.springframework.security.core.userdetails.UsernameNotFoundException; 9 import org.springframework.security.core.userdetails.UsernameNotFoundException;
@@ -20,13 +21,13 @@ public class CustomUserDetailService implements UserDetailsService { @@ -20,13 +21,13 @@ public class CustomUserDetailService implements UserDetailsService {
20 @Override 21 @Override
21 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 22 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
22 23
23 - try {  
24 - USERS user = userService.loadByUsername(username);  
25 - return user;  
26 - } catch (UsernameNotFoundException e) {  
27 24
28 - e.printStackTrace(); 25 + USERS user = userService.loadByUsername(username);
  26 + if (user == null) {
  27 + throw new UsernameNotFoundException("用户名不存在");
  28 +// throw new BadCredentialsException("用户名不存在");
29 } 29 }
30 - return null; 30 + return user;
  31 +
31 } 32 }
32 } 33 }
@@ -13,12 +13,17 @@ import java.util.Iterator; @@ -13,12 +13,17 @@ import java.util.Iterator;
13 13
14 @Service 14 @Service
15 public class MyAccessDecisionManager implements AccessDecisionManager{ 15 public class MyAccessDecisionManager implements AccessDecisionManager{
16 -  
17 - // decide 方法是判定是否拥有权限的决策方法,  
18 - //authentication 是释CustomUserService中循环添加到 GrantedAuthority 对象中的权限信息集合.  
19 - //object 包含客户端发起的请求的requset信息,可转换为 HttpServletRequest request = ((FilterInvocation) object).getHttpRequest();  
20 - //configAttributes 为MyInvocationSecurityMetadataSource的getAttributes(Object object)这个方法返回的结果,此方法是为了判定用户请求的url 是否在权限表中,如果在权限表中,则返回给 decide 方法,用来判定用户是否有此权限。如果不在权限表中则放行。  
21 - 16 + /**
  17 + * decide方法接收三个参数,decide 方法是判定是否拥有权限的决策方法
  18 + * 其中第一个参数中保存了当前登录用户的角色信息,authentication 是释CustomUserService中循环添加到 GrantedAuthority 对象中的权限信息集合.
  19 + * object 包含客户端发起的请求的requset信息,可转换为 HttpServletRequest request = ((FilterInvocation) object).getHttpRequest();
  20 + * 第三个参数则是MyInvocationSecurityMetadataSourceService中的getAttributes方法传来的,表示当前请求需要的角色(可能有多个),此方法是为了判定用户请求的url 是否在权限表中,如果在权限表中,则返回给 decide 方法,用来判定用户是否有此权限。如果不在权限表中则放行。
  21 + * @param authentication
  22 + * @param object
  23 + * @param configAttributes
  24 + * @throws AccessDeniedException
  25 + * @throws InsufficientAuthenticationException
  26 + */
22 @Override 27 @Override
23 public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException{ 28 public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException{
24 29
@@ -37,7 +42,7 @@ public class MyAccessDecisionManager implements AccessDecisionManager{ @@ -37,7 +42,7 @@ public class MyAccessDecisionManager implements AccessDecisionManager{
37 } 42 }
38 } 43 }
39 } 44 }
40 - throw new AccessDeniedException("no right"); 45 + throw new AccessDeniedException("权限不足!");
41 } 46 }
42 47
43 @Override 48 @Override
@@ -13,6 +13,10 @@ import org.springframework.stereotype.Service; @@ -13,6 +13,10 @@ import org.springframework.stereotype.Service;
13 import javax.servlet.http.HttpServletRequest; 13 import javax.servlet.http.HttpServletRequest;
14 import java.util.*; 14 import java.util.*;
15 15
  16 +/**
  17 + * 本类的主要功能就是通过当前的请求地址,获取该地址需要的用户角色
  18 + * 如果getAttributes(Object o)方法返回null的话,意味着当前这个请求不需要任何角色就能访问,甚至不需要登录。
  19 + */
16 @Service 20 @Service
17 public class MyInvocationSecurityMetadataSourceService implements FilterInvocationSecurityMetadataSource{ 21 public class MyInvocationSecurityMetadataSourceService implements FilterInvocationSecurityMetadataSource{
18 22
1 -package com.tianbo.warehouse.security; 1 +package com.tianbo.warehouse.security.config;
2 2
3 import org.apache.commons.codec.digest.DigestUtils; 3 import org.apache.commons.codec.digest.DigestUtils;
4 -import org.apache.tomcat.util.security.MD5Encoder;  
5 import org.springframework.security.crypto.password.PasswordEncoder; 4 import org.springframework.security.crypto.password.PasswordEncoder;
6 import org.springframework.stereotype.Service; 5 import org.springframework.stereotype.Service;
7 6
  7 +/**
  8 + * PasswordEncoder 是个接口,该接口下有两个方法,一个是encoder 一个是matches,前者用于加密,后者用于匹配校验.
  9 + */
8 @Service(value = "passwordEncodeService") 10 @Service(value = "passwordEncodeService")
9 public class PasswordEncoderImp implements PasswordEncoder{ 11 public class PasswordEncoderImp implements PasswordEncoder{
10 12
  1 +package com.tianbo.warehouse.security.config;
  2 +
  3 +import com.tianbo.warehouse.security.model.BrowserProperties;
  4 +import org.springframework.boot.context.properties.ConfigurationProperties;
  5 +import org.springframework.stereotype.Component;
  6 +
  7 +@ConfigurationProperties(prefix = "tianbo.security")
  8 +@Component
  9 +public class SecurityProperties {
  10 +
  11 + /**
  12 + * 浏览器 属性类
  13 + */
  14 + private BrowserProperties browser = new BrowserProperties();
  15 +
  16 + public BrowserProperties getBrowser() {
  17 + return browser;
  18 + }
  19 +
  20 + public void setBrowser(BrowserProperties browser) {
  21 + this.browser = browser;
  22 + }
  23 +}
1 -package com.tianbo.warehouse.security; 1 +package com.tianbo.warehouse.security.config;
2 2
  3 +import com.tianbo.warehouse.security.handel.MyAuthenticationFailHandler;
  4 +import com.tianbo.warehouse.security.handel.MyAuthenticationSuccessHandler;
  5 +import com.tianbo.warehouse.security.MyFilterSecurityInterceptor;
3 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.beans.factory.annotation.Qualifier; 7 import org.springframework.beans.factory.annotation.Qualifier;
5 import org.springframework.context.annotation.Configuration; 8 import org.springframework.context.annotation.Configuration;
  9 +import org.springframework.core.annotation.Order;
6 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 10 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7 import org.springframework.security.config.annotation.web.builders.HttpSecurity; 11 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 12 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 13 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10 import org.springframework.security.core.userdetails.UserDetailsService; 14 import org.springframework.security.core.userdetails.UserDetailsService;
11 import org.springframework.security.crypto.password.PasswordEncoder; 15 import org.springframework.security.crypto.password.PasswordEncoder;
12 -import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;  
13 16
14 @Configuration 17 @Configuration
15 @EnableWebSecurity 18 @EnableWebSecurity
  19 +@Order(1)
16 public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 20 public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
17 21
18 @Autowired 22 @Autowired
@@ -21,6 +25,12 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @@ -21,6 +25,12 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
21 @Autowired 25 @Autowired
22 private PasswordEncoder passwordEncoder; 26 private PasswordEncoder passwordEncoder;
23 27
  28 + @Autowired
  29 + private MyAuthenticationSuccessHandler successHandler;
  30 +
  31 + @Autowired
  32 + private MyAuthenticationFailHandler failHandler;
  33 +
24 @Qualifier("customuserservice") 34 @Qualifier("customuserservice")
25 @Autowired 35 @Autowired
26 private UserDetailsService userDetailsService; 36 private UserDetailsService userDetailsService;
@@ -41,11 +51,15 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @@ -41,11 +51,15 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
41 .formLogin() 51 .formLogin()
42 .passwordParameter("password") 52 .passwordParameter("password")
43 .usernameParameter("username") 53 .usernameParameter("username")
44 - //.loginProcessingUrl("/home")//登陆提交的处理url 54 + //登陆提交的处理url
  55 + //.loginProcessingUrl("/home")
45 .loginPage("/login") 56 .loginPage("/login")
46 - .failureUrl("/error")  
47 - .permitAll()//登录页面用户任意访问  
48 - .successForwardUrl("/main") 57 + .successHandler(successHandler)
  58 + .failureHandler(failHandler)
  59 +// .failureUrl("/error")
  60 + //登录页面用户任意访问
  61 + .permitAll()
  62 +// .successForwardUrl("/main")
49 .and() 63 .and()
50 .logout() 64 .logout()
51 .logoutSuccessUrl("/?logout=true") 65 .logoutSuccessUrl("/?logout=true")
  1 +package com.tianbo.warehouse.security.handel;
  2 +
  3 +import com.fasterxml.jackson.databind.ObjectMapper;
  4 +import com.tianbo.warehouse.security.config.SecurityProperties;
  5 +import com.tianbo.warehouse.security.model.LoginType;
  6 +import org.apache.commons.logging.Log;
  7 +import org.apache.commons.logging.LogFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.http.HttpStatus;
  10 +import org.springframework.security.core.AuthenticationException;
  11 +import org.springframework.security.web.DefaultRedirectStrategy;
  12 +import org.springframework.security.web.RedirectStrategy;
  13 +import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
  14 +import org.springframework.stereotype.Component;
  15 +
  16 +import javax.servlet.ServletException;
  17 +import javax.servlet.http.HttpServletRequest;
  18 +import javax.servlet.http.HttpServletResponse;
  19 +import java.io.IOException;
  20 +
  21 +/**
  22 + * 自定义登录失败处理器
  23 + * Created by mrz.
  24 + */
  25 +@Component
  26 +public class MyAuthenticationFailHandler extends SimpleUrlAuthenticationFailureHandler {
  27 + protected final Log logger = LogFactory.getLog(this.getClass());
  28 + /**
  29 + * json 转换工具类
  30 + */
  31 + @Autowired
  32 + private ObjectMapper objectMapper;
  33 +
  34 + private String defaultFailureUrl;
  35 + private boolean forwardToDestination = false;
  36 + private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
  37 +
  38 + @Autowired
  39 + private SecurityProperties securityProperties;
  40 +
  41 + @Override
  42 + public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
  43 +
  44 + logger.info("登录失败");
  45 + //如果securityProperties中配置的是JSON就返回JSON
  46 + if (LoginType.JSON.equals(securityProperties.getBrowser().getLoginType())){
  47 + //设置状态码
  48 + response.setStatus(HttpStatus.UNAUTHORIZED.value());
  49 + //将 登录失败 信息打包成json格式返回
  50 + response.setContentType("application/json;charset=UTF-8");
  51 + response.getWriter().write(objectMapper.writeValueAsString(exception));
  52 + }
  53 +
  54 + if (this.defaultFailureUrl == null) {
  55 + this.logger.debug("No failure URL set, sending 401 Unauthorized error");
  56 + response.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase());
  57 + } else {
  58 + this.saveException(request, exception);
  59 + if (this.forwardToDestination) {
  60 + this.logger.debug("Forwarding to " + this.defaultFailureUrl);
  61 + request.getRequestDispatcher(this.defaultFailureUrl).forward(request, response);
  62 + } else {
  63 + this.logger.debug("Redirecting to " + this.defaultFailureUrl);
  64 + this.redirectStrategy.sendRedirect(request, response, this.defaultFailureUrl);
  65 + }
  66 + }
  67 +
  68 + }
  69 +}
  1 +package com.tianbo.warehouse.security.handel;
  2 +
  3 +import com.fasterxml.jackson.databind.ObjectMapper;
  4 +import com.tianbo.warehouse.security.model.LoginType;
  5 +import org.apache.commons.logging.Log;
  6 +import org.apache.commons.logging.LogFactory;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import com.tianbo.warehouse.security.config.SecurityProperties;
  9 +import org.springframework.security.core.Authentication;
  10 +import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
  11 +import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
  12 +import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
  13 +import org.springframework.security.web.savedrequest.RequestCache;
  14 +import org.springframework.security.web.savedrequest.SavedRequest;
  15 +import org.springframework.stereotype.Component;
  16 +import org.springframework.util.StringUtils;
  17 +
  18 +import javax.servlet.ServletException;
  19 +import javax.servlet.http.HttpServletRequest;
  20 +import javax.servlet.http.HttpServletResponse;
  21 +import java.io.IOException;
  22 +
  23 +/**
  24 + * 登录成功后的返回处理
  25 + */
  26 +@Component
  27 +public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler{
  28 + protected final Log logger = LogFactory.getLog(this.getClass());
  29 +
  30 + @Autowired
  31 + private ObjectMapper objectMapper;
  32 +
  33 + private RequestCache requestCache = new HttpSessionRequestCache();
  34 +
  35 + @Autowired
  36 + private SecurityProperties securityProperties;
  37 +
  38 + @Override
  39 + public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
  40 + logger.info("登录成功");
  41 + if (LoginType.JSON.equals(securityProperties.getBrowser().getLoginType())){
  42 + //将 authention 信息打包成json格式返回
  43 + response.setContentType("application/json;charset=UTF-8");
  44 + response.getWriter().write(objectMapper.writeValueAsString(authentication));
  45 + }else {
  46 + //走原来的处理流程
  47 + SavedRequest savedRequest = this.requestCache.getRequest(request, response);
  48 + if (savedRequest == null) {
  49 + super.onAuthenticationSuccess(request, response, authentication);
  50 + } else {
  51 + String targetUrlParameter = this.getTargetUrlParameter();
  52 + if (!this.isAlwaysUseDefaultTargetUrl() && (targetUrlParameter == null || !StringUtils.hasText(request.getParameter(targetUrlParameter)))) {
  53 + this.clearAuthenticationAttributes(request);
  54 + String targetUrl = savedRequest.getRedirectUrl();
  55 + this.logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
  56 + this.getRedirectStrategy().sendRedirect(request, response, targetUrl);
  57 + } else {
  58 + this.requestCache.removeRequest(request, response);
  59 + super.onAuthenticationSuccess(request, response, authentication);
  60 + }
  61 + }
  62 + }
  63 +
  64 + }
  65 +
  66 +
  67 +}
  1 +package com.tianbo.warehouse.security.model;
  2 +
  3 +/**
  4 + * browser(浏览器)配置文件里的: fantJ.security.browser.loginPage 属性类
  5 + *
  6 + */
  7 +public class BrowserProperties {
  8 + /**
  9 + * loginPage 默认值 是login.html
  10 + * 如果 application.properties 里有对 fantJ.security.browser.loginPage 的声明,则获取该值
  11 + */
  12 + private String loginPage = "/browser-login.html";
  13 +
  14 + /**
  15 + * 默认 返回 json 类型,声明登录返回格式
  16 + */
  17 + private LoginType loginType = LoginType.JSON;
  18 +
  19 + public String getLoginPage() {
  20 + return loginPage;
  21 + }
  22 +
  23 + public void setLoginPage(String loginPage) {
  24 + this.loginPage = loginPage;
  25 + }
  26 +
  27 + public LoginType getLoginType() {
  28 + return loginType;
  29 + }
  30 +
  31 + public void setLoginType(LoginType loginType) {
  32 + this.loginType = loginType;
  33 + }
  34 +}
  1 +package com.tianbo.warehouse.security.model;
  2 +
  3 +public enum LoginType {
  4 + REDIRECT,
  5 + JSON
  6 +}
@@ -51,14 +51,9 @@ public class UserServiceImpl implements UserService{ @@ -51,14 +51,9 @@ public class UserServiceImpl implements UserService{
51 List<USERS> list = usersMapper.selectAllUser(); 51 List<USERS> list = usersMapper.selectAllUser();
52 for (USERS user: list) { 52 for (USERS user: list) {
53 List<PERMISSION> permissionList = permissionMapper.findByUserId(user.getUserId()); 53 List<PERMISSION> permissionList = permissionMapper.findByUserId(user.getUserId());
54 - if (permissionList!=null && permissionList.size()>0){  
55 - user.setPermissions(permissionList);  
56 - }  
57 - 54 + user.setPermissions(permissionList);
58 List<ROLE> roleList = roleMapper.findRolesByUserId(user.getUserId()); 55 List<ROLE> roleList = roleMapper.findRolesByUserId(user.getUserId());
59 - if (roleList!=null && roleList.size()>0){  
60 - user.setRoles(roleList);  
61 - } 56 + user.setRoles(roleList);
62 } 57 }
63 return list; 58 return list;
64 } 59 }
@@ -2,29 +2,46 @@ @@ -2,29 +2,46 @@
2 #服务端口 2 #服务端口
3 server.port=7003 3 server.port=7003
4 server.servlet.context-path=${SERVER_CONTEXTPATH:} 4 server.servlet.context-path=${SERVER_CONTEXTPATH:}
5 -#eureka主机名,会在控制页面中显示  
6 -eureka.instance.hostname=${spring.cloud.client.ip-address}  
7 -#eureka服务器页面中status的请求路径  
8 -eureka.instance.status-page-url=http://${eureka.instance.hostname}:${server.port}/index  
9 -#eureka注册中心服务器地址  
10 -eureka.client.service-url.defaultZone=http://10.50.3.82:19527/eureka/ 5 +
  6 +
11 #服务名 7 #服务名
12 -spring.application.name=imf-warehouse-reader  
13 -eureka.instance.prefer-ip-address=true  
14 -eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}  
15 -eureka.client.registry-fetch-interval-seconds=30  
16 -eureka.instance.lease-renewal-interval-in-seconds=15  
17 -eureka.instance.lease-expiration-duration-in-seconds=45 8 +spring.application.name=tianbo.base.dev.devkit
  9 +
18 10
19 #springcloud 基本配置 11 #springcloud 基本配置
20 12
  13 +#eureka主机名,会在控制页面中显示
  14 +spring.cloud.features.enabled=false
  15 +spring.cloud.discovery.enabled=false
  16 +spring.cloud.service-registry.auto-registration.enabled=false
  17 +#eureka.instance.hostname=${spring.cloud.client.ip-address}
  18 +#eureka服务器页面中status的请求路径
  19 +#eureka.instance.status-page-url=http://${eureka.instance.hostname}:${server.port}/index
  20 +#eureka注册中心服务器地址
  21 +#eureka.client.service-url.defaultZone=http://10.50.3.82:19527/eureka/
  22 +#eureka.instance.prefer-ip-address=true
  23 +#eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
  24 +#eureka.client.registry-fetch-interval-seconds=30
  25 +#eureka.instance.lease-renewal-interval-in-seconds=15
  26 +#eureka.instance.lease-expiration-duration-in-seconds=45
21 27
22 -#spring.datasource.name=CGOETL 28 +#spring.datasource oracle
23 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource 29 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
24 -spring.datasource.driver-class-name=oracle.jdbc.OracleDriver  
25 -spring.datasource.url=jdbc:oracle:thin:@10.50.3.68:1521:CGODW  
26 -spring.datasource.username=CGOETL  
27 -spring.datasource.password=1q2w3e4r 30 +#spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
  31 +#spring.datasource.url=jdbc:oracle:thin:@10.50.3.68:1521:CGODW
  32 +#spring.datasource.username=CGOETL
  33 +#spring.datasource.password=1q2w3e4r
  34 +
  35 +#spring datasource mysql
  36 +spring.datasource.url=jdbc:mysql://127.0.0.1:3307/statistics
  37 +spring.datasource.username=root
  38 +spring.datasource.password=
  39 +spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  40 +spring.datasource.max-idle=10
  41 +spring.datasource.max-wait=10000
  42 +spring.datasource.min-idle=5
  43 +spring.datasource.initial-size=5
  44 +
28 #配置初始化大小/最小/最大 45 #配置初始化大小/最小/最大
29 spring.datasource.druid.initial-size=1 46 spring.datasource.druid.initial-size=1
30 spring.datasource.druid.min-idle=1 47 spring.datasource.druid.min-idle=1
@@ -35,25 +52,31 @@ spring.datasource.druid.max-wait=60000 @@ -35,25 +52,31 @@ spring.datasource.druid.max-wait=60000
35 spring.datasource.druid.min-evictable-idle-time-millis=300000 52 spring.datasource.druid.min-evictable-idle-time-millis=300000
36 #间隔多久进行一次检测,检测需要关闭的空闲连接 53 #间隔多久进行一次检测,检测需要关闭的空闲连接
37 spring.datasource.druid.time-between-eviction-runs-millis=60000 54 spring.datasource.druid.time-between-eviction-runs-millis=60000
38 -spring.datasource.druid.validation-query=SELECT 'x' FROM DUAL 55 +#oracle
  56 +#spring.datasource.druid.validation-query=SELECT 'x' FROM DUAL
  57 +#mysql
  58 +spring.datasource.druid.validation-query=SELECT 1 FROM DUAL
39 spring.datasource.druid.test-while-idle=true 59 spring.datasource.druid.test-while-idle=true
40 spring.datasource.druid.test-on-borrow=false 60 spring.datasource.druid.test-on-borrow=false
41 spring.datasource.druid.test-on-return=false 61 spring.datasource.druid.test-on-return=false
42 spring.datasource.druid.default-auto-commit=true 62 spring.datasource.druid.default-auto-commit=true
43 63
44 -#security配置  
45 -trace=true 64 +
46 65
47 mybatis.mapper-locations=classpath:mapping/*.xml 66 mybatis.mapper-locations=classpath:mapping/*.xml
48 mybatis.type-aliases-package=com.tianbo.warehouse.model 67 mybatis.type-aliases-package=com.tianbo.warehouse.model
49 -logging.level.com.tianbo.warehouse.dao=DEBUG  
50 -logging.level.org.springframework.security =debug  
51 -debug=true  
52 -pagehelper.helper-dialect=oracle 68 +
  69 +
  70 +
  71 +pagehelper.helper-dialect=mysql
53 #pagehelper.auto-dialect=true 72 #pagehelper.auto-dialect=true
54 #pagehelper.auto-runtime-dialect=true 73 #pagehelper.auto-runtime-dialect=true
55 pagehelper.reasonable=true 74 pagehelper.reasonable=true
56 pagehelper.support-methods-arguments=true 75 pagehelper.support-methods-arguments=true
57 pagehelper.params=count=countSql 76 pagehelper.params=count=countSql
58 77
59 - 78 +#debug配置
  79 +trace=false
  80 +logging.level.com.tianbo.warehouse.dao=DEBUG
  81 +logging.level.org.springframework.security =trace
  82 +debug=false
@@ -30,23 +30,7 @@ @@ -30,23 +30,7 @@
30 </div> 30 </div>
31 </nav> 31 </nav>
32 <div class="container"> 32 <div class="container">
33 -  
34 - <div class="starter-template">  
35 - <p th:if="${param.logout}" class="bg-warning">已成功注销</p><!-- 1 -->  
36 - <p th:if="${param.error}" class="bg-danger">有错误,请重试</p> <!-- 2 -->  
37 - <h2>使用账号密码登录</h2>  
38 - <form name="form" th:action="@{/login}" action="/login" method="POST"> <!-- 3 -->  
39 - <div class="form-group">  
40 - <label for="username">账号</label>  
41 - <input type="text" class="form-control" name="username" value="" placeholder="账号" />  
42 - </div>  
43 - <div class="form-group">  
44 - <label for="password">密码</label>  
45 - <input type="password" class="form-control" name="password" placeholder="密码" />  
46 - </div>  
47 - <input type="submit" id="login" value="Login" class="btn btn-primary" />  
48 - </form>  
49 - </div> 33 + welcom
50 </div> 34 </div>
51 </body> 35 </body>
52 </html> 36 </html>