org.keycloak.common.util.Time.currentTimeMillis()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.keycloak.common.util.Time.currentTimeMillis()方法的一些代码示例,展示了Time.currentTimeMillis()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Time.currentTimeMillis()方法的具体详情如下:
包路径:org.keycloak.common.util.Time
类名称:Time
方法名:currentTimeMillis

Time.currentTimeMillis介绍

[英]Returns current time in milliseconds adjusted by adding #offset) seconds.
[中]返回通过添加#偏移)秒调整的当前时间(以毫秒为单位)。

代码示例

代码示例来源:origin: org.keycloak/keycloak-adapter-core

CacheEntry(String key, PathConfig value, long maxAge) {
  this.key = key;
  this.value = value;
  if(maxAge == -1) {
    expiration = -1;
  } else {
    expiration = Time.currentTimeMillis() + maxAge;
  }
}

代码示例来源:origin: org.keycloak/keycloak-adapter-core

boolean isExpired() {
    return expiration != -1 ? Time.currentTimeMillis() > expiration : false;
  }
}

代码示例来源:origin: org.keycloak/keycloak-server-spi

public static long dailyEvictionBoundary(int hour, int minute) {
  Calendar cal = Calendar.getInstance();
  cal.setTimeInMillis(Time.currentTimeMillis());
  cal.set(Calendar.HOUR_OF_DAY, hour);
  cal.set(Calendar.MINUTE, minute);
  if (cal.getTimeInMillis() > Time.currentTimeMillis()) {
    // if daily evict for today hasn't happened yet set boundary
    // to yesterday's time of eviction
    cal.add(Calendar.DAY_OF_YEAR, -1);
  }
  return cal.getTimeInMillis();
}

代码示例来源:origin: org.keycloak/keycloak-server-spi

public static long weeklyTimeout(int day, int hour, int minute) {
  Calendar cal = Calendar.getInstance();
  Calendar cal2 = Calendar.getInstance();
  cal.setTimeInMillis(Time.currentTimeMillis());
  cal2.setTimeInMillis(Time.currentTimeMillis());
  cal2.set(Calendar.HOUR_OF_DAY, hour);
  cal2.set(Calendar.MINUTE, minute);
  cal2.set(Calendar.DAY_OF_WEEK, day);
  if (cal2.getTimeInMillis() < cal.getTimeInMillis()) {
    int add = (7 * 24 * 60 * 60 * 1000);
    cal2.add(Calendar.MILLISECOND, add);
  }
  return cal2.getTimeInMillis();
}

代码示例来源:origin: org.keycloak/keycloak-server-spi

public static long dailyTimeout(int hour, int minute) {
  Calendar cal = Calendar.getInstance();
  Calendar cal2 = Calendar.getInstance();
  cal.setTimeInMillis(Time.currentTimeMillis());
  cal2.setTimeInMillis(Time.currentTimeMillis());
  cal2.set(Calendar.HOUR_OF_DAY, hour);
  cal2.set(Calendar.MINUTE, minute);
  if (cal2.getTimeInMillis() < cal.getTimeInMillis()) {
    int add = (24 * 60 * 60 * 1000);
    cal.add(Calendar.MILLISECOND, add);
  } else {
    cal = cal2;
  }
  return cal.getTimeInMillis();
}

代码示例来源:origin: org.keycloak/keycloak-model-mongo

private void fillEntityFromModel(UserConsentModel consent, MongoUserConsentEntity consentEntity) {
  List<String> roleIds = new LinkedList<String>();
  for (RoleModel role : consent.getGrantedRoles()) {
    roleIds.add(role.getId());
  }
  consentEntity.setGrantedRoles(roleIds);
  List<String> protMapperIds = new LinkedList<String>();
  for (ProtocolMapperModel protMapperModel : consent.getGrantedProtocolMappers()) {
    protMapperIds.add(protMapperModel.getId());
  }
  consentEntity.setGrantedProtocolMappers(protMapperIds);
  consentEntity.setLastUpdatedDate(Time.currentTimeMillis());
}

代码示例来源:origin: org.keycloak/keycloak-model-jpa

private void updateGrantedConsentEntity(UserConsentEntity consentEntity, UserConsentModel consentModel) {
  Collection<UserConsentClientScopeEntity> grantedClientScopeEntities = consentEntity.getGrantedClientScopes();
  Collection<UserConsentClientScopeEntity> scopesToRemove = new HashSet<>(grantedClientScopeEntities);
  for (ClientScopeModel clientScope : consentModel.getGrantedClientScopes()) {
    UserConsentClientScopeEntity grantedClientScopeEntity = new UserConsentClientScopeEntity();
    grantedClientScopeEntity.setUserConsent(consentEntity);
    grantedClientScopeEntity.setScopeId(clientScope.getId());
    // Check if it's already there
    if (!grantedClientScopeEntities.contains(grantedClientScopeEntity)) {
      em.persist(grantedClientScopeEntity);
      em.flush();
      grantedClientScopeEntities.add(grantedClientScopeEntity);
    } else {
      scopesToRemove.remove(grantedClientScopeEntity);
    }
  }
  // Those client scopes were no longer on consentModel and will be removed
  for (UserConsentClientScopeEntity toRemove : scopesToRemove) {
    grantedClientScopeEntities.remove(toRemove);
    em.remove(toRemove);
  }
  consentEntity.setLastUpdatedDate(Time.currentTimeMillis());
  em.flush();
}

代码示例来源:origin: org.keycloak/keycloak-model-jpa

private void updateGrantedConsentEntity(FederatedUserConsentEntity consentEntity, UserConsentModel consentModel) {
  Collection<FederatedUserConsentClientScopeEntity> grantedClientScopeEntities = consentEntity.getGrantedClientScopes();
  Collection<FederatedUserConsentClientScopeEntity> scopesToRemove = new HashSet<>(grantedClientScopeEntities);
  for (ClientScopeModel clientScope : consentModel.getGrantedClientScopes()) {
    FederatedUserConsentClientScopeEntity grantedClientScopeEntity = new FederatedUserConsentClientScopeEntity();
    grantedClientScopeEntity.setUserConsent(consentEntity);
    grantedClientScopeEntity.setScopeId(clientScope.getId());
    // Check if it's already there
    if (!grantedClientScopeEntities.contains(grantedClientScopeEntity)) {
      em.persist(grantedClientScopeEntity);
      em.flush();
      grantedClientScopeEntities.add(grantedClientScopeEntity);
    } else {
      scopesToRemove.remove(grantedClientScopeEntity);
    }
  }
  // Those mappers were no longer on consentModel and will be removed
  for (FederatedUserConsentClientScopeEntity toRemove : scopesToRemove) {
    grantedClientScopeEntities.remove(toRemove);
    em.remove(toRemove);
  }
  consentEntity.setLastUpdatedDate(Time.currentTimeMillis());
  em.flush();
}

代码示例来源:origin: org.keycloak/keycloak-model-infinispan

private void submitImpl(K key, MyClientEvent event, Runnable r) {
  logger.debugf("Submitting event to the executor: %s . eventsInProgress size: %d, eventsQueue size: %d", event.toString(), eventsInProgress.size(), eventsQueue.size());
  eventsInProgress.put(key, event);
  Runnable decoratedRunnable = () -> {
    Long start = null;
    try {
      if (logger.isDebugEnabled()) {
        start = Time.currentTimeMillis();
      }
      r.run();
    } finally {
      synchronized (lock) {
        eventsInProgress.remove(key);
        if (logger.isDebugEnabled()) {
          long took = Time.currentTimeMillis() - start;
          logger.debugf("Finished processing event by the executor: %s, took: %d ms. EventsInProgress size: %d", event.toString(), took, eventsInProgress.size());
        }
        pollQueue(key);
      }
    }
  };
  try {
    decorated.submit(decoratedRunnable);
  } catch (RejectedExecutionException ree) {
    eventsInProgress.remove(key);
    logger.errorf("Rejected execution of task for the event '%s' . Try to increase the pool size. Pool is '%s'", event.toString(), decorated.toString());
    throw ree;
  }
}

代码示例来源:origin: org.keycloak/keycloak-server-spi

public long getLifespan() {
  UserStorageProviderModel.CachePolicy policy = getCachePolicy();
  long lifespan = -1;
  if (policy == null || policy == UserStorageProviderModel.CachePolicy.DEFAULT) {
    lifespan = -1;
  } else if (policy == CacheableStorageProviderModel.CachePolicy.EVICT_DAILY) {
    if (getEvictionHour() > -1 && getEvictionMinute() > -1) {
      lifespan = dailyTimeout(getEvictionHour(), getEvictionMinute()) - Time.currentTimeMillis();
    }
  } else if (policy == CacheableStorageProviderModel.CachePolicy.EVICT_WEEKLY) {
    if (getEvictionDay() > 0 && getEvictionHour() > -1 && getEvictionMinute() > -1) {
      lifespan = weeklyTimeout(getEvictionDay(), getEvictionHour(), getEvictionMinute()) - Time.currentTimeMillis();
    }
  } else if (policy == CacheableStorageProviderModel.CachePolicy.MAX_LIFESPAN) {
    lifespan = getMaxLifespan();
  }
  return lifespan;
}

代码示例来源:origin: org.keycloak/keycloak-model-mongo

@Override
public void addConsent(RealmModel realm, String userId, UserConsentModel consent) {
  String clientId = consent.getClient().getId();
  if (getConsentEntityByClientId(userId, clientId) != null) {
    throw new ModelDuplicateException("Consent already exists for client [" + clientId + "] and user [" + userId + "]");
  }
  long currentTime = Time.currentTimeMillis();
  MongoUserConsentEntity consentEntity = new MongoUserConsentEntity();
  consentEntity.setUserId(userId);
  consentEntity.setClientId(clientId);
  consentEntity.setCreatedDate(currentTime);
  consentEntity.setLastUpdatedDate(currentTime);
  fillEntityFromModel(consent, consentEntity);
  getMongoStore().insertEntity(consentEntity, invocationContext);
}

代码示例来源:origin: org.keycloak/keycloak-model-jpa

@Override
public void addConsent(RealmModel realm, String userId, UserConsentModel consent) {
  String clientId = consent.getClient().getId();
  UserConsentEntity consentEntity = getGrantedConsentEntity(userId, clientId);
  if (consentEntity != null) {
    throw new ModelDuplicateException("Consent already exists for client [" + clientId + "] and user [" + userId + "]");
  }
  long currentTime = Time.currentTimeMillis();
  consentEntity = new UserConsentEntity();
  consentEntity.setId(KeycloakModelUtils.generateId());
  consentEntity.setUser(em.getReference(UserEntity.class, userId));
  StorageId clientStorageId = new StorageId(clientId);
  if (clientStorageId.isLocal()) {
    consentEntity.setClientId(clientId);
  } else {
    consentEntity.setClientStorageProvider(clientStorageId.getProviderId());
    consentEntity.setExternalClientId(clientStorageId.getExternalId());
  }
  consentEntity.setCreatedDate(currentTime);
  consentEntity.setLastUpdatedDate(currentTime);
  em.persist(consentEntity);
  em.flush();
  updateGrantedConsentEntity(consentEntity, consent);
}

代码示例来源:origin: org.keycloak/keycloak-model-jpa

@Override
public void addConsent(RealmModel realm, String userId, UserConsentModel consent) {
  createIndex(realm, userId);
  String clientId = consent.getClient().getId();
  FederatedUserConsentEntity consentEntity = getGrantedConsentEntity(userId, clientId);
  if (consentEntity != null) {
    throw new ModelDuplicateException("Consent already exists for client [" + clientId + "] and user [" + userId + "]");
  }
  consentEntity = new FederatedUserConsentEntity();
  consentEntity.setId(KeycloakModelUtils.generateId());
  consentEntity.setUserId(userId);
  StorageId clientStorageId = new StorageId(clientId);
  if (clientStorageId.isLocal()) {
    consentEntity.setClientId(clientId);
  } else {
    consentEntity.setClientStorageProvider(clientStorageId.getProviderId());
    consentEntity.setExternalClientId(clientStorageId.getExternalId());
  }
  consentEntity.setRealmId(realm.getId());
  consentEntity.setStorageProviderId(new StorageId(userId).getProviderId());
  long currentTime = Time.currentTimeMillis();
  consentEntity.setCreatedDate(currentTime);
  consentEntity.setLastUpdatedDate(currentTime);
  em.persist(consentEntity);
  em.flush();
  updateGrantedConsentEntity(consentEntity, consent);
}

代码示例来源:origin: org.keycloak/keycloak-server-spi

invalidate = true;
} else if (policy == CacheableStorageProviderModel.CachePolicy.MAX_LIFESPAN) {
  if (cached.getCacheTimestamp() + getMaxLifespan() < Time.currentTimeMillis()) {
    invalidate = true;

相关文章