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

The following examples show how to use org.joda.time.DateTime#isAfterNow() . 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: SessionManagerImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
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
Source File: SessionManagerImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
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
Source File: AuthenticationHandlerSAML2.java    From sling-whiteboard with Apache License 2.0 6 votes vote down vote up
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 File: RemoteKerberosService.java    From MaxKey with 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 File: ReadDnsQueueAction.java    From nomulus with 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
Source File: ExecutionSemester.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: TokenExpiredRenew.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
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 8
Source File: WrittenEvaluation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 9
Source File: WrittenEvaluation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 10
Source File: WrittenEvaluation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 11
Source File: SAMLTokenValidator.java    From cxf with 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 12
Source File: BlockingHttpClient.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
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 File: UserRoleManage.java    From bbs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 查询用户角色名称(排除默认角色)
 * @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 14
Source File: SessionManagerImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
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 15
Source File: TokenExpiredRenew.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
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 16
Source File: SlidingWindowRenewStrategy.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
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 17
Source File: SessionManagerImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
   }
}