use of plus.wcj.heifer.boot.common.exception.ResultException in project heifer by galaxy-sea.
the class BeanConfig method daoAuthenticationProvider.
@Bean
public AuthenticationProvider daoAuthenticationProvider(PasswordEncoder passwordEncoder) {
DaoAuthenticationProvider impl = new DaoAuthenticationProvider();
impl.setPasswordEncoder(passwordEncoder);
impl.setUserDetailsService(username -> {
throw new ResultException(ResultStatusEnum.INTERNAL_SERVER_ERROR);
});
return impl;
}
use of plus.wcj.heifer.boot.common.exception.ResultException in project heifer by galaxy-sea.
the class BeanConfig method configure.
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.cors().configurationSource(request -> new CorsConfiguration().applyPermitDefaultValues()).and().csrf().disable().formLogin().disable().httpBasic().disable().authorizeRequests().anyRequest().authenticated().and().logout().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling().authenticationEntryPoint((request, response, authException) -> {
throw new ResultException(ResultStatusEnum.UNAUTHORIZED);
}).accessDeniedHandler((request, response, accessDeniedException) -> {
throw new ResultException(ResultStatusEnum.FORBIDDEN);
});
// @formatter:on
// 添加自定义 JWT 过滤器
http.addFilter(new JwtAuthenticationFilter(this.authenticationManager(), this.jwtUtil, this.heiferUserDetailsServiceImpl, handlerExceptionResolver));
}
use of plus.wcj.heifer.boot.common.exception.ResultException in project heifer by galaxy-sea.
the class JwtUtil method verify.
private void verify(SignedJWT signedJwt, MACVerifier verifier) throws ParseException, JOSEException {
if (!signedJwt.verify(verifier)) {
throw new ResultException(ResultStatusEnum.UNAUTHORIZED);
}
JWTClaimsSet claimsSet = signedJwt.getJWTClaimsSet();
// throw new ResultException(ResultStatus.UNAUTHORIZED);
final Date now = new Date();
final Date exp = claimsSet.getExpirationTime();
if (exp == null || !DateUtils.isAfter(exp, now, MAX_CLOCK_SKEW_SECONDS)) {
throw new ResultException(ResultStatusEnum.EXPIRED_TOKEN);
}
final Date nbf = claimsSet.getNotBeforeTime();
if (nbf == null || !DateUtils.isBefore(nbf, now, MAX_CLOCK_SKEW_SECONDS)) {
throw new ResultException(ResultStatusEnum.TOKEN_BEFORE_USE_TIME);
}
}
use of plus.wcj.heifer.boot.common.exception.ResultException in project heifer by galaxy-sea.
the class AliyunSmsServer method sendCaptcha.
@Override
public void sendCaptcha(String phoneNumbers, String captcha) {
SendSmsRequest sendSmsRequest = new SendSmsRequest().setPhoneNumbers(phoneNumbers).setSignName(this.aliyunSmsProperties.getSignName()).setTemplateCode(TemplateCode.SMS_185520034.toString()).setTemplateParam("{\"code\":\"" + captcha + "\"}");
SendSmsResponse sendSmsResponse;
try {
sendSmsResponse = this.client.sendSms(sendSmsRequest);
} catch (Exception e) {
throw new ResultException(ResultStatusEnum.SMS_NETWORK_EXCEPTION);
}
SendSmsResponseBody body = sendSmsResponse.getBody();
if (!OK.equals(body.getCode())) {
throw new ResultException(ResultStatusEnum.SMS_SEND_FAIL, body.getMessage());
}
}
use of plus.wcj.heifer.boot.common.exception.ResultException in project heifer by galaxy-sea.
the class TenantMethodArgumentResolver method resolveArgument.
@SuppressWarnings("NullableProblems")
@Override
public Tenant resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
UserPrincipal userDetails = (UserPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (userDetails == null) {
throw new ResultException(ResultStatusEnum.UNAUTHORIZED);
}
String allPower = "";
if (userDetails.getTenantId() != null) {
allPower = heiferUserDetailsService.getAllPower(userDetails.getTenantId(), userDetails.getId());
}
return new Tenant(userDetails.getId(), userDetails.getUsername(), userDetails.getTenantId(), userDetails.getDeptId(), allPower, false);
}
Aggregations