use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class AbstractPrincipalAttributesRepository method getAttributes.
@Override
public Map<String, Object> getAttributes(final Principal p) {
final Map<String, Object> cachedAttributes = getPrincipalAttributes(p);
if (cachedAttributes != null && !cachedAttributes.isEmpty()) {
LOGGER.debug("Found [{}] cached attributes for principal [{}] that are [{}]", cachedAttributes.size(), p.getId(), cachedAttributes);
return cachedAttributes;
}
if (getAttributeRepository() == null) {
LOGGER.debug("No attribute repository is defined for [{}]. Returning default principal attributes for [{}]", getClass().getName(), p.getId());
return cachedAttributes;
}
final Map<String, List<Object>> sourceAttributes = retrievePersonAttributesToPrincipalAttributes(p.getId());
LOGGER.debug("Found [{}] attributes for principal [[{}]] from the attribute repository.", sourceAttributes.size(), p.getId());
if (this.mergingStrategy == null || this.mergingStrategy.getAttributeMerger() == null) {
LOGGER.debug("No merging strategy found, so attributes retrieved from the repository will be used instead.");
return convertAttributesToPrincipalAttributesAndCache(p, sourceAttributes);
}
final Map<String, List<Object>> principalAttributes = convertPrincipalAttributesToPersonAttributes(p);
LOGGER.debug("Merging current principal attributes with that of the repository via strategy [{}]", this.mergingStrategy.getClass().getSimpleName());
try {
final Map<String, List<Object>> mergedAttributes = this.mergingStrategy.getAttributeMerger().mergeAttributes(principalAttributes, sourceAttributes);
return convertAttributesToPrincipalAttributesAndCache(p, mergedAttributes);
} catch (final Exception e) {
final StringBuilder builder = new StringBuilder();
builder.append(e.getClass().getName().concat("-"));
if (StringUtils.isNotBlank(e.getMessage())) {
builder.append(e.getMessage());
}
LOGGER.error("The merging strategy [{}] for [{}] has failed to produce principal attributes because: [{}]. " + "This usually is indicative of a bug and/or configuration mismatch. CAS will skip the merging process " + "and will return the original collection of principal attributes [{}]", this.mergingStrategy, p.getId(), builder.toString(), principalAttributes);
return convertAttributesToPrincipalAttributesAndCache(p, principalAttributes);
}
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class LogoutAction method doInternalExecute.
@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response, final RequestContext context) throws Exception {
boolean needFrontSlo = false;
final List<LogoutRequest> logoutRequests = WebUtils.getLogoutRequests(context);
if (logoutRequests != null) {
// if some logout request must still be attempted
needFrontSlo = logoutRequests.stream().anyMatch(logoutRequest -> logoutRequest.getStatus() == LogoutRequestStatus.NOT_ATTEMPTED);
}
final String paramName = StringUtils.defaultIfEmpty(logoutProperties.getRedirectParameter(), CasProtocolConstants.PARAMETER_SERVICE);
LOGGER.debug("Using parameter name [{}] to detect destination service, if any", paramName);
final String service = request.getParameter(paramName);
LOGGER.debug("Located target service [{}] for redirection after logout", paramName);
if (logoutProperties.isFollowServiceRedirects() && StringUtils.isNotBlank(service)) {
final Service webAppService = webApplicationServiceFactory.createService(service);
final RegisteredService rService = this.servicesManager.findServiceBy(webAppService);
if (rService != null && rService.getAccessStrategy().isServiceAccessAllowed()) {
LOGGER.debug("Redirecting to service [{}]", service);
WebUtils.putLogoutRedirectUrl(context, service);
} else {
LOGGER.warn("Cannot redirect to [{}] given the service is unauthorized to use CAS. " + "Ensure the service is registered with CAS and is enabled to allowed access", service);
}
} else {
LOGGER.debug("No target service is located for redirection after logout, or CAS is not allowed to follow redirects after logout");
}
// there are some front services to logout, perform front SLO
if (needFrontSlo) {
LOGGER.debug("Proceeding forward with front-channel single logout");
return new Event(this, FRONT_EVENT);
}
LOGGER.debug("Moving forward to finish the logout process");
return new Event(this, FINISH_EVENT);
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project cas by apereo.
the class DuoSecurityAuthenticationEventExecutionPlanConfiguration method duoMultifactorAuthenticationProvider.
@Bean
@RefreshScope
public VariegatedMultifactorAuthenticationProvider duoMultifactorAuthenticationProvider() {
final DefaultVariegatedMultifactorAuthenticationProvider provider = new DefaultVariegatedMultifactorAuthenticationProvider();
casProperties.getAuthn().getMfa().getDuo().stream().filter(duo -> StringUtils.isNotBlank(duo.getDuoApiHost()) && StringUtils.isNotBlank(duo.getDuoIntegrationKey()) && StringUtils.isNotBlank(duo.getDuoSecretKey()) && StringUtils.isNotBlank(duo.getDuoApplicationKey())).forEach(duo -> {
final BasicDuoAuthenticationService s = new BasicDuoAuthenticationService(duo, httpClient);
final DefaultDuoMultifactorAuthenticationProvider pWeb = new DefaultDuoMultifactorAuthenticationProvider(s);
pWeb.setGlobalFailureMode(casProperties.getAuthn().getMfa().getGlobalFailureMode());
pWeb.setBypassEvaluator(new DefaultMultifactorAuthenticationProviderBypass(duo.getBypass()));
pWeb.setOrder(duo.getRank());
pWeb.setId(duo.getId());
provider.addProvider(pWeb);
});
if (provider.getProviders().isEmpty()) {
throw new IllegalArgumentException("At least one Duo instance must be defined");
}
return provider;
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project DataX by alibaba.
the class SecretUtil method getPrivateKeyMap.
private static synchronized Map<String, Triple<String, String, String>> getPrivateKeyMap() {
if (versionKeyMap == null) {
versionKeyMap = new HashMap<String, Triple<String, String, String>>();
Properties properties = SecretUtil.getSecurityProperties();
String[] serviceUsernames = new String[] { CoreConstant.LAST_SERVICE_USERNAME, CoreConstant.CURRENT_SERVICE_USERNAME };
String[] servicePasswords = new String[] { CoreConstant.LAST_SERVICE_PASSWORD, CoreConstant.CURRENT_SERVICE_PASSWORD };
for (int i = 0; i < serviceUsernames.length; i++) {
String serviceUsername = properties.getProperty(serviceUsernames[i]);
if (StringUtils.isNotBlank(serviceUsername)) {
String servicePassword = properties.getProperty(servicePasswords[i]);
if (StringUtils.isNotBlank(servicePassword)) {
versionKeyMap.put(serviceUsername, ImmutableTriple.of(servicePassword, SecretUtil.KEY_ALGORITHM_3DES, servicePassword));
} else {
throw DataXException.asDataXException(FrameworkErrorCode.SECRET_ERROR, String.format("DataX配置要求加解密,但配置的密钥版本[%s]存在密钥为空的情况", serviceUsername));
}
}
}
String[] keyVersions = new String[] { CoreConstant.LAST_KEYVERSION, CoreConstant.CURRENT_KEYVERSION };
String[] privateKeys = new String[] { CoreConstant.LAST_PRIVATEKEY, CoreConstant.CURRENT_PRIVATEKEY };
String[] publicKeys = new String[] { CoreConstant.LAST_PUBLICKEY, CoreConstant.CURRENT_PUBLICKEY };
for (int i = 0; i < keyVersions.length; i++) {
String keyVersion = properties.getProperty(keyVersions[i]);
if (StringUtils.isNotBlank(keyVersion)) {
String privateKey = properties.getProperty(privateKeys[i]);
String publicKey = properties.getProperty(publicKeys[i]);
if (StringUtils.isNotBlank(privateKey) && StringUtils.isNotBlank(publicKey)) {
versionKeyMap.put(keyVersion, ImmutableTriple.of(privateKey, SecretUtil.KEY_ALGORITHM_RSA, publicKey));
} else {
throw DataXException.asDataXException(FrameworkErrorCode.SECRET_ERROR, String.format("DataX配置要求加解密,但配置的公私钥对存在为空的情况,版本[%s]", keyVersion));
}
}
}
}
if (versionKeyMap.size() <= 0) {
throw DataXException.asDataXException(FrameworkErrorCode.SECRET_ERROR, "DataX配置要求加解密,但无法找到加解密配置");
}
return versionKeyMap;
}
use of org.apache.commons.lang3.StringUtils.isNotBlank in project DataX by alibaba.
the class SingleTableSplitUtil method genSplitSqlForOracle.
/**
* support Number and String split
* */
public static List<String> genSplitSqlForOracle(String splitPK, String table, String where, Configuration configuration, int adviceNum) {
if (adviceNum < 1) {
throw new IllegalArgumentException(String.format("切分份数不能小于1. 此处:adviceNum=[%s].", adviceNum));
} else if (adviceNum == 1) {
return null;
}
String whereSql = String.format("%s IS NOT NULL", splitPK);
if (StringUtils.isNotBlank(where)) {
whereSql = String.format(" WHERE (%s) AND (%s) ", whereSql, where);
} else {
whereSql = String.format(" WHERE (%s) ", whereSql);
}
Double percentage = configuration.getDouble(Key.SAMPLE_PERCENTAGE, 0.1);
String sampleSqlTemplate = "SELECT * FROM ( SELECT %s FROM %s SAMPLE (%s) %s ORDER BY DBMS_RANDOM.VALUE) WHERE ROWNUM <= %s ORDER by %s ASC";
String splitSql = String.format(sampleSqlTemplate, splitPK, table, percentage, whereSql, adviceNum, splitPK);
int fetchSize = configuration.getInt(Constant.FETCH_SIZE, 32);
String jdbcURL = configuration.getString(Key.JDBC_URL);
String username = configuration.getString(Key.USERNAME);
String password = configuration.getString(Key.PASSWORD);
Connection conn = DBUtil.getConnection(DATABASE_TYPE, jdbcURL, username, password);
LOG.info("split pk [sql={}] is running... ", splitSql);
ResultSet rs = null;
List<Pair<Object, Integer>> splitedRange = new ArrayList<Pair<Object, Integer>>();
try {
try {
rs = DBUtil.query(conn, splitSql, fetchSize);
} catch (Exception e) {
throw RdbmsException.asQueryException(DATABASE_TYPE, e, splitSql, table, username);
}
if (configuration != null) {
configuration.set(Constant.PK_TYPE, Constant.PK_TYPE_MONTECARLO);
}
ResultSetMetaData rsMetaData = rs.getMetaData();
while (DBUtil.asyncResultSetNext(rs)) {
ImmutablePair<Object, Integer> eachPoint = new ImmutablePair<Object, Integer>(rs.getObject(1), rsMetaData.getColumnType(1));
splitedRange.add(eachPoint);
}
} catch (DataXException e) {
throw e;
} catch (Exception e) {
throw DataXException.asDataXException(DBUtilErrorCode.ILLEGAL_SPLIT_PK, "DataX尝试切分表发生错误. 请检查您的配置并作出修改.", e);
} finally {
DBUtil.closeDBResources(rs, null, null);
}
LOG.debug(JSON.toJSONString(splitedRange));
List<String> rangeSql = new ArrayList<String>();
int splitedRangeSize = splitedRange.size();
// demo: Parameter rangeResult can not be null and its length can not <2. detail:rangeResult=[24999930].
if (splitedRangeSize >= 2) {
// warn: oracle Number is long type here
if (isLongType(splitedRange.get(0).getRight())) {
BigInteger[] integerPoints = new BigInteger[splitedRange.size()];
for (int i = 0; i < splitedRangeSize; i++) {
integerPoints[i] = new BigInteger(splitedRange.get(i).getLeft().toString());
}
rangeSql.addAll(RdbmsRangeSplitWrap.wrapRange(integerPoints, splitPK));
// its ok if splitedRangeSize is 1
rangeSql.add(RdbmsRangeSplitWrap.wrapFirstLastPoint(integerPoints[0], integerPoints[splitedRangeSize - 1], splitPK));
} else if (isStringType(splitedRange.get(0).getRight())) {
// warn: treated as string type
String[] stringPoints = new String[splitedRange.size()];
for (int i = 0; i < splitedRangeSize; i++) {
stringPoints[i] = new String(splitedRange.get(i).getLeft().toString());
}
rangeSql.addAll(RdbmsRangeSplitWrap.wrapRange(stringPoints, splitPK, "'", DATABASE_TYPE));
// its ok if splitedRangeSize is 1
rangeSql.add(RdbmsRangeSplitWrap.wrapFirstLastPoint(stringPoints[0], stringPoints[splitedRangeSize - 1], splitPK, "'", DATABASE_TYPE));
} else {
throw DataXException.asDataXException(DBUtilErrorCode.ILLEGAL_SPLIT_PK, "您配置的DataX切分主键(splitPk)有误. 因为您配置的切分主键(splitPk) 类型 DataX 不支持. DataX 仅支持切分主键为一个,并且类型为整数或者字符串类型. 请尝试使用其他的切分主键或者联系 DBA 进行处理.");
}
}
return rangeSql;
}
Aggregations