org.jasig.cas.client.util.AbstractCasFilter Java Examples

The following examples show how to use org.jasig.cas.client.util.AbstractCasFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexController.java    From CAS with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/caslogin", method = RequestMethod.GET)
public void caslogin() throws IOException {
    HttpSession session = request.getSession();
    Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
    if (assertion != null) {
        //获取登录用户名
        String username = assertion.getPrincipal().getName();
        System.out.println("user ---------> " + username);
        User temp = userService.findByUsername(username);
        System.out.println("TEMP user ---------> " + (temp.getUsername()));
        if (temp != null) {
            session.setAttribute(WebSecurityConfig.SESSION_LOGIN, temp);

            String jsessionid = session.getId();

            System.out.println("jsessionid ------> " + jsessionid);

            // 使用url传递参数,跳转到前端
            // response.sendRedirect("http://front.anumbrella.net:8000/home?jsessionid=" + jsessionid);

            // 使用nginx代理,跳转到前端
            response.sendRedirect("http://nginx.anumbrella.net:81/home");
        }
    }
}
 
Example #2
Source File: WebSecurityConfig.java    From CAS with Apache License 2.0 6 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
    HttpSession session = request.getSession(false);

    if (session != null) {
        System.out.println("requst path " + request.getServletPath());

        Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);

        if (assertion != null) {
            System.out.println("cas user ---------> " + assertion.getPrincipal().getName());
        }

        User value = (User) session.getAttribute(SESSION_LOGIN);

        System.out.println("security session = null ---------> " + (value == null));

        if (value != null) {
            return true;
        }
    }

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    return false;
}
 
Example #3
Source File: WebSecurityConfig.java    From CAS with Apache License 2.0 6 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
    HttpSession session = request.getSession();


    //获取cas给我们传递回来的对象,这个东西放到了session中
    //session的 key是 _const_cas_assertion_
    Assertion assertion = (Assertion) request.getSession().getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);

    //获取登录用户名
    String loginName = assertion.getPrincipal().getName();
    System.out.printf("登录用户名:%s\r\n", loginName);


    // 判断是否已有该用户登录的session
    if (session.getAttribute(SESSION_KEY) != null) {
        return true;
    }


    // 跳转到登录页
    String url = "/login";
    response.sendRedirect(url);
    return false;
}
 
Example #4
Source File: WebSecurityConfig.java    From CAS with Apache License 2.0 6 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
    HttpSession session = request.getSession();


    //获取cas给我们传递回来的对象,这个东西放到了session中
    //session的 key是 _const_cas_assertion_
    Assertion assertion = (Assertion) request.getSession().getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);

    //获取登录用户名
    String loginName = assertion.getPrincipal().getName();
    System.out.printf("登录用户名:%s\r\n", loginName);


    // 判断是否已有该用户登录的session
    if (session.getAttribute(SESSION_KEY) != null) {
        return true;
    }


    // 跳转到登录页
    String url = "/login";
    response.sendRedirect(url);
    return false;
}
 
Example #5
Source File: CasSsoService3.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Get a new ticket.
 * 
 * @param session HttpSession
 * 
 * @return String
 * 
 * @throws IOException Signals that an I/O exception has occurred.
 */
public String readTicket(HttpSession session) throws IOException{
 logger.debug("IN");
 String ticket=null;
 String spagoBiServerURL = EnginConf.getInstance().getSpagoBiServerUrl();
 logger.debug("Read spagoBiServerURL=" + spagoBiServerURL);
 SourceBean engineConfig = EnginConf.getInstance().getConfig();
 SourceBean sourceBeanConf = (SourceBean) engineConfig.getAttribute("FILTER_RECEIPT");
 String filterReceipt = (String) sourceBeanConf.getCharacters();
 logger.debug("Read filterReceipt=" + filterReceipt);
 filterReceipt = spagoBiServerURL + filterReceipt;
 
 Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
 ticket=assertion.getPrincipal().getProxyTicketFor(filterReceipt);

 logger.debug("OUT.ticket="+ticket);
 return ticket;
}
 
Example #6
Source File: CasSsoService5.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
public String readUserIdentifier(HttpServletRequest request){
   HttpSession session=request.getSession();
   Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
   if (assertion == null) {
   	return super.readUserIdentifier(request);
   }
   String userInSession=assertion.getPrincipal().getName();

//String user=(String)request.getRemoteUser();
//logger.debug("CAS user in HttpServletRequest:"+user);
logger.debug("CAS user in HttpSession:"+userInSession);
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.HOUR, 10);
Date expiresAt = calendar.getTime();
	
String jwtToken = JWTSsoService.userId2jwtToken(userInSession, expiresAt);
logger.debug("JWT-TOKEN " + jwtToken);
	
return jwtToken;
  }
 
Example #7
Source File: ShiroCasWebFilterConfiguration.java    From shiro-cas-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean<AbstractCasFilter> authenticationFilter() {
	FilterRegistrationBean<AbstractCasFilter> filterRegistration = new FilterRegistrationBean<AbstractCasFilter>();
	if (Protocol.SAML11.equals(casProperties.getProtocol())) {
		filterRegistration.setFilter(new Saml11AuthenticationFilter());
	} else {
		filterRegistration.setFilter(new AuthenticationFilter());
	}
	
	if(StringUtils.hasText(casProperties.getAuthenticationRedirectStrategyClass())) {	
		filterRegistration.addInitParameter(ConfigurationKeys.AUTHENTICATION_REDIRECT_STRATEGY_CLASS.getName(), casProperties.getAuthenticationRedirectStrategyClass());
	}
	filterRegistration.addInitParameter(ConfigurationKeys.CAS_SERVER_LOGIN_URL.getName(), casProperties.getCasServerLoginUrl());
	filterRegistration.addInitParameter(ConfigurationKeys.ENCODE_SERVICE_URL.getName(), Boolean.toString(casProperties.isEncodeServiceUrl()));
	filterRegistration.addInitParameter(ConfigurationKeys.GATEWAY.getName(), Boolean.toString(casProperties.isGateway()));
	if(StringUtils.hasText(casProperties.getGatewayStorageClass())) {	
		filterRegistration.addInitParameter(ConfigurationKeys.GATEWAY_STORAGE_CLASS.getName(), casProperties.getGatewayStorageClass());
	}
	if(StringUtils.hasText(casProperties.getIgnorePattern())) {
		filterRegistration.addInitParameter(ConfigurationKeys.IGNORE_PATTERN.getName(), casProperties.getIgnorePattern());
	}
	filterRegistration.addInitParameter(ConfigurationKeys.IGNORE_URL_PATTERN_TYPE.getName(), casProperties.getIgnoreUrlPatternType().toString());
	//filterRegistration.addInitParameter(ConfigurationKeys.RENEW.getName(), Boolean.toString(properties.isRenew()));
	if(StringUtils.hasText(casProperties.getServerName())) {	
		filterRegistration.addInitParameter(ConfigurationKeys.SERVER_NAME.getName(), casProperties.getServerName());
	} else if(StringUtils.hasText(casProperties.getService())) {	
		filterRegistration.addInitParameter(ConfigurationKeys.SERVICE.getName(), casProperties.getService());
	}
	
	filterRegistration.addUrlPatterns(casProperties.getAuthenticationFilterUrlPatterns());
	filterRegistration.setOrder(4);
	return filterRegistration;
}
 
Example #8
Source File: CasSsoService3.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
    * Read user id.
    * 
    * @param session HttpSession
    * 
    * @return String
    */
   public String readUserIdentifier(HttpServletRequest request){
   HttpSession session=request.getSession();
   Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
   String userInSession=assertion.getPrincipal().getName();
//String user=(String)request.getRemoteUser();
//logger.debug("CAS user in HttpServletRequest:"+user);
logger.debug("CAS user in HttpSession:"+userInSession);
return userInSession;
   }
 
Example #9
Source File: CasSsoService3NoProxy.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
    * Read user id.
    * 
    * @param session HttpSession
    * 
    * @return String
    */
   public String readUserIdentifier(HttpServletRequest request){
   HttpSession session=request.getSession();
   Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
   String userInSession=assertion.getPrincipal().getName();
String user=(String)request.getRemoteUser();
logger.debug("CAS user in HttpServletRequest:"+user);
logger.debug("CAS user in HttpSession:"+userInSession);
return user!=null? user:userInSession;
   }
 
Example #10
Source File: CasSsoService3.java    From Knowage-Server with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
    * Read user id.
    * 
    * @param session PortletSession
    * 
    * @return String
    */
   public String readUserIdentifier(PortletSession session){
   Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
   String user=assertion.getPrincipal().getName();
logger.debug("CAS user in PortletSession:"+user);
return user;
   }
 
Example #11
Source File: CasSsoService3NoProxy.java    From Knowage-Server with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
    * Read user id.
    * 
    * @param session PortletSession
    * 
    * @return String
    */
   public String readUserIdentifier(PortletSession session){
   Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
   String user=assertion.getPrincipal().getName();
logger.debug("CAS user in PortletSession:"+user);
return user;
   }