Commit d77de842 by 张乐 Committed by GitHub

Merge pull request #296 from nobodyiam/sso-heartbeat-ctrip

dynamic sso heartbeat controller
parents d8a4475d eb199d3a
package com.ctrip.framework.apollo.portal.auth;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class CtripSsoHeartbeatHandler implements SsoHeartbeatHandler {
@Override
public void doHeartbeat(HttpServletRequest request, HttpServletResponse response) {
try {
response.sendRedirect("ctrip_sso_heartbeat.html");
} catch (IOException e) {
}
}
}
package com.ctrip.framework.apollo.portal.auth;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class DefaultSsoHeartbeatHandler implements SsoHeartbeatHandler {
@Override
public void doHeartbeat(HttpServletRequest request, HttpServletResponse response) {
try {
response.getWriter().write("default sso heartbeat handler");
} catch (IOException e) {
}
}
}
package com.ctrip.framework.apollo.portal.auth;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public interface SsoHeartbeatHandler {
void doHeartbeat(HttpServletRequest request, HttpServletResponse response);
}
package com.ctrip.framework.apollo.portal.configutation; package com.ctrip.framework.apollo.portal.configutation;
import com.ctrip.framework.apollo.portal.auth.CtripLogoutHandler; import com.ctrip.framework.apollo.portal.auth.CtripLogoutHandler;
import com.ctrip.framework.apollo.portal.auth.CtripSsoHeartbeatHandler;
import com.ctrip.framework.apollo.portal.auth.CtripUserInfoHolder; import com.ctrip.framework.apollo.portal.auth.CtripUserInfoHolder;
import com.ctrip.framework.apollo.portal.auth.CtripUserService; import com.ctrip.framework.apollo.portal.auth.CtripUserService;
import com.ctrip.framework.apollo.portal.auth.DefaultLogoutHandler; import com.ctrip.framework.apollo.portal.auth.DefaultLogoutHandler;
import com.ctrip.framework.apollo.portal.auth.DefaultSsoHeartbeatHandler;
import com.ctrip.framework.apollo.portal.auth.DefaultUserInfoHolder; import com.ctrip.framework.apollo.portal.auth.DefaultUserInfoHolder;
import com.ctrip.framework.apollo.portal.auth.DefaultUserService; import com.ctrip.framework.apollo.portal.auth.DefaultUserService;
import com.ctrip.framework.apollo.portal.auth.LogoutHandler; import com.ctrip.framework.apollo.portal.auth.LogoutHandler;
import com.ctrip.framework.apollo.portal.auth.SsoHeartbeatHandler;
import com.ctrip.framework.apollo.portal.auth.UserInfoHolder; import com.ctrip.framework.apollo.portal.auth.UserInfoHolder;
import com.ctrip.framework.apollo.portal.service.ServerConfigService; import com.ctrip.framework.apollo.portal.service.ServerConfigService;
import com.ctrip.framework.apollo.portal.service.UserService; import com.ctrip.framework.apollo.portal.service.UserService;
...@@ -152,6 +155,11 @@ public class AuthConfiguration { ...@@ -152,6 +155,11 @@ public class AuthConfiguration {
public UserService ctripUserService(ServerConfigService serverConfigService) { public UserService ctripUserService(ServerConfigService serverConfigService) {
return new CtripUserService(serverConfigService); return new CtripUserService(serverConfigService);
} }
@Bean
public SsoHeartbeatHandler ctripSsoHeartbeatHandler() {
return new CtripSsoHeartbeatHandler();
}
} }
/** /**
...@@ -161,6 +169,12 @@ public class AuthConfiguration { ...@@ -161,6 +169,12 @@ public class AuthConfiguration {
static class DefaultAuthAutoConfiguration { static class DefaultAuthAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(SsoHeartbeatHandler.class)
public SsoHeartbeatHandler defaultSsoHeartbeatHandler() {
return new DefaultSsoHeartbeatHandler();
}
@Bean
@ConditionalOnMissingBean(UserInfoHolder.class) @ConditionalOnMissingBean(UserInfoHolder.class)
public DefaultUserInfoHolder notCtripUserInfoHolder(){ public DefaultUserInfoHolder notCtripUserInfoHolder(){
return new DefaultUserInfoHolder(); return new DefaultUserInfoHolder();
......
package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.portal.auth.SsoHeartbeatHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Since sso auth information has a limited expiry time, so we need to do sso heartbeat to keep the
* information refreshed when unavailable
*
* @author Jason Song(song_s@ctrip.com)
*/
@Controller
@RequestMapping("/sso_heartbeat")
public class SsoHeartbeatController {
@Autowired
private SsoHeartbeatHandler handler;
@RequestMapping(value = "", method = RequestMethod.GET)
public void heartbeat(HttpServletRequest request, HttpServletResponse response) {
handler.doHeartbeat(request, response);
}
}
...@@ -5,4 +5,4 @@ ...@@ -5,4 +5,4 @@
<a href="http://conf.ctripcorp.com/display/FRAM/Apollo" target="_blank">wiki</a> <a href="http://conf.ctripcorp.com/display/FRAM/Apollo" target="_blank">wiki</a>
</p> </p>
</div> </div>
<iframe src="/sso_heartbeat.html" class="hide"></iframe> <iframe src="/sso_heartbeat" class="hide"></iframe>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment