Commit a16c9a9a993b645fdf24cb8a9d22c33ad1ee6658
1 parent
11725b5d
update
Showing
1 changed file
with
14 additions
and
144 deletions
src/main/java/com/cnlive/shenhe/ShenheApplication.java
| @@ -9,18 +9,12 @@ import org.slf4j.Logger; | @@ -9,18 +9,12 @@ import org.slf4j.Logger; | ||
| 9 | import org.slf4j.LoggerFactory; | 9 | import org.slf4j.LoggerFactory; |
| 10 | import org.springframework.beans.factory.annotation.Value; | 10 | import org.springframework.beans.factory.annotation.Value; |
| 11 | import org.springframework.boot.ApplicationRunner; | 11 | import org.springframework.boot.ApplicationRunner; |
| 12 | -import org.springframework.boot.SpringApplication; | ||
| 13 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 12 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 14 | -import org.springframework.boot.builder.SpringApplicationBuilder; | ||
| 15 | import org.springframework.boot.web.servlet.FilterRegistrationBean; | 13 | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| 16 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | 14 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
| 17 | import org.springframework.context.annotation.Bean; | 15 | import org.springframework.context.annotation.Bean; |
| 18 | import org.springframework.context.annotation.Configuration; | 16 | import org.springframework.context.annotation.Configuration; |
| 19 | import org.springframework.stereotype.Controller; | 17 | import org.springframework.stereotype.Controller; |
| 20 | -import org.springframework.ui.Model; | ||
| 21 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 22 | -import org.springframework.web.servlet.ModelAndView; | ||
| 23 | - | ||
| 24 | import tk.mybatis.spring.annotation.MapperScan; | 18 | import tk.mybatis.spring.annotation.MapperScan; |
| 25 | 19 | ||
| 26 | import java.net.InetAddress; | 20 | import java.net.InetAddress; |
| @@ -29,7 +23,7 @@ import java.util.HashMap; | @@ -29,7 +23,7 @@ import java.util.HashMap; | ||
| 29 | import java.util.Map; | 23 | import java.util.Map; |
| 30 | 24 | ||
| 31 | @SpringBootApplication | 25 | @SpringBootApplication |
| 32 | -@MapperScan(basePackages= {"com.cnlive.shenhe.mapper"}) | 26 | +@MapperScan(basePackages = {"com.cnlive.shenhe.mapper"}) |
| 33 | public class ShenheApplication extends SpringBootServletInitializer { | 27 | public class ShenheApplication extends SpringBootServletInitializer { |
| 34 | 28 | ||
| 35 | //url的前缀 | 29 | //url的前缀 |
| @@ -47,6 +41,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -47,6 +41,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 47 | 41 | ||
| 48 | /** | 42 | /** |
| 49 | * 用于实现单点登出功能 | 43 | * 用于实现单点登出功能 |
| 44 | + * | ||
| 50 | * @return | 45 | * @return |
| 51 | */ | 46 | */ |
| 52 | @Bean | 47 | @Bean |
| @@ -55,7 +50,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -55,7 +50,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 55 | registration.setFilter(new SingleSignOutFilter()); | 50 | registration.setFilter(new SingleSignOutFilter()); |
| 56 | // 设定匹配的路径 | 51 | // 设定匹配的路径 |
| 57 | registration.addUrlPatterns("/*"); | 52 | registration.addUrlPatterns("/*"); |
| 58 | - Map<String,String> initParameters = new HashMap<String, String>(); | 53 | + Map<String, String> initParameters = new HashMap<String, String>(); |
| 59 | initParameters.put("casServerUrlPrefix", CAS_SERVER_URL_PREFIX); | 54 | initParameters.put("casServerUrlPrefix", CAS_SERVER_URL_PREFIX); |
| 60 | registration.setInitParameters(initParameters); | 55 | registration.setInitParameters(initParameters); |
| 61 | // 设定加载的顺序 | 56 | // 设定加载的顺序 |
| @@ -65,6 +60,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -65,6 +60,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 65 | 60 | ||
| 66 | /** | 61 | /** |
| 67 | * 该过滤器负责用户的认证工作 | 62 | * 该过滤器负责用户的认证工作 |
| 63 | + * | ||
| 68 | * @return | 64 | * @return |
| 69 | */ | 65 | */ |
| 70 | @Bean | 66 | @Bean |
| @@ -73,7 +69,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -73,7 +69,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 73 | registration.setFilter(new AuthenticationFilter()); | 69 | registration.setFilter(new AuthenticationFilter()); |
| 74 | // 设定匹配的路径 | 70 | // 设定匹配的路径 |
| 75 | registration.addUrlPatterns("/*"); | 71 | registration.addUrlPatterns("/*"); |
| 76 | - Map<String,String> initParameters = new HashMap<String, String>(); | 72 | + Map<String, String> initParameters = new HashMap<String, String>(); |
| 77 | initParameters.put("casServerLoginUrl", CAS_SERVER_LOGIN_URL); | 73 | initParameters.put("casServerLoginUrl", CAS_SERVER_LOGIN_URL); |
| 78 | initParameters.put("service", SERVICE_LOGIN); | 74 | initParameters.put("service", SERVICE_LOGIN); |
| 79 | initParameters.put("ignorePattern", "/api/*|/logging/*"); | 75 | initParameters.put("ignorePattern", "/api/*|/logging/*"); |
| @@ -86,6 +82,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -86,6 +82,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 86 | 82 | ||
| 87 | /** | 83 | /** |
| 88 | * 该过滤器负责对Ticket的校验工作 | 84 | * 该过滤器负责对Ticket的校验工作 |
| 85 | + * | ||
| 89 | * @return | 86 | * @return |
| 90 | */ | 87 | */ |
| 91 | @Bean | 88 | @Bean |
| @@ -94,10 +91,10 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -94,10 +91,10 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 94 | registration.setFilter(new Cas20ProxyReceivingTicketValidationFilter()); | 91 | registration.setFilter(new Cas20ProxyReceivingTicketValidationFilter()); |
| 95 | // 设定匹配的路径 | 92 | // 设定匹配的路径 |
| 96 | registration.addUrlPatterns("/*"); | 93 | registration.addUrlPatterns("/*"); |
| 97 | - Map<String,String> initParameters = new HashMap<String, String>(); | 94 | + Map<String, String> initParameters = new HashMap<String, String>(); |
| 98 | initParameters.put("casServerUrlPrefix", CAS_SERVER_URL_PREFIX); | 95 | initParameters.put("casServerUrlPrefix", CAS_SERVER_URL_PREFIX); |
| 99 | initParameters.put("serverName", SERVER_NAME); | 96 | initParameters.put("serverName", SERVER_NAME); |
| 100 | - initParameters.put("encoding","utf-8"); | 97 | + initParameters.put("encoding", "utf-8"); |
| 101 | registration.setInitParameters(initParameters); | 98 | registration.setInitParameters(initParameters); |
| 102 | // 设定加载的顺序 | 99 | // 设定加载的顺序 |
| 103 | registration.setOrder(3); | 100 | registration.setOrder(3); |
| @@ -107,7 +104,8 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -107,7 +104,8 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 107 | 104 | ||
| 108 | /** | 105 | /** |
| 109 | * 该过滤器负责实现HttpServletRequest请求的包裹, | 106 | * 该过滤器负责实现HttpServletRequest请求的包裹, |
| 110 | - * 比如允许开发者通过HttpServletRequest的getRemoteUser()方法获得SSO登录用户的登录名,可选配置。 | 107 | + * 比如允许开发者通过HttpServletRequest的getRemoteUser()方法获得SSO登录用户的登录名,可选配置。 |
| 108 | + * | ||
| 111 | * @return | 109 | * @return |
| 112 | */ | 110 | */ |
| 113 | @Bean | 111 | @Bean |
| @@ -123,7 +121,8 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -123,7 +121,8 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 123 | 121 | ||
| 124 | /** | 122 | /** |
| 125 | * 该过滤器使得开发者可以通过org.jasig.cas.client.util.AssertionHolder来获取 | 123 | * 该过滤器使得开发者可以通过org.jasig.cas.client.util.AssertionHolder来获取 |
| 126 | - * 用户的登录名。比如AssertionHolder.getAssertion().getPrincipal().getName()。 | 124 | + * 用户的登录名。比如AssertionHolder.getAssertion().getPrincipal().getName()。 |
| 125 | + * | ||
| 127 | * @return | 126 | * @return |
| 128 | */ | 127 | */ |
| 129 | @Bean | 128 | @Bean |
| @@ -137,137 +136,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -137,137 +136,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 137 | return registration; | 136 | return registration; |
| 138 | } | 137 | } |
| 139 | 138 | ||
| 140 | - | ||
| 141 | - | ||
| 142 | - | ||
| 143 | - | ||
| 144 | - | ||
| 145 | - | ||
| 146 | - | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - | ||
| 151 | - | ||
| 152 | - | ||
| 153 | /** | 139 | /** |
| 154 | - * 登录过滤器 | ||
| 155 | - * @return | ||
| 156 | - */ | ||
| 157 | - /* @Bean | ||
| 158 | - public FilterRegistrationBean filterSingleRegistration() { | ||
| 159 | - FilterRegistrationBean registration = new FilterRegistrationBean(); | ||
| 160 | - registration.setFilter(new SingleSignOutFilter()); | ||
| 161 | - // 设定匹配的路径 | ||
| 162 | - registration.addUrlPatterns("/*"); | ||
| 163 | - Map<String,String> initParameters = new HashMap<String, String>(); | ||
| 164 | - initParameters.put("casServerUrlPrefix", CAS_SERVER_URL_PREFIX); | ||
| 165 | - registration.setInitParameters(initParameters); | ||
| 166 | - // 设定加载的顺序 | ||
| 167 | - registration.setOrder(1); | ||
| 168 | - return registration; | ||
| 169 | - } | ||
| 170 | - | ||
| 171 | - *//** | ||
| 172 | - * 过滤验证器 | ||
| 173 | - * @return | ||
| 174 | - *//* | ||
| 175 | - @Bean | ||
| 176 | - public FilterRegistrationBean filterValidationRegistration() { | ||
| 177 | - FilterRegistrationBean registration = new FilterRegistrationBean(); | ||
| 178 | - registration.setFilter(new Cas30ProxyReceivingTicketValidationFilter()); | ||
| 179 | - // 设定匹配的路径 | ||
| 180 | - registration.addUrlPatterns("/*"); | ||
| 181 | - Map<String,String> initParameters = new HashMap<String, String>(); | ||
| 182 | - initParameters.put("casServerUrlPrefix", CAS_SERVER_URL_PREFIX); | ||
| 183 | - initParameters.put("serverName", SERVER_NAME); | ||
| 184 | - initParameters.put("useSession", "true"); | ||
| 185 | - registration.setInitParameters(initParameters); | ||
| 186 | - // 设定加载的顺序 | ||
| 187 | - registration.setOrder(1); | ||
| 188 | - return registration; | ||
| 189 | - } | ||
| 190 | - | ||
| 191 | - *//** | ||
| 192 | - * 授权过滤器 | ||
| 193 | - * @return | ||
| 194 | - *//* | ||
| 195 | - *//*@Bean | ||
| 196 | - public FilterRegistrationBean filterAuthenticationRegistration() { | ||
| 197 | - FilterRegistrationBean registration = new FilterRegistrationBean(); | ||
| 198 | - registration.setFilter(new AuthenticationFilter()); | ||
| 199 | - // 设定匹配的路径 | ||
| 200 | - registration.addUrlPatterns("/*"); | ||
| 201 | - Map<String,String> initParameters = new HashMap<String, String>(); | ||
| 202 | - initParameters.put("casServerLoginUrl", CAS_SERVER_URL_PREFIX); | ||
| 203 | - initParameters.put("server", SERVICE_LOGIN); | ||
| 204 | - | ||
| 205 | - //initParameters.put("ignorePattern", ".*"); | ||
| 206 | - //表示过滤所有 | ||
| 207 | - //initParameters.put("ignoreUrlPatternType", "com.cnlive.shenhe.config.SimpleUrlPatternMatcherStrategy"); | ||
| 208 | - | ||
| 209 | - registration.setInitParameters(initParameters); | ||
| 210 | - // 设定加载的顺序 | ||
| 211 | - registration.setOrder(1); | ||
| 212 | - return registration; | ||
| 213 | - }*//* | ||
| 214 | - | ||
| 215 | - *//** | ||
| 216 | - * wraper过滤器 | ||
| 217 | - * @return | ||
| 218 | - *//* | ||
| 219 | - @Bean | ||
| 220 | - public FilterRegistrationBean filterWrapperRegistration() { | ||
| 221 | - FilterRegistrationBean registration = new FilterRegistrationBean(); | ||
| 222 | - registration.setFilter(new HttpServletRequestWrapperFilter()); | ||
| 223 | - // 设定匹配的路径 | ||
| 224 | - registration.addUrlPatterns("/*"); | ||
| 225 | - // 设定加载的顺序 | ||
| 226 | - registration.setOrder(1); | ||
| 227 | - return registration; | ||
| 228 | - } | ||
| 229 | - | ||
| 230 | - *//** | ||
| 231 | - * 添加监听器 | ||
| 232 | - * @return | ||
| 233 | - *//* | ||
| 234 | - @Bean | ||
| 235 | - public ServletListenerRegistrationBean<EventListener> singleSignOutListenerRegistration(){ | ||
| 236 | - ServletListenerRegistrationBean<EventListener> registrationBean = new ServletListenerRegistrationBean<EventListener>(); | ||
| 237 | - registrationBean.setListener(new SingleSignOutHttpSessionListener()); | ||
| 238 | - registrationBean.setOrder(1); | ||
| 239 | - return registrationBean; | ||
| 240 | - } | ||
| 241 | - | ||
| 242 | - *//** | ||
| 243 | - * 设定首页 | ||
| 244 | - *//* | ||
| 245 | - @Configuration | ||
| 246 | - public class DefaultView extends WebMvcConfigurerAdapter { | ||
| 247 | - | ||
| 248 | - @Override | ||
| 249 | - public void addViewControllers(ViewControllerRegistry registry) { | ||
| 250 | - //设定首页为index | ||
| 251 | - registry.addViewController("/").setViewName("forward:/users/index"); | ||
| 252 | - | ||
| 253 | - //设定匹配的优先级 | ||
| 254 | - registry.setOrder(Ordered.HIGHEST_PRECEDENCE); | ||
| 255 | - | ||
| 256 | - //添加视图控制类 | ||
| 257 | - super.addViewControllers(registry); | ||
| 258 | - } | ||
| 259 | - }*/ | ||
| 260 | - | ||
| 261 | - | ||
| 262 | - public static void main(String[] args) { | ||
| 263 | -// SpringApplication.run(ShenheApplication.class, args); | ||
| 264 | - SpringApplicationBuilder builder=new SpringApplicationBuilder(ShenheApplication.class); | ||
| 265 | - builder.headless(true).run(args); | ||
| 266 | - // 设置Headless模式,linux系统下 | ||
| 267 | - System.setProperty("java.awt.headless", "true"); | ||
| 268 | - } | ||
| 269 | - | ||
| 270 | - /** | ||
| 271 | * 配置内部类 | 140 | * 配置内部类 |
| 272 | */ | 141 | */ |
| 273 | @Controller | 142 | @Controller |
| @@ -287,6 +156,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -287,6 +156,7 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 287 | */ | 156 | */ |
| 288 | @Value("${server.port}") | 157 | @Value("${server.port}") |
| 289 | private String port; | 158 | private String port; |
| 159 | + | ||
| 290 | /** | 160 | /** |
| 291 | * 启动成功 | 161 | * 启动成功 |
| 292 | */ | 162 | */ |
| @@ -303,6 +173,6 @@ public class ShenheApplication extends SpringBootServletInitializer { | @@ -303,6 +173,6 @@ public class ShenheApplication extends SpringBootServletInitializer { | ||
| 303 | } | 173 | } |
| 304 | }; | 174 | }; |
| 305 | } | 175 | } |
| 306 | - | 176 | + |
| 307 | } | 177 | } |
| 308 | } | 178 | } |