Java Code Examples for org.springframework.util.StringUtils.pathEquals()

The following are Jave code examples for showing how to use pathEquals() of the org.springframework.util.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: lams   File:   Source Code and License Vote up 6 votes
 * Set a system property to the web application root directory.
 * The key of the system property can be defined with the "webAppRootKey"
 * context-param in {@code web.xml}. Default is "webapp.root".
 * <p>Can be used for tools that support substition with {@code System.getProperty}
 * values, like log4j's "${key}" syntax within log file locations.
 * @param servletContext the servlet context of the web application
 * @throws IllegalStateException if the system property is already set,
 * or if the WAR file is not expanded
 * @see WebAppRootListener
 * @see Log4jWebConfigurer
public static void setWebAppRootSystemProperty(ServletContext servletContext) throws IllegalStateException {
	Assert.notNull(servletContext, "ServletContext must not be null");
	String root = servletContext.getRealPath("/");
	if (root == null) {
		throw new IllegalStateException(
			"Cannot set web app root system property when WAR file is not expanded");
	String param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM);
	String key = (param != null ? param : DEFAULT_WEB_APP_ROOT_KEY);
	String oldValue = System.getProperty(key);
	if (oldValue != null && !StringUtils.pathEquals(oldValue, root)) {
		throw new IllegalStateException(
			"Web app root system property already set to different value: '" +
			key + "' = [" + oldValue + "] instead of [" + root + "] - " +
			"Choose unique values for the 'webAppRootKey' context-param in your web.xml files!");
	System.setProperty(key, root);
	servletContext.log("Set web app root system property: '" + key + "' = [" + root + "]");
Example 2
Project: parkingcloud   File:   Source Code and License Vote up 5 votes
@RequestMapping(value = "/register",method = RequestMethod.POST)
@ApiOperation(value = "Register user")
public ResponseEntity<?>  register(@RequestBody AuthRequest authRequest) throws AuthenticationException{
    logger.debug("Register with \r\n"+authRequest.toString());
    if (authRequest==null || StringUtils.isEmpty(authRequest.getUsername())){
        throw new UsernameNotFoundException("Username is empty.");
    String captcha = captchaService.getCachedCaptcha(authRequest.getUsername());
    if (StringUtils.isEmpty(captcha)){
        throw new BadCaptchaException("Captcha is empty");
    if (!StringUtils.pathEquals(captcha,authRequest.getCaptcha())){
        throw new BadCaptchaException("Bad captcha");
    if (StringUtils.isEmpty(authRequest.getPassword())){
        throw new BadCredentialsException("Bad credentials");
    if (userService.isUserExist(authRequest.getUsername())){
        throw new UserExistException("User has existed");
    boolean result = userService.createUser(authRequest.getUsername(),authRequest.getPassword());
    if (result){
        return ResponseEntity.ok(AuthResponse.success());
    } else {
        logger.warn("Create user failed.");
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                .body(AuthResponse.failure("Create user failed"));