Commit cb845726f63f275e2def6101459833da6cc23681
1 parent
72852799
优化代码
Showing
3 changed files
with
17 additions
and
11 deletions
src/main/java/com/genersoft/iot/vmp/conf/security/LoginSuccessHandler.java
| @@ -11,6 +11,9 @@ import javax.servlet.http.HttpServletRequest; | @@ -11,6 +11,9 @@ import javax.servlet.http.HttpServletRequest; | ||
| 11 | import javax.servlet.http.HttpServletResponse; | 11 | import javax.servlet.http.HttpServletResponse; |
| 12 | import java.io.IOException; | 12 | import java.io.IOException; |
| 13 | 13 | ||
| 14 | +/** | ||
| 15 | + * @author lin | ||
| 16 | + */ | ||
| 14 | @Component | 17 | @Component |
| 15 | public class LoginSuccessHandler implements AuthenticationSuccessHandler { | 18 | public class LoginSuccessHandler implements AuthenticationSuccessHandler { |
| 16 | 19 |
src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java
| @@ -20,6 +20,7 @@ import java.util.List; | @@ -20,6 +20,7 @@ import java.util.List; | ||
| 20 | 20 | ||
| 21 | /** | 21 | /** |
| 22 | * 配置Spring Security | 22 | * 配置Spring Security |
| 23 | + * @author lin | ||
| 23 | */ | 24 | */ |
| 24 | @Configuration | 25 | @Configuration |
| 25 | @EnableWebSecurity | 26 | @EnableWebSecurity |
| @@ -132,15 +133,19 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | @@ -132,15 +133,19 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
| 132 | .anyRequest().authenticated() | 133 | .anyRequest().authenticated() |
| 133 | // 异常处理(权限拒绝、登录失效等) | 134 | // 异常处理(权限拒绝、登录失效等) |
| 134 | .and().exceptionHandling() | 135 | .and().exceptionHandling() |
| 135 | - .authenticationEntryPoint(anonymousAuthenticationEntryPoint)//匿名用户访问无权限资源时的异常处理 | 136 | + //匿名用户访问无权限资源时的异常处理 |
| 137 | + .authenticationEntryPoint(anonymousAuthenticationEntryPoint) | ||
| 136 | // .accessDeniedHandler(accessDeniedHandler)//登录用户没有权限访问资源 | 138 | // .accessDeniedHandler(accessDeniedHandler)//登录用户没有权限访问资源 |
| 137 | - // 登入 | ||
| 138 | - .and().formLogin().permitAll()//允许所有用户 | ||
| 139 | - .successHandler(loginSuccessHandler)//登录成功处理逻辑 | ||
| 140 | - .failureHandler(loginFailureHandler)//登录失败处理逻辑 | 139 | + // 登入 允许所有用户 |
| 140 | + .and().formLogin().permitAll() | ||
| 141 | + //登录成功处理逻辑 | ||
| 142 | + .successHandler(loginSuccessHandler) | ||
| 143 | + //登录失败处理逻辑 | ||
| 144 | + .failureHandler(loginFailureHandler) | ||
| 141 | // 登出 | 145 | // 登出 |
| 142 | - .and().logout().logoutUrl("/api/user/logout").permitAll()//允许所有用户 | ||
| 143 | - .logoutSuccessHandler(logoutHandler)//登出成功处理逻辑 | 146 | + .and().logout().logoutUrl("/api/user/logout").permitAll() |
| 147 | + //登出成功处理逻辑 | ||
| 148 | + .logoutSuccessHandler(logoutHandler) | ||
| 144 | .deleteCookies("JSESSIONID") | 149 | .deleteCookies("JSESSIONID") |
| 145 | // 会话管理 | 150 | // 会话管理 |
| 146 | // .and().sessionManagement().invalidSessionStrategy(invalidSessionHandler) // 超时处理 | 151 | // .and().sessionManagement().invalidSessionStrategy(invalidSessionHandler) // 超时处理 |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
| @@ -64,16 +64,14 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp | @@ -64,16 +64,14 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp | ||
| 64 | device.setHostAddress(received.concat(":").concat(String.valueOf(rPort))); | 64 | device.setHostAddress(received.concat(":").concat(String.valueOf(rPort))); |
| 65 | } | 65 | } |
| 66 | device.setKeepaliveTime(DateUtil.getNow()); | 66 | device.setKeepaliveTime(DateUtil.getNow()); |
| 67 | + // 回复200 OK | ||
| 68 | + responseAck(evt, Response.OK); | ||
| 67 | if (device.getOnline() == 1) { | 69 | if (device.getOnline() == 1) { |
| 68 | - // 回复200 OK | ||
| 69 | - responseAck(evt, Response.OK); | ||
| 70 | deviceService.updateDevice(device); | 70 | deviceService.updateDevice(device); |
| 71 | }else { | 71 | }else { |
| 72 | // 对于已经离线的设备判断他的注册是否已经过期 | 72 | // 对于已经离线的设备判断他的注册是否已经过期 |
| 73 | if (!deviceService.expire(device)){ | 73 | if (!deviceService.expire(device)){ |
| 74 | deviceService.online(device); | 74 | deviceService.online(device); |
| 75 | - // 回复200 OK | ||
| 76 | - responseAck(evt, Response.OK); | ||
| 77 | } | 75 | } |
| 78 | } | 76 | } |
| 79 | } catch (SipException e) { | 77 | } catch (SipException e) { |