Commit f5885c6b authored by xiaozhe.chen's avatar xiaozhe.chen

尝试登陆功能

parent 0674ecaf
package cn.quantgroup.customer.config.http.mvc.converter;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
public class IntegerToEnumConverterFactory implements ConverterFactory<String, Enum> {
public IntegerToEnumConverterFactory() {
}
@Override
public <T extends Enum> Converter<String, T> getConverter(Class<T> targetType) {
Class<?> enumType = targetType;
while (enumType != null && !enumType.isEnum()) {
enumType = enumType.getSuperclass();
}
if (enumType == null) {
throw new IllegalArgumentException("The target type " + targetType.getName() + " does not refer to an enum");
} else {
return new IntegerToEnumConverterFactory.IntegerToEnum(enumType);
}
}
private class IntegerToEnum<T extends Enum> implements Converter<String, T> {
private final Class<T> enumType;
public IntegerToEnum(Class<T> enumType) {
this.enumType = enumType;
}
public T convert(String source) {
T[] ts = enumType.getEnumConstants();
int ordinal = Integer.parseInt(source);
return ordinal < ts.length && ordinal >= 0 ? ts[ordinal] : null;
}
}
}
\ No newline at end of file
......@@ -31,9 +31,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
//String allowedRoutes = "/test/**,/error/**,/user/**,/repay/**";
String allowedRoutes = "/test/**,/error/**";
String allowedRoutes = "/test/**,/error/**,/user/login";
String[] allowedRoutesArr = allowedRoutes.split(",");
http
http.httpBasic().and()
.authorizeRequests()
.antMatchers(allowedRoutesArr)
.permitAll().anyRequest().authenticated()
......
package cn.quantgroup.customer.config.http.security;
import cn.quantgroup.customer.config.http.mvc.converter.IntegerToEnumConverterFactory;
import cn.quantgroup.customer.constant.Constant;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.converter.ConverterRegistry;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.HeaderHttpSessionStrategy;
import org.springframework.session.web.http.HttpSessionStrategy;
import java.text.SimpleDateFormat;
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = Constant.COOKIE_AND_SESSION_EXPIRE_TIMEOUT_SECONDS)
public class WebSessionConfig {
......@@ -15,4 +25,38 @@ public class WebSessionConfig {
return strategy;
}
@Bean
public Jackson2ObjectMapperBuilder jacksonBuilder() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.indentOutput(false)
.dateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"))
.defaultViewInclusion(false)
.serializationInclusion(JsonInclude.Include.NON_NULL)
.featuresToEnable(SerializationFeature.WRITE_ENUMS_USING_INDEX,
DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS);
return builder;
}
@Bean
public ConverterRegistry defaultConversionService() {
FormattingConversionService conversionService = new DefaultFormattingConversionService();
addFormatter(conversionService);
return conversionService;
}
@Bean
public ConverterRegistry integrationConversionService() {
FormattingConversionService conversionService = new DefaultFormattingConversionService();
addFormatter(conversionService);
return conversionService;
}
private void addFormatter(FormattingConversionService conversionService) {
IntegerToEnumConverterFactory factory = new IntegerToEnumConverterFactory();
conversionService.removeConvertible(String.class, Enum.class);
conversionService.addConverterFactory(factory);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment