본문 바로가기

▶ Back-End/Java55

VERIFY JWT(nimbus) JWT 검증 메소드*JWE*자세한 설명 생략  /** * JWT VERIFY * * @param HttpServletRequest * @param resVO * @return CmmResVO */public CmmResVO JWTVerify(HttpServletRequest req, CmmResVO resVO) { try { final String jwt = req.getHeader("Authorization"); if(CmmUtile.nullCheck(jwt)) { return resVO.ERR_9005(); } /** JWE RSA KEYPAIR */ final KeyFactory keyFactory = KeyFactory.getInstance.. 2023. 10. 12.
SpringBoot Security Login 기능 추가 아주 간단한 Spring Security Login 기능 추가 방법*Maven 사용*Spring Boot Project 생성 과정 생략*자세한 설명 생략  ▷ pom.xml*의존성 추가  org.springframework.boot spring-boot-starter-security  ▷ application.properties*사용자 지정 ID/PWD 설정* Default user ID : user * Default user Pwd : 서버 실행 시 제공( Using generated security password: fd67f8d9-652b-46cd-a147-4b6681292d50 ) spring.security.user.name = testspring.security.user.passwo.. 2023. 9. 26.
Objcet to String Object를 String으로 변환하는 간단한 방법  /** * * Object to String * * @param Object * @return String * @throws JsonProcessingException */public static String getObjStr(Object obj) throws JsonProcessingException { return new ObjectMapper() .registerModule(new JavaTimeModule()) .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .writeValueAsString(obj);} 2023. 9. 21.
@Value 사용법 application.properties에 설정한 값을 가져와 사용하는 @Value*자세한 설명 생략  ▷ application.properties*Test를 위한 값 설정 # valuetest.val = HELLO# maptest.mapInt = {W:0, O:1, R:2, L:3, D:4}test.mapStr = {W:'w', O:'o', R:'r', L:'l', D:'d'}# listtest.listInt = 0, 1, 2, 3, 4test.listStr = H, E, L, L, O  ▷ Application.java*간단한 Test를 위해 Application.java에서 진행*Bean이 생성된 후 사용해야 하기 때문에 CommandLineRunner 사용*CommandLineRunner : Se.. 2023. 9. 21.
LocalTime AVG LocalTime 평균 구하기*parameter는 상황에 따라 변경해서 사용(LocalTime t1, LocalTime...ts)  /** * LocalTime AVG * * @param List * @return AVG LocalTime */public static LocalTime getLocalTimeAVG(List list) { LocalTime result = LocalTime.of(0, 0, 0); if (!list.isEmpty()) { long nanoSum = 0L; for (LocalTime time : list) { nanoSum += time.toNanoOfDay(); } result = LocalTi.. 2023. 9. 21.
String to LocalTime String time format은 상황에 따라 변경해서 사용  /*** String(HHmmss) to LocalTime* * @param String(HHmmss)* @return LocalTime(HH:mm:ss)*/public static LocalTime getStrLocalTime(String str) { return LocalTime.parse(str, DateTimeFormatter.ofPattern("HHmmss"));} 2023. 9. 21.
String to LocalDate String date format은 상황에 따라 변경해서 사용  *개선 후/** * String(yyyyMMdd) to LocalDate * * @param String(yyyyMMdd) * @return LocalDate(pattern) */public static LocalDate getStrLocalDate(String str) { return LocalDate.parse(str, DateTimeFormatter.BASIC_ISO_DATE);} *개선 전/** * String(yyyyMMdd) to LocalDate * * @param String(yyyyMMdd) * @return LocalDate(pattern) */public static LocalDate getStrLocalDate.. 2023. 9. 21.
Ramdom LocalTime 생성 원하는 시간의 Random LocalTime 생성  /** * getRandomTime * * @param LocalTime (LocalTime.of(0, 0, 0)) * @param LocalTime (LocalTime.of(0, 0, 0)) * @return LocalTime(HH:mm:ss) */public LocalTime getRandomTime(LocalTime startTime, LocalTime endTime) { return LocalTime.ofSecondOfDay(ThreadLocalRandom.current().nextInt(startTime.toSecondOfDay(), endTime.toSecondOfDay()));} 2023. 9. 21.
Random LocalDate 생성 원하는 기간의 Random LocalDate 생성  /** * getRandomDate * * @param String(yyyyMMdd) * @param String(yyyyMMdd) * @return LocalDate(yyyy-MM-dd) */public LocalDate getRandomDate(String startDate, String endDate) { LocalDate fromDate = LocalDate.of( Integer.parseInt(startDate.substring(0, 4)), Integer.parseInt(startDate.substring(4, 6)), Integer.parseInt(startDate.subst.. 2023. 9. 21.
728x90
728x90