|
@@ -1,73 +0,0 @@
|
|
|
-package com.dragoninfo.dcuc.authweb.restcontroller.api.controller;
|
|
|
-
|
|
|
-import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-import org.apache.http.HttpResponse;
|
|
|
-import org.apache.http.NameValuePair;
|
|
|
-import org.apache.http.client.HttpClient;
|
|
|
-import org.apache.http.client.methods.HttpGet;
|
|
|
-import org.apache.http.client.utils.URIBuilder;
|
|
|
-import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
-import org.apache.http.message.BasicNameValuePair;
|
|
|
-import org.apache.http.util.EntityUtils;
|
|
|
-import org.jasig.cas.client.util.XmlUtils;
|
|
|
-import org.jasig.cas.client.validation.Assertion;
|
|
|
-import org.jasig.cas.client.validation.Cas20ServiceTicketValidator;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-
|
|
|
- *
|
|
|
- * @author Administrator
|
|
|
- * @date 2019/3/5
|
|
|
- */
|
|
|
-@Controller
|
|
|
-@RequestMapping(value = "/api/")
|
|
|
-public class RestLoginController {
|
|
|
- @RequestMapping(value = "login")
|
|
|
- public void login(@RequestParam(value = "ticket", required = false) String ticket,
|
|
|
- HttpServletRequest request,
|
|
|
- HttpServletResponse response) {
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(request.getParameter("logoutRequest"))) {
|
|
|
- String logoutMessage = request.getParameter("logoutRequest");
|
|
|
- final String key = XmlUtils.getTextForElement(logoutMessage, "SessionIndex");
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(ticket)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- HttpClient httpclient = HttpClientBuilder.create().build();
|
|
|
- String casTicketValidateUrl = "http://54.179.163.62:8080/dcucserver/serviceValidate";
|
|
|
- URIBuilder uriBuilder = null;
|
|
|
- try {
|
|
|
- uriBuilder = new URIBuilder(casTicketValidateUrl);
|
|
|
- List<NameValuePair> params = Lists.newArrayList();
|
|
|
- params.add(new BasicNameValuePair("ticket", ticket));
|
|
|
- params.add(new BasicNameValuePair("service", "http://172.16.105.196:8888/dcuc/api/login"));
|
|
|
- uriBuilder.addParameters(params);
|
|
|
- HttpGet httpGet = new HttpGet(uriBuilder.build());
|
|
|
- httpGet.addHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
- HttpResponse httpResponse = httpclient.execute(httpGet);
|
|
|
- String tokenResponse = EntityUtils.toString(httpResponse.getEntity());
|
|
|
-
|
|
|
- Cas20ServiceTicketValidator cas20ServiceTicketValidator = new Cas20ServiceTicketValidator("");
|
|
|
- Assertion assertion = cas20ServiceTicketValidator.parseResponse(tokenResponse);
|
|
|
- String userId = assertion.getPrincipal().getName();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- response.sendRedirect(request.getContextPath() + "/index");
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-}
|