Coverage Report - com.ctrip.framework.apollo.portal.auth.CtripUserInfoHolder
 
Classes in this File Line Coverage Branch Coverage Complexity
CtripUserInfoHolder
0%
0/19
N/A
3.5
 
 1  
 package com.ctrip.framework.apollo.portal.auth;
 2  
 
 3  
 import com.ctrip.framework.apollo.portal.entity.po.UserInfo;
 4  
 
 5  
 import java.lang.reflect.Method;
 6  
 
 7  
 /**
 8  
  * ctrip内部实现的获取用户信息
 9  
  */
 10  
 public class CtripUserInfoHolder implements UserInfoHolder{
 11  
 
 12  
   private Object assertionHolder;
 13  
 
 14  
   private Method getAssertion;
 15  
 
 16  
 
 17  0
   public CtripUserInfoHolder() {
 18  0
     Class clazz = null;
 19  
     try {
 20  0
       clazz = Class.forName("org.jasig.cas.client.util.AssertionHolder");
 21  0
       assertionHolder = clazz.newInstance();
 22  0
       getAssertion = assertionHolder.getClass().getMethod("getAssertion");
 23  0
     } catch (Exception e) {
 24  0
       throw new RuntimeException("init AssertionHolder fail", e);
 25  0
     }
 26  0
   }
 27  
 
 28  
   @Override
 29  
   public UserInfo getUser() {
 30  
     try {
 31  
 
 32  0
       Object assertion = getAssertion.invoke(assertionHolder);
 33  0
       Method getPrincipal = assertion.getClass().getMethod("getPrincipal");
 34  0
       Object principal = getPrincipal.invoke(assertion);
 35  0
       Method getName = principal.getClass().getMethod("getName");
 36  0
       String name = (String) getName.invoke(principal);
 37  
 
 38  0
       UserInfo userInfo = new UserInfo();
 39  0
       userInfo.setUserId(name);
 40  
 
 41  0
       return userInfo;
 42  0
     } catch (Exception e) {
 43  0
       throw new RuntimeException("get user info from assertion holder error", e);
 44  
     }
 45  
   }
 46  
 
 47  
 }