Java Code Examples for org.joda.time.DateTime#isAfterNow()

The following examples show how to use org.joda.time.DateTime#isAfterNow() . These examples are extracted from open source projects. 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
public boolean hasValidSession() throws SessionManagementException {
   LOG.debug("Checking if session exists and if session is valid...");
   if (this.getSession() != null && this.getSession().getSAMLToken() != null) {
      SAMLToken samlToken = this.getSession().getSAMLToken();
      DateTime end = SAMLHelper.getNotOnOrAfterCondition(samlToken.getAssertion());
      boolean valid = end.isAfterNow();
      if (!valid) {
         valid = this.renewSession(samlToken);
      }

      LOG.debug("Session found, valid: " + valid + ". (Valid until:" + DateUtils.printDateTime(end) + ")");
      return valid;
   } else {
      LOG.debug("No Session found");
      return false;
   }
}
 
Example 2
public boolean hasValidSession() throws SessionManagementException {
   LOG.debug("Checking if session exists and if session is valid...");
   if (this.getSession() != null && this.getSession().getSAMLToken() != null) {
      SAMLToken samlToken = this.getSession().getSAMLToken();
      DateTime end = SAMLHelper.getNotOnOrAfterCondition(samlToken.getAssertion());
      boolean valid = end.isAfterNow();
      if (!valid) {
         valid = this.renewSession(samlToken);
      }

      LOG.debug("Session found, valid: " + valid + ". (Valid until:" + DateUtils.printDateTime(end) + ")");
      return valid;
   } else {
      LOG.debug("No Session found");
      return false;
   }
}
 
Example 3
private boolean validateSaml2Conditions(HttpServletRequest req, Assertion assertion) {
    final List<SubjectConfirmation> subjectConfirmations = assertion.getSubject().getSubjectConfirmations();
    if (subjectConfirmations.isEmpty()) {
        return false;
    }
    final SubjectConfirmationData subjectConfirmationData = subjectConfirmations.get(0).getSubjectConfirmationData();
    final DateTime notOnOrAfter = subjectConfirmationData.getNotOnOrAfter();
    // validate expiration
    final boolean validTime = notOnOrAfter.isAfterNow();
    if (!validTime) {
        logger.error("SAML2 Subject Confirmation failed validation: Expired.");
    }
    // validate recipient
    final String recipient = subjectConfirmationData.getRecipient();
    final boolean validRecipient = recipient.equals(saml2ConfigService.getACSURL());
    if (!validRecipient) {
        logger.error("SAML2 Subject Confirmation failed validation: Invalid Recipient.");
    }
    // validate In Response To (ID saved in session from authnRequest)
    final String inResponseTo = subjectConfirmationData.getInResponseTo();
    final String savedInResponseTo = new SessionStorage(SAML2_REQUEST_ID).getString(req);
    boolean validID = savedInResponseTo.equals(inResponseTo);

    // return true if subject confirmation is validated
    return validTime && validRecipient && validID;
}
 
Example 4
Source Project: MaxKey   File: RemoteKerberosService.java    License: Apache License 2.0 6 votes vote down vote up
public boolean login(String kerberosTokenString,String kerberosUserDomain){
	_logger.debug("encoder Kerberos Token "+kerberosTokenString);
	_logger.debug("kerberos UserDomain "+kerberosUserDomain);
	
	String decoderKerberosToken=null;
	for(KerberosProxy kerberosProxy : kerberosProxys){
		if(kerberosProxy.getUserdomain().equalsIgnoreCase(kerberosUserDomain)){
			decoderKerberosToken=ReciprocalUtils.aesDecoder(kerberosTokenString, kerberosProxy.getCrypto());
			break;
		}
	}
	_logger.debug("decoder Kerberos Token "+decoderKerberosToken);
	KerberosToken  kerberosToken=new KerberosToken();
	kerberosToken=(KerberosToken)JsonUtils.json2Object(decoderKerberosToken, kerberosToken);
	_logger.debug("Kerberos Token "+kerberosToken);
	
	DateTime notOnOrAfter=DateUtils.toUtcDate(kerberosToken.getNotOnOrAfter());
	_logger.debug("Kerberos Token is After Now  "+notOnOrAfter.isAfterNow());
	if(notOnOrAfter.isAfterNow()){
    	return WebContext.setAuthentication(kerberosToken.getPrincipal(),ConstantsLoginType.KERBEROS,kerberosUserDomain,"","success");
	}else{
		
		return false;
	}
		
}
 
Example 5
Source Project: nomulus   File: ReadDnsQueueAction.java    License: Apache License 2.0 6 votes vote down vote up
/** Leases all tasks from the pull queue and creates per-tld update actions for them. */
@Override
public void run() {
  DateTime requestedEndTime = clock.nowUtc().plus(requestedMaximumDuration);
  ImmutableSet<String> tlds = Registries.getTlds();
  while (requestedEndTime.isAfterNow()) {
    List<TaskHandle> tasks = dnsQueue.leaseTasks(requestedMaximumDuration.plus(LEASE_PADDING));
    logger.atInfo().log("Leased %d DNS update tasks.", tasks.size());
    if (!tasks.isEmpty()) {
      dispatchTasks(ImmutableSet.copyOf(tasks), tlds);
    }
    if (tasks.size() < dnsQueue.getLeaseTasksBatchSize()) {
      return;
    }
  }
}
 
Example 6
public void renew(SessionItem session) throws SessionManagementException {
   SAMLToken samlToken = session.getSAMLToken();
   DateTime end = SAMLHelper.getNotOnOrAfterCondition(samlToken.getAssertion());
   boolean valid = end.isAfterNow();
   if (!valid) {
      executeReload(session, this.getCacheServices());
   }

}
 
Example 7
public boolean hasValidSession() throws SessionManagementException {
   LOG.debug("Checking if session exists and if session is valid...");
   if (this.getSession() != null && this.getSession().getSAMLToken() != null) {
      RenewStrategyFactory.get().renew(this.session);
      DateTime end = SAMLHelper.getNotOnOrAfterCondition(this.getSession().getSAMLToken().getAssertion());
      boolean valid = end.isAfterNow();
      LOG.debug("Session found, valid: " + valid + ". (Valid until:" + DateUtils.printDateTime(end) + ")");
      return valid;
   } else {
      LOG.debug("No Session found");
      return false;
   }
}
 
Example 8
private static long calculateDelay(DateTime end) {
   if (end.isAfterNow()) {
      Interval interval = new Interval(DateTime.now(), end);
      return interval.toDurationMillis() / (long)ConfigFactory.getConfigValidator().getIntegerProperty("be.ehealth.technicalconnector.session.renew.SlidingWindowRenewStrategy.divider", 2);
   } else {
      return 0L;
   }
}
 
Example 9
public void renew(SessionItem session) throws SessionManagementException {
   SAMLToken samlToken = session.getSAMLToken();
   DateTime end = SAMLHelper.getNotOnOrAfterCondition(samlToken.getAssertion());
   boolean valid = end.isAfterNow();
   if (!valid) {
      executeReload(session, this.getCacheServices());
   }

}
 
Example 10
public boolean hasValidSession() throws SessionManagementException {
   LOG.debug("Checking if session exists and if session is valid...");
   if (this.getSession() != null && this.getSession().getSAMLToken() != null) {
      RenewStrategyFactory.get().renew(this.session);
      DateTime end = SAMLHelper.getNotOnOrAfterCondition(this.getSession().getSAMLToken().getAssertion());
      boolean valid = end.isAfterNow();
      LOG.debug("Session found, valid: " + valid + ". (Valid until:" + DateUtils.printDateTime(end) + ")");
      return valid;
   } else {
      LOG.debug("No Session found");
      return false;
   }
}
 
Example 11
/**
 * 查询用户角色名称(排除默认角色)
 * @param userName 用户名称
 * @return
 */
public List<String> queryUserRoleName(String userName){
	List<String> roleNameList = new ArrayList<String>();
	
	//查询用户角色组
 		List<UserRoleGroup> userRoleGroupList = userRoleManage.query_cache_findRoleGroupByUserName(userName);
 		if(userRoleGroupList != null && userRoleGroupList.size() >0){
 			List<UserRole> allRoleList = userRoleService.findAllRole_cache();
 			if(allRoleList != null && allRoleList.size() >0){
 				for(UserRole userRole : allRoleList){
 					if(!userRole.getDefaultRole()){//不是默认角色
 						for(UserRoleGroup userRoleGroup : userRoleGroupList){
 			  				if(userRoleGroup.getUserRoleId().equals(userRole.getId())){
  			  				DateTime time = new DateTime(userRoleGroup.getValidPeriodEnd());  
		  					userRole.setValidPeriodEnd(userRoleGroup.getValidPeriodEnd());
		  					//和系统时间比  
		  					if(time.isAfterNow()){//判断有效期
		  						roleNameList.add(userRole.getName());
		  					}
 			  					
 			  					break;
 			  				}
 			  			}
 					}
 				}
 			}
 			
 			
 			
 		}
 		return roleNameList;
}
 
Example 12
protected CloseableHttpResponse filter(final HttpHost target, final Filterable filterable) throws IOException {
  // main target is the first accessed target
  if (mainTarget == null) {
    mainTarget = target;
  }
  // we only filter requests to our main target
  if (!target.equals(mainTarget)) {
    return filterable.call();
  }
  if (blocked) {
    throw new RemoteBlockedIOException("Remote Manually Blocked");
  }
  DateTime blockedUntilCopy = this.blockedUntil;
  if (autoBlock && blockedUntilCopy != null && blockedUntilCopy.isAfterNow()) {
    throw new RemoteBlockedIOException("Remote Auto Blocked until " + blockedUntilCopy);
  }

  try {
    CloseableHttpResponse response = filterable.call();
    int statusCode = response.getStatusLine().getStatusCode();

    if (autoBlockConfiguration.shouldBlock(statusCode)) {
      updateStatusToUnavailable(getReason(statusCode), target);
    }
    else {
      updateStatusToAvailable();
    }
    return response;
  }
  catch (IOException e) {
    if (isRemoteUnavailable(e)) {
      updateStatusToUnavailable(getReason(e), target);
    }
    throw e;
  }
}
 
Example 13
Source Project: cxf   File: SAMLTokenValidator.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean validateConditions(
    SamlAssertionWrapper assertion, ReceivedToken validateTarget
) {
    DateTime validFrom = null;
    DateTime validTill = null;
    DateTime issueInstant = null;
    if (assertion.getSamlVersion().equals(SAMLVersion.VERSION_20)) {
        validFrom = assertion.getSaml2().getConditions().getNotBefore();
        validTill = assertion.getSaml2().getConditions().getNotOnOrAfter();
        issueInstant = assertion.getSaml2().getIssueInstant();
    } else {
        validFrom = assertion.getSaml1().getConditions().getNotBefore();
        validTill = assertion.getSaml1().getConditions().getNotOnOrAfter();
        issueInstant = assertion.getSaml1().getIssueInstant();
    }

    if (validFrom != null && validFrom.isAfterNow()) {
        LOG.log(Level.WARNING, "SAML Token condition not met");
        return false;
    } else if (validTill != null && validTill.isBeforeNow()) {
        LOG.log(Level.WARNING, "SAML Token condition not met");
        validateTarget.setState(STATE.EXPIRED);
        return false;
    }

    if (issueInstant != null && issueInstant.isAfterNow()) {
        LOG.log(Level.WARNING, "SAML Token IssueInstant not met");
        return false;
    }

    return true;
}
 
Example 14
private boolean validUnEnrollment() {
    if (this.getEnrollmentEndDay() != null && this.getEnrollmentEndTime() != null) {
        DateTime enrolmentEnd = createDate(this.getEnrollmentEndDayDate(), this.getEnrollmentEndTimeDate());
        if (enrolmentEnd.isAfterNow()) {
            return true;
        }
    }
    return false;
}
 
Example 15
public void checkIfCanDistributeStudentsByRooms() {
    if (this.getWrittenEvaluationSpaceOccupationsSet().isEmpty()) {
        throw new DomainException("error.no.roms.associated");
    }

    final Date todayDate = Calendar.getInstance().getTime();
    final Date evaluationDateAndTime;
    try {
        evaluationDateAndTime =
                DateFormatUtil.parse("yyyy/MM/dd HH:mm", DateFormatUtil.format("yyyy/MM/dd ", this.getDayDate())
                        + DateFormatUtil.format("HH:mm", this.getBeginningDate()));
    } catch (ParseException e) {
        // This should never happen, the string where obtained from other
        // dates.
        throw new Error(e);
    }

    DateTime enrolmentEndDate = null;
    // This can happen if the Enrolment OccupationPeriod for Evaluation
    // wasn't defined
    if (this.getEnrollmentEndDayDate() != null && this.getEnrollmentEndTimeDate() != null) {
        enrolmentEndDate = createDate(this.getEnrollmentEndDayDate(), this.getEnrollmentEndTimeDate());
    }
    if (DateFormatUtil.isBefore("yyyy/MM/dd HH:mm", evaluationDateAndTime, todayDate)
            || (enrolmentEndDate != null && enrolmentEndDate.isAfterNow())) {
        throw new DomainException("error.out.of.period.enrollment.period");
    }
}
 
Example 16
public boolean isInEnrolmentPeriod() {
    if (this.getEnrollmentBeginDayDate() == null || this.getEnrollmentBeginTimeDate() == null
            || this.getEnrollmentEndDayDate() == null || this.getEnrollmentEndTimeDate() == null) {
        throw new DomainException("error.enrolmentPeriodNotDefined");
    }
    final DateTime enrolmentBeginDate = createDate(this.getEnrollmentBeginDayDate(), this.getEnrollmentBeginTimeDate());
    final DateTime enrolmentEndDate = createDate(this.getEnrollmentEndDayDate(), this.getEnrollmentEndTimeDate());
    return enrolmentBeginDate.isBeforeNow() && enrolmentEndDate.isAfterNow();
}
 
Example 17
public DateMidnight getThisMonday() {
    final DateTime beginningOfSemester = getBeginDateYearMonthDay().toDateTimeAtMidnight();
    final DateTime endOfSemester = getEndDateYearMonthDay().toDateTimeAtMidnight();

    if (beginningOfSemester.isAfterNow() || endOfSemester.isBeforeNow()) {
        return null;
    }

    final DateMidnight now = new DateMidnight();
    return now.withField(DateTimeFieldType.dayOfWeek(), 1);
}