use of lombok.SneakyThrows in project cas by apereo.
the class JWTTokenTicketBuilder method build.
@Override
@SneakyThrows
public String build(final TicketGrantingTicket ticketGrantingTicket) {
final Authentication authentication = ticketGrantingTicket.getAuthentication();
final Map<String, Object> attributes = new LinkedHashMap<>(authentication.getAttributes());
attributes.putAll(authentication.getPrincipal().getAttributes());
final ZonedDateTime dt = ZonedDateTime.now().plusSeconds(expirationPolicy.getTimeToLive());
final Date validUntilDate = DateTimeUtils.dateOf(dt);
return buildJwt(ticketGrantingTicket.getId(), casSeverPrefix, DateTimeUtils.dateOf(ticketGrantingTicket.getCreationTime()), authentication.getPrincipal().getId(), validUntilDate, attributes);
}
use of lombok.SneakyThrows in project cas by apereo.
the class WsFederationNavigationController method getRelativeRedirectUrlFor.
/**
* Gets redirect url for.
*
* @param config the config
* @param service the service
* @param request the request
* @return the redirect url for
*/
@SneakyThrows
public static String getRelativeRedirectUrlFor(final WsFederationConfiguration config, final Service service, final HttpServletRequest request) {
final URIBuilder builder = new URIBuilder(ENDPOINT_REDIRECT);
builder.addParameter(PARAMETER_NAME, config.getId());
if (service != null) {
builder.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
}
final String method = request.getParameter(CasProtocolConstants.PARAMETER_METHOD);
if (StringUtils.isNotBlank(method)) {
builder.addParameter(CasProtocolConstants.PARAMETER_METHOD, method);
}
return builder.toString();
}
use of lombok.SneakyThrows in project cas by apereo.
the class MongoDbConnectionFactory method buildMongoDbClientOptionsFactoryBean.
/**
* Create a MongoClientOptions object.
* <p>
* The object will be created from a collection of individual property
* settings, or a MongoDb client connection string (uri), or some
* combination of the two.
* <p>
* This is complicated by the fact that the default values provided by
* the CAS code in BaseMongoDbProperties.java are not the same as the
* default values for the corresponding options provided by the MongoDb
* Java driver when it creates a MongoClientOptions object.
* <p>
* To ensure predictable results in all cases, we initialize the client
* options from the individual property settings (even if just the CAS
* default values), and then use those values as the starting point to
* process the client uri (if one is provided). This way, any options
* in the uri will override the earlier ones, but any options missing
* from the uri will have the values (default or user-provided) from
* the individual property settings.
* <p>
* This behavior matches the comment in BaseMongoDbProperties.java for
* the clientUri property: "If not specified, will fallback onto other
* individual settings. If specified, takes over all other settings
* where applicable."
*
* @param mongo the property setttings (including, perhaps, a client uri)
* @return a bean containing the MongoClientOptions object
*/
@SneakyThrows
private MongoClientOptionsFactoryBean buildMongoDbClientOptionsFactoryBean(final BaseMongoDbProperties mongo) {
final MongoClientOptionsFactoryBean bean1 = new MongoClientOptionsFactoryBean();
bean1.setWriteConcern(WriteConcern.valueOf(mongo.getWriteConcern()));
bean1.setHeartbeatConnectTimeout((int) Beans.newDuration(mongo.getTimeout()).toMillis());
bean1.setHeartbeatSocketTimeout((int) Beans.newDuration(mongo.getTimeout()).toMillis());
bean1.setMaxConnectionLifeTime(mongo.getConns().getLifetime());
bean1.setSocketKeepAlive(mongo.isSocketKeepAlive());
bean1.setMaxConnectionIdleTime((int) Beans.newDuration(mongo.getIdleTimeout()).toMillis());
bean1.setConnectionsPerHost(mongo.getConns().getPerHost());
bean1.setSocketTimeout((int) Beans.newDuration(mongo.getTimeout()).toMillis());
bean1.setConnectTimeout((int) Beans.newDuration(mongo.getTimeout()).toMillis());
if (StringUtils.isNotBlank(mongo.getReplicaSet())) {
bean1.setRequiredReplicaSetName(mongo.getReplicaSet());
}
bean1.setSsl(mongo.isSslEnabled());
if (mongo.isSslEnabled()) {
bean1.setSslSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault());
}
bean1.afterPropertiesSet();
if (StringUtils.isNotBlank(mongo.getClientUri())) {
final MongoClientOptionsFactoryBean bean2 = new MongoClientOptionsFactoryBean();
final MongoClientURI uri = buildMongoClientURI(mongo.getClientUri(), bean1.getObject());
final MongoClientOptions opts = uri.getOptions();
bean2.setWriteConcern(opts.getWriteConcern());
bean2.setHeartbeatConnectTimeout(opts.getHeartbeatConnectTimeout());
bean2.setHeartbeatSocketTimeout(opts.getHeartbeatSocketTimeout());
bean2.setMaxConnectionLifeTime(opts.getMaxConnectionLifeTime());
bean2.setSocketKeepAlive(opts.isSocketKeepAlive());
bean2.setMaxConnectionIdleTime(opts.getMaxConnectionIdleTime());
bean2.setConnectionsPerHost(opts.getConnectionsPerHost());
bean2.setSocketTimeout(opts.getSocketTimeout());
bean2.setConnectTimeout(opts.getConnectTimeout());
bean2.setRequiredReplicaSetName(opts.getRequiredReplicaSetName());
bean2.setSsl(opts.isSslEnabled());
if (opts.isSslEnabled()) {
bean2.setSslSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault());
}
bean2.afterPropertiesSet();
bean1.destroy();
return bean2;
}
return bean1;
}
use of lombok.SneakyThrows in project cas by apereo.
the class MongoDbConnectionFactory method buildMongoDbClientOptions.
@SneakyThrows
private MongoClientOptions buildMongoDbClientOptions() {
final MongoClientOptionsFactoryBean bean = new MongoClientOptionsFactoryBean();
bean.setSocketTimeout(TIMEOUT);
bean.setConnectTimeout(TIMEOUT);
bean.setMaxWaitTime(TIMEOUT);
bean.afterPropertiesSet();
return bean.getObject();
}
use of lombok.SneakyThrows in project cas by apereo.
the class JcifsConfig method configureJaasLoginConfig.
/**
* Configure jaas login config location and set it as a system property.
*/
@SneakyThrows
protected void configureJaasLoginConfig() {
final String propValue = System.getProperty(SYS_PROP_LOGIN_CONF);
if (StringUtils.isNotBlank(propValue)) {
LOGGER.info("Found login config [{}] in system property [{}]", propValue, SYS_PROP_LOGIN_CONF);
if (StringUtils.isNotBlank(this.loginConf)) {
LOGGER.warn("Configured login config for CAS under [{}] will be ignored", this.loginConf);
}
} else {
final String loginConf = StringUtils.isBlank(this.loginConf) ? DEFAULT_LOGIN_CONFIG : this.loginConf;
LOGGER.debug("Attempting to load login config from [{}]", loginConf);
final Resource res = this.resourceLoader.getResource(loginConf);
if (res != null && res.exists()) {
final String urlPath = res.getURL().toExternalForm();
LOGGER.debug("Located login config [{}] and configured it under [{}]", urlPath, SYS_PROP_LOGIN_CONF);
System.setProperty(SYS_PROP_LOGIN_CONF, urlPath);
} else {
final URL url = getClass().getResource("/jcifs/http/login.conf");
if (url != null) {
LOGGER.debug("Falling back unto default login config [{}] under [{}]", url.toExternalForm(), SYS_PROP_LOGIN_CONF);
System.setProperty(SYS_PROP_LOGIN_CONF, url.toExternalForm());
}
}
LOGGER.debug("configured login configuration path : [{}]", propValue);
}
}
Aggregations