mirror of https://github.com/halo-dev/halo
Remove deprecated methods and resolve warnings on building
parent
e7bef97f85
commit
ed81be4ffd
|
@ -151,8 +151,6 @@ public class HaloConfiguration {
|
|||
"/api/admin/installations",
|
||||
"/api/admin/recoveries/migrations/*"
|
||||
);
|
||||
adminAuthenticationFilter.addTryAuthUrlMethodPattern("/api/admin/comments", HttpMethod.POST.name());
|
||||
adminAuthenticationFilter.addTryAuthUrlMethodPattern("/api/content/comments", HttpMethod.POST.name());
|
||||
adminAuthenticationFilter.setFailureHandler(
|
||||
failureHandler);
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package run.halo.app.model.dto;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import run.halo.app.model.dto.base.OutputConverter;
|
||||
import run.halo.app.model.entity.Category;
|
||||
import lombok.Data;
|
||||
|
@ -11,6 +13,8 @@ import lombok.Data;
|
|||
* @date 3/19/19
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class CategoryDTO implements OutputConverter<CategoryDTO, Category> {
|
||||
|
||||
private Integer id;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package run.halo.app.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Tag with post count output dto.
|
||||
|
@ -9,6 +11,8 @@ import lombok.Data;
|
|||
* @date 3/20/19
|
||||
*/
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TagWithPostCountDTO extends TagDTO {
|
||||
|
||||
private Long postCount;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.model.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.model.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package run.halo.app.model.support;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
|
@ -13,6 +15,8 @@ import java.util.List;
|
|||
* @date 3/25/19
|
||||
*/
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CommentPage<T> extends PageImpl<T> {
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package run.halo.app.model.vo;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import run.halo.app.model.dto.CategoryDTO;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -12,6 +14,8 @@ import java.util.List;
|
|||
* @date 3/21/19
|
||||
*/
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CategoryVO extends CategoryDTO {
|
||||
|
||||
private List<CategoryVO> children;
|
||||
|
|
|
@ -18,7 +18,10 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Abstract authentication filter.
|
||||
|
@ -35,11 +38,6 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
|
|||
*/
|
||||
private Set<String> excludeUrlPatterns = new HashSet<>(2);
|
||||
|
||||
/**
|
||||
* Try authenticating url, method patterns.
|
||||
*/
|
||||
private Map<String, String> tryAuthUrlMethodPatterns = new HashMap<>(2);
|
||||
|
||||
protected final AntPathMatcher antPathMatcher;
|
||||
|
||||
protected final HaloProperties haloProperties;
|
||||
|
@ -72,26 +70,6 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
|
|||
return excludeUrlPatterns.stream().anyMatch(p -> antPathMatcher.match(p, request.getServletPath()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Should skip authentication failure.
|
||||
*
|
||||
* @param request http servlet request must not be null.
|
||||
* @return true if the request should skip authentication failure; false otherwise
|
||||
*/
|
||||
@Deprecated
|
||||
protected boolean shouldSkipAuthenticateFailure(@NonNull HttpServletRequest request) {
|
||||
Assert.notNull(request, "Http servlet request must not be null");
|
||||
|
||||
for (String url : tryAuthUrlMethodPatterns.keySet()) {
|
||||
if (antPathMatcher.match(url, request.getServletPath())
|
||||
&& tryAuthUrlMethodPatterns.get(url).equalsIgnoreCase(request.getMethod())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets exclude url patterns.
|
||||
*
|
||||
|
@ -124,20 +102,6 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
|
|||
return excludeUrlPatterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds try authenticating url method pattern.
|
||||
*
|
||||
* @param url url must not be blank
|
||||
* @param method method must not be blank
|
||||
*/
|
||||
@Deprecated
|
||||
public void addTryAuthUrlMethodPattern(@NonNull String url, @NonNull String method) {
|
||||
Assert.hasText(url, "Try authenticating url must not be blank");
|
||||
Assert.hasText(method, "Try authenticating method must not be blank");
|
||||
|
||||
tryAuthUrlMethodPatterns.put(url, method);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets authentication failure handler. (Default: @DefaultAuthenticationFailureHandler)
|
||||
|
@ -145,7 +109,7 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
|
|||
* @return authentication failure handler
|
||||
*/
|
||||
@NonNull
|
||||
public AuthenticationFailureHandler getFailureHandler() {
|
||||
protected AuthenticationFailureHandler getFailureHandler() {
|
||||
if (failureHandler == null) {
|
||||
synchronized (this) {
|
||||
if (failureHandler == null) {
|
||||
|
|
|
@ -78,17 +78,6 @@ public interface UserService extends CrudService<User, Integer> {
|
|||
@NonNull
|
||||
User getByEmailOfNonNull(@NonNull String email);
|
||||
|
||||
/**
|
||||
* Logins by username and password.
|
||||
*
|
||||
* @param key username or email must not be blank
|
||||
* @param password password must not be blank
|
||||
* @return user info
|
||||
*/
|
||||
@NonNull
|
||||
@Deprecated
|
||||
User login(@NonNull String key, @NonNull String password);
|
||||
|
||||
/**
|
||||
* Updates user password.
|
||||
*
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package run.halo.app.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
@ -19,14 +18,10 @@ import run.halo.app.model.entity.User;
|
|||
import run.halo.app.model.enums.LogType;
|
||||
import run.halo.app.model.params.UserParam;
|
||||
import run.halo.app.repository.UserRepository;
|
||||
import run.halo.app.security.context.SecurityContextHolder;
|
||||
import run.halo.app.security.filter.AdminAuthenticationFilter;
|
||||
import run.halo.app.security.support.UserDetail;
|
||||
import run.halo.app.service.UserService;
|
||||
import run.halo.app.service.base.AbstractCrudService;
|
||||
import run.halo.app.utils.DateUtils;
|
||||
import run.halo.app.utils.HaloUtils;
|
||||
import run.halo.app.utils.ServletUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
@ -104,68 +99,6 @@ public class UserServiceImpl extends AbstractCrudService<User, Integer> implemen
|
|||
return getByEmail(email).orElseThrow(() -> new NotFoundException("The email dose not exist").setErrorData(email));
|
||||
}
|
||||
|
||||
@Override
|
||||
public User login(String key, String password) {
|
||||
Assert.hasText(key, "Username or email must not be blank");
|
||||
Assert.hasText(password, "Password must not be blank");
|
||||
|
||||
// Check login status
|
||||
if (SecurityContextHolder.getContext().isAuthenticated()) {
|
||||
throw new BadRequestException("You have logged in already, no need to log in again");
|
||||
}
|
||||
|
||||
// Ger user by username
|
||||
User user = Validator.isEmail(key) ? getByEmailOfNonNull(key) : getByUsernameOfNonNull(key);
|
||||
|
||||
Date now = DateUtils.now();
|
||||
|
||||
// Check expiration
|
||||
if (user.getExpireTime() != null && user.getExpireTime().after(now)) {
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(user.getExpireTime().getTime() - now.getTime());
|
||||
// If expired
|
||||
throw new BadRequestException("You have been temporarily disabled,please try again " + HaloUtils.timeFormat(seconds) + " later").setErrorData(seconds);
|
||||
}
|
||||
|
||||
if (!BCrypt.checkpw(password, user.getPassword())) {
|
||||
// If the password is mismatch
|
||||
// Add login failure count
|
||||
Integer loginFailureCount = stringCacheStore.getAny(LOGIN_FAILURE_COUNT_KEY, Integer.class).orElse(0);
|
||||
|
||||
if (loginFailureCount >= MAX_LOGIN_TRY - 1) {
|
||||
// Set expiration
|
||||
user.setExpireTime(org.apache.commons.lang3.time.DateUtils.addMinutes(now, LOCK_MINUTES));
|
||||
// Update user
|
||||
update(user);
|
||||
}
|
||||
|
||||
loginFailureCount++;
|
||||
|
||||
stringCacheStore.putAny(LOGIN_FAILURE_COUNT_KEY, loginFailureCount, LOCK_MINUTES, TimeUnit.MINUTES);
|
||||
|
||||
int remainder = MAX_LOGIN_TRY - loginFailureCount;
|
||||
|
||||
String errorMessage = String.format("Username or password incorrect, you%shave %s", remainder <= 0 ? "" : " still ", HaloUtils.pluralize(remainder, "chance", "chances"));
|
||||
|
||||
// Lot it
|
||||
eventPublisher.publishEvent(new LogEvent(this, key, LogType.LOGIN_FAILED, password));
|
||||
|
||||
throw new BadRequestException(errorMessage);
|
||||
}
|
||||
|
||||
// Clear the login failure count cache
|
||||
stringCacheStore.delete(LOGIN_FAILURE_COUNT_KEY);
|
||||
|
||||
// Set session
|
||||
ServletUtils.getCurrentRequest().ifPresent(request -> {
|
||||
request.getSession().setAttribute(AdminAuthenticationFilter.ADMIN_SESSION_KEY, new UserDetail(user));
|
||||
});
|
||||
|
||||
// Log it
|
||||
eventPublisher.publishEvent(new LogEvent(this, user.getId().toString(), LogType.LOGGED_IN, user.getUsername()));
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User updatePassword(String oldPassword, String newPassword, Integer userId) {
|
||||
Assert.hasText(oldPassword, "Old password must not be blank");
|
||||
|
|
|
@ -64,33 +64,4 @@ public class HaloMediaType extends MediaType {
|
|||
super(type, subtype, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the media type is zip type or not .
|
||||
*
|
||||
* @param mediaType media type
|
||||
* @return true if the given media type is zip type; false otherwise
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isZipType(MediaType mediaType) {
|
||||
if (mediaType == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mediaType.includes(APPLICATION_ZIP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the media type is zip type or not .
|
||||
*
|
||||
* @param contentType content type
|
||||
* @return true if the given content type is zip type; false otherwise
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isZipType(String contentType) {
|
||||
if (StringUtils.isBlank(contentType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isZipType(valueOf(contentType));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,4 @@ public class MediaTypeTest {
|
|||
assertFalse(isInclude);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zipTest() {
|
||||
MediaType mediaType = MediaType.valueOf("application/x-zip-compressed");
|
||||
log.debug("Zip type: [{}]", mediaType);
|
||||
|
||||
assertFalse(HaloMediaType.isZipType(mediaType));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package run.halo.app.model.dto.base;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -47,6 +45,8 @@ public class InputConverterTest {
|
|||
}
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class TestDomain {
|
||||
|
@ -57,6 +57,8 @@ public class InputConverterTest {
|
|||
}
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class TestInputDTO implements InputConverter<TestDomain>, Serializable {
|
||||
|
@ -65,6 +67,8 @@ public class InputConverterTest {
|
|||
}
|
||||
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class SubTestInputDTO extends TestInputDTO {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package run.halo.app.model.dto.base;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -35,6 +33,8 @@ public class OutputConverterTest {
|
|||
}
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class TestDomain {
|
||||
|
@ -45,6 +45,8 @@ public class OutputConverterTest {
|
|||
}
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class TestOutputDTO implements OutputConverter<TestOutputDTO, TestDomain> {
|
||||
|
@ -53,6 +55,8 @@ public class OutputConverterTest {
|
|||
}
|
||||
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class SubTestOutputDTO extends TestOutputDTO {
|
||||
|
|
|
@ -40,6 +40,7 @@ public class RecoveryServiceTest {
|
|||
log.debug(migrationObject.getClass().toString());
|
||||
|
||||
if (migrationObject instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> migrationMap = (Map<String, Object>) migrationObject;
|
||||
|
||||
migrationMap.forEach((key, value) -> log.debug("Key: [{}], value type: [{}], value: [{}]", key, value.getClass().getTypeName(), value));
|
||||
|
|
Loading…
Reference in New Issue