Java Code Examples for org.apache.commons.lang3.StringUtils#isAllBlank()

The following examples show how to use org.apache.commons.lang3.StringUtils#isAllBlank() . These examples are extracted from open source projects. 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 Project: SpringBlade   File: AuthFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
	String path = exchange.getRequest().getURI().getPath();
	if (isSkip(path)) {
		return chain.filter(exchange);
	}
	ServerHttpResponse resp = exchange.getResponse();
	String headerToken = exchange.getRequest().getHeaders().getFirst(AuthProvider.AUTH_KEY);
	String paramToken = exchange.getRequest().getQueryParams().getFirst(AuthProvider.AUTH_KEY);
	if (StringUtils.isAllBlank(headerToken, paramToken)) {
		return unAuth(resp, "缺失令牌,鉴权失败");
	}
	String auth = StringUtils.isBlank(headerToken) ? paramToken : headerToken;
	String token = JwtUtil.getToken(auth);
	Claims claims = JwtUtil.parseJWT(token);
	if (claims == null) {
		return unAuth(resp, "请求未授权");
	}
	return chain.filter(exchange);
}
 
Example 2
Source Project: redtorch   File: NodeServiceImpl.java    License: MIT License 6 votes vote down vote up
@Override
public NodePo nodeAuth(NodePo node) {
	if (node == null) {
		logger.error("节点审核错误,参数node缺失");
		throw new IllegalArgumentException("节点审核错误,参数node缺失");
	}
	if (node.getNodeId() == null) {
		logger.error("节点审核错误,参数nodeId缺失");
		throw new IllegalArgumentException("节点审核错误,参数nodeId缺失");
	}
	if (StringUtils.isAllBlank(node.getToken())) {
		logger.error("节点审核错误,参数token缺失");
		throw new IllegalArgumentException("节点审核错误,参数token缺失");
	}

	NodePo queriedNode = nodeDao.queryNodeByNodeId(node.getNodeId());
	if (queriedNode != null && node.getToken().equals(queriedNode.getToken())) {
		logger.info("节点审核成功,节点ID:{}", node.getNodeId());
		return queriedNode;
	} else {
		logger.info("节点审核失败,节点ID:{}", node.getNodeId());
		return null;
	}
}
 
Example 3
Source Project: jakduk-api   File: UserService.java    License: MIT License 6 votes vote down vote up
/**
 * SNS 회원의 하위 호환 검사
 *
 * @param snsEmail Provider(페이스북, 다음)에서 가져온 email
 * @param user DB에서 가져온 회원
 */
public void checkBackwardCompatibilityOfSnsUser(String snsEmail, User user) {

	// User DB 와 SNS Profile 모두에 email이 없을 경우에는 신규 가입으로 진행한다.
	// SNS 가입시 이메일 제공 동의를 안해서 그렇다.
	if (StringUtils.isAllBlank(user.getEmail(), snsEmail)) {
		user.setEmail(JakdukUtils.generateTemporaryEmail());
		userRepository.save(user);

		log.info("user({},{}) temporary email:{} has been entered.", user.getId(), user.getUsername(), user.getEmail());
	}
	// 과거 SNS 가입 회원들은 email이 없는 경우가 있음. 이메일을 DB에 저장
	else if (StringUtils.isBlank(user.getEmail()) && StringUtils.isNotBlank(snsEmail)) {
		user.setEmail(snsEmail);
		userRepository.save(user);

		log.info("user({},{}) email:{} has been entered.", user.getId(), user.getUsername(), user.getEmail());
	}
}
 
Example 4
/**
 * Extracts parameters from http request and overrides corresponding attributes in {@link BidRequest}.
 */
private BidRequest overrideParameters(BidRequest bidRequest, HttpServerRequest request) {
    final String requestConsentParam = request.getParam(CONSENT_PARAM);
    final String requestGdprConsentParam = request.getParam(GDPR_CONSENT_PARAM);
    final String consentString = ObjectUtils.firstNonNull(requestConsentParam, requestGdprConsentParam);

    String gdprConsent = null;
    String ccpaConsent = null;
    if (StringUtils.isNotBlank(consentString)) {
        gdprConsent = TcfDefinerService.isGdprConsentValid(consentString) ? consentString : null;
        ccpaConsent = Ccpa.isValid(consentString) ? consentString : null;

        if (StringUtils.isAllBlank(gdprConsent, ccpaConsent)) {
            logger.debug("Amp request parameter consent_string or gdpr_consent have invalid format: {0}",
                    consentString);
        }
    }

    final Site updatedSite = overrideSite(bidRequest.getSite(), request);
    final Imp updatedImp = overrideImp(bidRequest.getImp().get(0), request);
    final Long updatedTimeout = overrideTimeout(bidRequest.getTmax(), request);
    final User updatedUser = overrideUser(bidRequest.getUser(), gdprConsent);
    final Regs updatedRegs = overrideRegs(bidRequest.getRegs(), ccpaConsent);

    final BidRequest result;
    if (updatedSite != null || updatedImp != null || updatedTimeout != null || updatedUser != null
            || updatedRegs != null) {
        result = bidRequest.toBuilder()
                .site(updatedSite != null ? updatedSite : bidRequest.getSite())
                .imp(updatedImp != null ? Collections.singletonList(updatedImp) : bidRequest.getImp())
                .tmax(updatedTimeout != null ? updatedTimeout : bidRequest.getTmax())
                .user(updatedUser != null ? updatedUser : bidRequest.getUser())
                .regs(updatedRegs != null ? updatedRegs : bidRequest.getRegs())
                .build();
    } else {
        result = bidRequest;
    }
    return result;
}
 
Example 5
Source Project: redtorch   File: SystemController.java    License: MIT License 5 votes vote down vote up
@RequestMapping(value = { "/changePassword" }, method = { RequestMethod.POST })
@ResponseBody
public ResponseVo<UserPo> changePassword(HttpServletRequest request, @RequestBody UserPo user) {
	ResponseVo<UserPo> responseVo = new ResponseVo<>();
	try {
		if (user == null) {
			responseVo.setStatus(false);
			responseVo.setMessage("修改密码失败,未找到请求体");
		} else {
			if (request.getSession().getAttribute(RtConstant.KEY_USER_PO) != null) {
				UserPo sessionUser = (UserPo) request.getSession().getAttribute(RtConstant.KEY_USER_PO);
				logger.info("用户{}修改密码,地址{}:{}", sessionUser.getUsername(), request.getRemoteAddr(), request.getRemotePort());
				if ("admin".equals(sessionUser.getUsername())) {
					responseVo.setStatus(false);
					responseVo.setMessage("修改密码失败,admin用户仅允许通过配置文件修改密码");
					return responseVo;
				} else {
					user.setUsername(sessionUser.getUsername());
					String resString = userService.userChangePassword(user);
					if (!StringUtils.isAllBlank(resString)) {
						responseVo.setStatus(false);
						responseVo.setMessage(resString);
					}
				}
			} else {
				responseVo.setStatus(false);
				responseVo.setMessage("修改密码失败,SESSION缓存中未能找到用户");
			}
		}
	} catch (Exception e) {
		logger.error("修改密码异常", e);
		responseVo.setStatus(false);
		responseVo.setMessage(e.getMessage());
	}
	return responseVo;
}
 
Example 6
Source Project: redtorch   File: UserController.java    License: MIT License 5 votes vote down vote up
@RequestMapping(value = { "/changePassword" }, method = { RequestMethod.POST })
@ResponseBody
public ResponseVo<UserPo> changePassword(HttpServletRequest request, @RequestBody UserPo user) {
	ResponseVo<UserPo> responseVo = new ResponseVo<>();
	try {
		if (user == null) {
			responseVo.setStatus(false);
			responseVo.setMessage("修改密码失败,未找到请求体");
		} else {
			if (request.getSession().getAttribute(RtConstant.KEY_USER_PO) != null) {
				UserPo sessionUser = (UserPo) request.getSession().getAttribute(RtConstant.KEY_USER_PO);
				logger.info("用户{}修改密码,地址{}:{}", sessionUser.getUsername(), request.getRemoteAddr(), request.getRemotePort());
				if ("admin".equals(sessionUser.getUsername())) {
					responseVo.setStatus(false);
					responseVo.setMessage("修改密码失败,admin用户仅允许通过配置文件修改密码");
					return responseVo;
				} else {
					user.setUsername(sessionUser.getUsername());
					String resString = userService.userChangePassword(user);
					if (!StringUtils.isAllBlank(resString)) {
						responseVo.setStatus(false);
						responseVo.setMessage(resString);
					}
				}
			} else {
				responseVo.setStatus(false);
				responseVo.setMessage("修改密码失败,SESSION中未能找到用户");
			}
		}
	} catch (Exception e) {
		logger.error("修改密码异常", e);
		responseVo.setStatus(false);
		responseVo.setMessage(e.getMessage());
	}
	return responseVo;
}
 
Example 7
@Override
public void sendForInvite(IMatrixIdInvite invite) {
    EmailTemplate template = cfg.getTemplates().getGeneric().get("matrixId");
    if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
        throw new FeatureNotAvailable("No template has been configured for Matrix ID invite notifications");
    }

    Email email = getEmail();
    email.setSubject(populateForInvite(invite, template.getSubject()));
    email.setText(populateForInvite(invite, getFromFile(template.getBody().getText())));
    email.setHtml(populateForInvite(invite, getFromFile(template.getBody().getHtml())));

    send(invite.getAddress(), email);
}
 
Example 8
@Override
public void sendForReply(IThreePidInviteReply invite) {
    EmailTemplate template = cfg.getTemplates().getInvite();
    if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
        throw new FeatureNotAvailable("No template has been configured for 3PID invite notifications");
    }

    Email email = getEmail();
    email.setSubject(populateForReply(invite, template.getSubject()));
    email.setText(populateForReply(invite, getFromFile(template.getBody().getText())));
    email.setHtml(populateForReply(invite, getFromFile(template.getBody().getHtml())));

    send(invite.getInvite().getAddress(), email);
}
 
Example 9
@Override
public void sendForValidation(IThreePidSession session) {
    EmailTemplate template = cfg.getTemplates().getSession().getValidation();
    if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
        throw new FeatureNotAvailable("No template has been configured for validation notifications");
    }

    Email email = getEmail();
    email.setSubject(populateForValidation(session, template.getSubject()));
    email.setText(populateForValidation(session, getFromFile(template.getBody().getText())));
    email.setHtml(populateForValidation(session, getFromFile(template.getBody().getHtml())));

    send(session.getThreePid().getAddress(), email);
}
 
Example 10
@Override
public void sendForFraudulentUnbind(ThreePid tpid) {
    EmailTemplate template = cfg.getTemplates().getSession().getUnbind().getFraudulent();
    if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
        throw new FeatureNotAvailable("No template has been configured for fraudulent unbind notifications");
    }

    Email email = getEmail();
    email.setSubject(populateForCommon(tpid, template.getSubject()));
    email.setText(populateForCommon(tpid, getFromFile(template.getBody().getText())));
    email.setHtml(populateForCommon(tpid, getFromFile(template.getBody().getHtml())));

    send(tpid.getAddress(), email);
}
 
Example 11
Source Project: syncope   File: GroupWizardBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Serializable onApplyInternal(final AnyWrapper<GroupTO> modelObject) {
    GroupTO updated = modelObject instanceof GroupWrapper
            ? GroupWrapper.class.cast(modelObject).fillDynamicConditions()
            : modelObject.getInnerObject();

    ProvisioningResult<GroupTO> result;
    if (updated.getKey() == null) {
        GroupCR req = new GroupCR();
        EntityTOUtils.toAnyCR(updated, req);
        result = GroupRestClient.create(req);
    } else {
        GroupTO original = getOriginalItem().getInnerObject();
        fixPlainAndVirAttrs(updated, original);

        // SYNCOPE-1170
        boolean othersNotEqualsOrBlanks =
                !updated.getADynMembershipConds().equals(original.getADynMembershipConds())
                || (StringUtils.isNotBlank(original.getUDynMembershipCond())
                && StringUtils.isBlank(updated.getUDynMembershipCond()))
                || (StringUtils.isBlank(original.getUDynMembershipCond())
                && StringUtils.isNotBlank(updated.getUDynMembershipCond()))
                || StringUtils.isAllBlank(original.getUDynMembershipCond(), updated.getUDynMembershipCond())
                || !updated.getUDynMembershipCond().equals(original.getUDynMembershipCond())
                || !CollectionUtils.diff(updated.getTypeExtensions(), original.getTypeExtensions()).isEmpty();

        GroupUR groupUR = AnyOperations.diff(updated, original, false);

        // update just if it is changed
        if (groupUR.isEmpty() && !othersNotEqualsOrBlanks) {
            result = new ProvisioningResult<>();
            result.setEntity(updated);
        } else {
            result = groupRestClient.update(original.getETagValue(), groupUR);
        }
    }

    return result;
}
 
Example 12
@PostMapping(value = "/importGroups", consumes = "multipart/form-data")
public String showImportGroups(@RequestParam(required=false) String groupUploadedText, Model model, HttpServletRequest req) {
    log.debug("showImportGroups called with value {}", groupUploadedText);

    // Variable definition
    Locale userLocale = sakaiService.getCurrentUserLocale();
    Map<String, List<String>> importedGroupMap = new HashMap<String, List<String>>();
    String uploadedText = StringUtils.EMPTY;
    String groupFileUploadedText = StringUtils.EMPTY;

    //Check the uploaded file and contents.
    FileItem uploadedFileItem = (FileItem) req.getAttribute("groupUploadFile");
    if (uploadedFileItem.getSize() > 0) {
        try (Scanner scanner = new Scanner(uploadedFileItem.getInputStream(), StandardCharsets.UTF_8.name())) {
            groupFileUploadedText = scanner.useDelimiter("\\A").next();
        } catch (Exception e) {
            log.error("The file {} provided is not valid.", uploadedFileItem.getName());
        }
    }

    // Check if both options are blank and return an error message
    if (StringUtils.isAllBlank(groupUploadedText, groupFileUploadedText)) {
        return returnImportError(model, "import.error.inputrequired", userLocale);
    }        

    // Process the submitted texts, combine the uploaded and the file into one String
    uploadedText = String.format("%s\r\n%s", groupUploadedText, groupFileUploadedText);

    String[] lineArray = uploadedText.split(BULK_LINE_DELIMITER);
    for (String line : lineArray) {

        if (StringUtils.isBlank(line)) {
            continue;
        }

        String[] lineContentArray = line.split(BULK_FIELD_DELIMITER);

        //Each line must contain a groupTitle and a userEid
        if (lineContentArray.length == 2) {
            String groupTitle = StringUtils.trimToNull(lineContentArray[0]);
            String userEid = StringUtils.trimToNull(lineContentArray[1]);

            if (StringUtils.isAnyBlank(groupTitle, userEid)) {
                // One of the items of the line is blank, redirect to the import form again displaying an error. 
                return returnImportError(model, "import.error.wrongformat", userLocale);
            }

            if (groupTitle.length() > 99) {
                // One of the items of the line has more than 99 characters, redirect to the import form again displaying an error. 
                return returnImportError(model, "import.error.titlelength", userLocale);
            }

            if (importedGroupMap.get(groupTitle) != null) {
                // If the map contains an entry for that group, add the user to the list
                importedGroupMap.get(groupTitle).add(userEid);
            } else {
                // If the map does not contain an entry for that group, create a list and add the member to the list
                List<String> newUserlist = new ArrayList<String>();
                newUserlist.add(userEid);
                importedGroupMap.put(groupTitle, newUserlist);
            }
        } else {
            // One line does not contain two items, redirect to the import form again displaying an error.
            return returnImportError(model, "import.error.wrongformat", userLocale);
        }
    }

    //Redirect to the confirmation page once the map are correct
    return showImportConfirmation(model, importedGroupMap);
}
 
Example 13
@PostMapping(value = "/importGroups", consumes = "multipart/form-data")
public String showImportGroups(@RequestParam(required=false) String groupUploadedText, Model model, HttpServletRequest req) {
    log.debug("showImportGroups called with value {}", groupUploadedText);

    // Variable definition
    Locale userLocale = sakaiService.getCurrentUserLocale();
    Map<String, List<String>> importedGroupMap = new HashMap<String, List<String>>();
    String uploadedText = StringUtils.EMPTY;
    String groupFileUploadedText = StringUtils.EMPTY;

    //Check the uploaded file and contents.
    FileItem uploadedFileItem = (FileItem) req.getAttribute("groupUploadFile");
    if (uploadedFileItem.getSize() > 0) {
        try (Scanner scanner = new Scanner(uploadedFileItem.getInputStream(), StandardCharsets.UTF_8.name())) {
            groupFileUploadedText = scanner.useDelimiter("\\A").next();
        } catch (Exception e) {
            log.error("The file {} provided is not valid.", uploadedFileItem.getName());
        }
    }

    // Check if both options are blank and return an error message
    if (StringUtils.isAllBlank(groupUploadedText, groupFileUploadedText)) {
        return returnImportError(model, "import.error.inputrequired", userLocale);
    }        

    // Process the submitted texts, combine the uploaded and the file into one String
    uploadedText = String.format("%s\r\n%s", groupUploadedText, groupFileUploadedText);

    String[] lineArray = uploadedText.split(BULK_LINE_DELIMITER);
    for (String line : lineArray) {

        if (StringUtils.isBlank(line)) {
            continue;
        }

        String[] lineContentArray = line.split(BULK_FIELD_DELIMITER);

        //Each line must contain a groupTitle and a userEid
        if (lineContentArray.length == 2) {
            String groupTitle = StringUtils.trimToNull(lineContentArray[0]);
            String userEid = StringUtils.trimToNull(lineContentArray[1]);

            if (StringUtils.isAnyBlank(groupTitle, userEid)) {
                // One of the items of the line is blank, redirect to the import form again displaying an error. 
                return returnImportError(model, "import.error.wrongformat", userLocale);
            }

            if (groupTitle.length() > 99) {
                // One of the items of the line has more than 99 characters, redirect to the import form again displaying an error. 
                return returnImportError(model, "import.error.titlelength", userLocale);
            }

            if (importedGroupMap.get(groupTitle) != null) {
                // If the map contains an entry for that group, add the user to the list
                importedGroupMap.get(groupTitle).add(userEid);
            } else {
                // If the map does not contain an entry for that group, create a list and add the member to the list
                List<String> newUserlist = new ArrayList<String>();
                newUserlist.add(userEid);
                importedGroupMap.put(groupTitle, newUserlist);
            }
        } else {
            // One line does not contain two items, redirect to the import form again displaying an error.
            return returnImportError(model, "import.error.wrongformat", userLocale);
        }
    }

    //Redirect to the confirmation page once the map are correct
    return showImportConfirmation(model, importedGroupMap);
}