use of org.springframework.beans.factory.annotation.Value in project uPortal by Jasig.
the class IdTokenFactory method createUserInfo.
public String createUserInfo(String username, Set<String> claimsToInclude, Set<String> groupsToInclude) {
final Date now = new Date();
final Date expires = new Date(now.getTime() + (timeoutSeconds * 1000L));
final JwtBuilder builder = Jwts.builder().setIssuer(issuer).setSubject(username).setAudience(issuer).setExpiration(expires).setIssuedAt(now);
final IPersonAttributes person = personAttributeDao.getPerson(username);
// Attribute mappings
mappings.stream().filter(mapping -> includeClaim(mapping.getClaimName(), claimsToInclude)).forEach(item -> {
final Object value = person.getAttributeValue(item.getAttributeName());
if (value != null) {
builder.claim(item.getClaimName(), item.getDataTypeConverter().convert(value));
}
});
// Groups
final List<String> groups = new ArrayList<>();
final IGroupMember groupMember = GroupService.getGroupMember(username, IPerson.class);
if (groupMember != null) {
final Set<IEntityGroup> ancestors = groupMember.getAncestorGroups();
for (IEntityGroup g : ancestors) {
if (includeGroup(g, groupsToInclude)) {
groups.add(g.getName());
}
}
}
if (!groups.isEmpty()) {
/*
* If a Claim is not returned, that Claim Name SHOULD be omitted from the JSON object
* representing the Claims; it SHOULD NOT be present with a null or empty string value.
*/
builder.claim("groups", groups);
}
// Default custom claims defined by uPortal.properties
customClaims.stream().filter(claimName -> includeClaim(claimName, claimsToInclude)).map(attributeName -> new CustomClaim(attributeName, person.getAttributeValues(attributeName))).filter(claim -> claim.getClaimValue() != null).forEach(claim -> builder.claim(claim.getClaimName(), claim.getClaimValue()));
final String rslt = builder.signWith(algorithmFactory.getAlgorithm(), signatureKey).compact();
logger.debug("Produced the following JWT for username='{}': {}", username, rslt);
return rslt;
}
use of org.springframework.beans.factory.annotation.Value in project leopard by tanhaichao.
the class SysconfigBeanPostProcessor method postProcessBeforeInitialization.
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
// System.err.println("postProcessBeforeInitialization:" + beanName);
Class<?> clazz = bean.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
Value annotation = field.getAnnotation(Value.class);
if (annotation == null) {
continue;
}
field.setAccessible(true);
Object value = resolveValue(annotation, field);
if (value == null) {
continue;
}
try {
field.set(bean, value);
FieldInfo fieldInfo = new FieldInfo();
fieldInfo.setBean(bean);
fieldInfo.setField(field);
fieldList.add(fieldInfo);
} catch (IllegalAccessException e) {
throw new BeanInstantiationException(clazz, e.getMessage(), e);
}
}
return bean;
}
use of org.springframework.beans.factory.annotation.Value in project leopard by tanhaichao.
the class SysconfigBeanPostProcessor method get.
@Override
public SysconfigVO get() {
SysconfigVO sysconfigVO = new SysconfigVO();
List<FieldVO> fieldVOList = new ArrayList<FieldVO>();
sysconfigVO.setFieldList(fieldVOList);
for (FieldInfo fieldInfo : fieldList) {
Field field = fieldInfo.getField();
Value annotation = field.getAnnotation(Value.class);
Object value;
try {
value = field.get(fieldInfo.getBean());
} catch (IllegalAccessException e) {
throw new RuntimeException(e.getMessage(), e);
}
String sysconfigId = annotation.value().replace("${", "").replace("}", "");
FieldVO fieldVO = new FieldVO();
fieldVO.setSysconfigId(sysconfigId);
fieldVO.setValue(value);
fieldVOList.add(fieldVO);
}
sysconfigVO.setLmodify(lmodify);
return sysconfigVO;
}
use of org.springframework.beans.factory.annotation.Value in project CzechIdMng by bcvsolutions.
the class ClusteredEhCacheConfiguration method ehCacheManager.
/**
* Defines clustered {@link CacheManager} using Terracotta server.
*
* @param terracotaUrl a list of IP addresses with ports (IP_ADDR:PORT)
* @param terracotaResourceName name of server resource to connect
* @param terracotaResourcePoolName name od server resource pool name
* @param terracotaResourcePoolSize size of server resource pool in MB
* @param idMCacheConfigurations a list of {@link IdMCacheConfiguration} defined in container
* @return CacheManager with distributed capabilities
*/
@Bean
@Qualifier("jCacheManager")
@ConditionalOnProperty(value = TERRACOTA_URL_PROPERTY)
@ConditionalOnMissingBean
public CacheManager ehCacheManager(@Value("${" + TERRACOTA_URL_PROPERTY + "}") String terracotaUrl, @Value("${" + TERRACOTA_RESOURCE_NAME_PROPERTY + "}") String terracotaResourceName, @Value("${" + TERRACOTA_RESOURCE_POOL_NAME_PROPERTY + "}") String terracotaResourcePoolName, @Value("${" + TERRACOTA_RESOURCE_POOL_SIZE_PROPERTY + "}") int terracotaResourcePoolSize, @Autowired List<IdMCacheConfiguration> idMCacheConfigurations) {
CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder().with(ClusteringServiceConfigurationBuilder.cluster(parseServerAddresses(terracotaUrl), "default").autoCreate(server -> server.defaultServerResource(terracotaResourceName).resourcePool(terracotaResourcePoolName, terracotaResourcePoolSize, MemoryUnit.MB, terracotaResourceName))).withSerializer(CacheObjectWrapper.class, CacheWrapperSerializer.class).withSerializer(SerializableCacheObjectWrapper.class, SerializableCacheWrapperSerializer.class);
PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);
// create caches using IdMCacheConfiguration instances
if (!CollectionUtils.isEmpty(idMCacheConfigurations)) {
for (IdMCacheConfiguration config : idMCacheConfigurations) {
cacheManager.createCache(config.getCacheName(), toConcreteConfiguration(config, terracotaResourcePoolName));
}
}
// get CacheManager (Jcache) with above updated configuration
final EhcacheCachingProvider ehcacheCachingProvider = (EhcacheCachingProvider) Caching.getCachingProvider();
return ehcacheCachingProvider.getCacheManager(ehcacheCachingProvider.getDefaultURI(), cacheManager.getRuntimeConfiguration());
}
use of org.springframework.beans.factory.annotation.Value in project ArachneCentralAPI by OHDSI.
the class AntivirusServiceImpl method processRequest.
@EventListener
@Async(value = "antivirusScanExecutor")
public void processRequest(AntivirusJobEvent event) {
final AntivirusJob antivirusJob = event.getAntivirusJob();
final AntivirusJobFileType fileType = antivirusJob.getAntivirusJobFileType();
final Long fileId = antivirusJob.getFileId();
logger.debug(PROCESSING_SCAN_REQUEST, fileId, fileType);
String description = null;
AntivirusStatus status;
try (InputStream content = antivirusJob.getContent()) {
clamavClientAvailabilityCheck();
final ScanResult scan = retryTemplate.execute((RetryCallback<ScanResult, Exception>) retryContext -> {
logger.debug(PROCESSING_SCAN_ATTEMPT, fileId, fileType);
return scan(content);
});
if (scan instanceof ScanResult.OK) {
status = AntivirusStatus.OK;
} else {
status = AntivirusStatus.INFECTED;
description = scan.toString();
}
} catch (Exception e) {
logger.error("Error scanning file: {}", e.getMessage());
if (e instanceof ClamavException) {
final Throwable cause = e.getCause();
description = cause.getMessage();
} else {
description = e.getMessage();
}
status = AntivirusStatus.NOT_SCANNED;
}
logger.debug(PROCESSING_SCAN_RESULT, fileId, fileType, status);
publishResponse(fileType, fileId, status, description);
}
Aggregations