๐Ÿš€ Java ๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํ˜„๋Œ€ ๋ณด์•ˆ ๊ฐ€์ด๋“œ

๋ฐœํ–‰: (2025๋…„ 12์›” 3์ผ ์˜ค์ „ 02:48 GMT+9)
5 min read
์›๋ฌธ: Dev.to

Source: Dev.to

Zeroโ€‘Trust ๊ทœ์น™ โ€“ ์‚ฌ์šฉ์ž๊ฐ€ ๋ˆ„๊ตฌ์ธ์ง€ ํ™•์ธํ•˜๊ณ , ๊ทธ๋“ค์ด ๋ฌด์—‡์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ฒ€์ฆํ•˜๋ฉฐ, VPC ๋‚ด๋ถ€๋ผ๋„ ์•”๋ฌต์ ์ธ ์‹ ๋ขฐ๋ฅผ ๋‘์ง€ ๋งˆ์„ธ์š”.

ํ•ต์‹ฌ ํ๋ฆ„

Client โ†’ API Gateway โ†’ Authorization Server โ†’ Resource Server

Zeroโ€‘Trust ๊ทœ์น™

  • ์‚ฌ์šฉ์ž๊ฐ€ ๋ˆ„๊ตฌ์ธ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  • ์‚ฌ์šฉ์ž๊ฐ€ ๋ฌด์—‡์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  • ์•”๋ฌต์ ์ธ ์‹ ๋ขฐ ๊ธˆ์ง€ โ€” VPC ๋‚ด๋ถ€๋ผ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค.
  • ํ† ํฐ์€ ํ•ญ์ƒ ๋‹จ๊ธฐ๊ฐ„์— ๋งŒ๋ฃŒ๋˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

JWT โ€” ๋น„๋Œ€์นญ ํ‚ค ์‚ฌ์šฉ (RS256)

ํ‚ค ์ „๋žต

  • Private Key: Authorization Server์—๋งŒ ๋ณด๊ด€ํ•ฉ๋‹ˆ๋‹ค.
  • Public Key: ๊ฒ€์ฆ์„ ์œ„ํ•ด Gateway์™€ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค์— ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค.

Stepโ€ฏ1: RSA ํ‚ค ์ƒ์„ฑ

openssl genrsa -out private.pem 4096
openssl rsa -in private.pem -pubout -out public.pem

Stepโ€ฏ2: Spring Boot JWT ๊ฒ€์ฆ (Public Key)

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
    http
        .authorizeHttpRequests(auth -> auth
            .requestMatchers("/public/**").permitAll()
            .anyRequest().authenticated()
        )
        .oauth2ResourceServer(oauth -> oauth
            .jwt(jwt -> jwt.publicKey(publicKey()))
        )
        .sessionManagement(session -> session
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        );
    return http.build();
}

@Bean
public RSAPublicKey publicKey() throws Exception {
    String key = Files.readString(Path.of("public.pem"))
            .replace("-----BEGIN PUBLIC KEY-----", "")
            .replace("-----END PUBLIC KEY-----", "")
            .replaceAll("\\s", "");

    byte[] decoded = Base64.getDecoder().decode(key);
    return (RSAPublicKey) KeyFactory
            .getInstance("RSA")
            .generatePublic(new X509EncodedKeySpec(decoded));
}

๋ฐฉ์–ด ๋ชฉ๋ก โ€“ ๋ณด์•ˆ HTTP ํ—ค๋”

  • Contentโ€‘Securityโ€‘Policy (CSP): ์•…์„ฑ JS ์‚ฝ์ž…์„ ์ฐจ๋‹จํ•˜์—ฌ ๋Œ€๋ถ€๋ถ„์˜ XSS๋ฅผ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.
  • Strictโ€‘Transportโ€‘Security (HSTS): HTTPS๋ฅผ ๊ฐ•์ œํ•˜๊ณ  SSL ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œ๋ฅผ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.
  • Xโ€‘Frameโ€‘Options: ํ”„๋ ˆ์ž„ ์‚ฝ์ž…์„ ์ฐจ๋‹จํ•ด ํด๋ฆญ์žฌํ‚น์„ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.
  • Xโ€‘Contentโ€‘Typeโ€‘Options: MIME ์Šค๋‹ˆํ•‘์„ ์ฐจ๋‹จํ•ฉ๋‹ˆ๋‹ค.

๋ณด์•ˆ ํ—ค๋” ์„ค์ • (Spring Security)

http.headers(headers -> headers
    .contentSecurityPolicy(csp -> csp
        .policyDirectives("default-src 'self'; script-src 'self'")
    )
    .xssProtection(xss -> xss.block(true))
    .frameOptions(HeadersConfigurer.FrameOptionsConfig::deny)
    .httpStrictTransportSecurity(hsts -> hsts
        .includeSubDomains(true)
        .maxAgeInSeconds(31536000)
    )
    .contentTypeOptions(Customizer.withDefaults())
);

CSRF ์„ค์ •

  • JWT๋ฅผ ํ—ค๋”์— ์‚ฌ์šฉํ•  ๋•Œ: CSRF๋ฅผ ๋น„ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค (ํ† ํฐ ์ž์ฒด๊ฐ€ ๋ณดํ˜ธ ์—ญํ• ์„ ํ•จ).
http.csrf(csrf -> csrf.disable());
  • ์ฟ ํ‚ค ๊ธฐ๋ฐ˜ ์ธ์ฆ์„ ์‚ฌ์šฉํ•  ๋•Œ: CSRF ๋ณดํ˜ธ๋ฅผ ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค.

์ž…๋ ฅ ๊ฒ€์ฆ ๋ฐ ์ •ํ™”

// Example using Google's JSON Sanitizer (or similar)
String sanitized = JsonSanitizer.sanitize(userInput);

// Log sanitized data only
log.info("User input: {}", sanitized);

// Simple length check
if (userInput.length() > 200) {
    throw new BadRequestException();
}

API Gateway ์—ญํ• 

ํ๋ฆ„: Client โ†’ WAF โ†’ Load Balancer โ†’ API Gateway โ†’ Microservices

  • ์ค‘์•™ ์ง‘์ค‘์‹ ์ธ์ฆ
  • JWT ๊ฒ€์ฆ
  • Rate limiting ๋ฐ IP ์ฐจ๋‹จ ๋ฆฌ์ŠคํŠธ
  • ๋ผ์šฐํŠธ ๊ฒฉ๋ฆฌ

Spring Cloud Gateway Token Relay ์˜ˆ์‹œ

spring:
  cloud:
    gateway:
      routes:
        - id: secure-service
          uri: http://localhost:8082
          predicates:
            - Path=/secure/**
          filters:
            - RemoveRequestHeader=Cookie
            - TokenRelay

Stateless architecture โ€“ JWT๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์„ธ์…˜ ์Šคํ‹ฐํ‚ค๋‹ˆ์Šค๊ฐ€ ํ•„์š” ์—†์Šต๋‹ˆ๋‹ค.

Client
   |
Load Balancer
   โ†“
Microservice A โ†” Microservice B

Actuator ๋…ธ์ถœ ๊ด€๋ฆฌ

์ „์ฒด ์‹œ์Šคํ…œ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๊ฐ€ ์œ ์ถœ๋˜์ง€ ์•Š๋„๋ก ๋…ธ์ถœ์„ ๋ช…์‹œ์ ์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค:

management.endpoints.web.exposure.include=health,info
management.endpoints.web.exposure.exclude=env,beans

๋น„๋ฐ€๋ฒˆํ˜ธ ์ธ์ฝ”๋”ฉ

์ง์ ‘ ์•”ํ˜ธํ™” ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜์ง€ ๋งˆ์„ธ์š”. BCrypt๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์˜๋„์ ์œผ๋กœ ๋А๋ฆฌ๊ฒŒ ๋™์ž‘ํ•ด ๋ฌด์ฐจ๋ณ„ ๋Œ€์ž… ๊ณต๊ฒฉ์— ๊ฐ•ํ•ฉ๋‹ˆ๋‹ค.

@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder(12);
}

Enterprise Control List (๊ณ„์ธตํ˜• ๋ณด์•ˆ)

LayerFocus
1 โ€“ PerimeterWAF, DDoS mitigation
2 โ€“ NetworkZeroโ€‘Trust, TLSโ€ฏ1.3
3 โ€“ GatewayAuth, rate limits
4 โ€“ ApplicationOAuth2, JWTโ€ฏRS256
5 โ€“ HeadersCSP, HSTS, Xโ€‘Frameโ€‘Options
6 โ€“ CodeInput validation
7 โ€“ SecretsVault / AWS Secrets Manager
8 โ€“ MonitoringSIEM, audit logs

์•„ํ‚คํ…์ฒ˜ ์ฒญ์‚ฌ์ง„

๐Ÿ“ฑ Client
   โ†“ (TLSโ€ฏ1.3)
๐ŸŒ API Gateway (JWT validation, throttling)
   โ†“
๐Ÿ” Microservices (RBAC + scopes)
   โ†“
๐Ÿ—„ Encrypted Database (leastโ€‘privilege access)

์ •๋ฆฌ

๋Œ€๋ถ€๋ถ„์˜ ํ”„๋กœ์ ํŠธ๋Š” ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€๋งŒ ๋ณดํ˜ธํ•ฉ๋‹ˆ๋‹ค. ์—”ํ„ฐํ”„๋ผ์ด์ฆˆ ์ˆ˜์ค€ ์‹œ์Šคํ…œ์€ ๋ชจ๋“  ๊ณ„์ธต์—์„œ ๋ณดํ˜ธ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ œ์‹œํ•œ ์‹ค์ฒœ ํ•ญ๋ชฉ ์ค‘ ์ ˆ๋ฐ˜์ด๋ผ๋„ ์ ์šฉํ•˜๋ฉด ๋Œ€๋ถ€๋ถ„์˜ ๊ฐœ๋ฐœ์ž๋ณด๋‹ค ์•ž์„œ ๋‚˜๊ฐˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๐Ÿš€

Back to Blog

๊ด€๋ จ ๊ธ€

๋” ๋ณด๊ธฐ ยป

Java OOPS ๊ฐœ๋…

Forem ๋กœ๊ณ https://media2.dev.to/dynamic/image/width=65,height=,fit=scale-down,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%...

Java: ์ดˆ๋ณด์ž๋ถ€ํ„ฐ ๊ณ ๊ธ‰๊นŒ์ง€ ์™„์ „ ๊ฐ€์ด๋“œ (์‹ค์šฉ ์ฝ”๋“œ ์˜ˆ์ œ ํฌํ•จ)

Java๋ž€ ๋ฌด์—‡์ด๋ฉฐ ์™œ ์ธ๊ธฐ๊ฐ€ ์žˆ๋‚˜์š”? Java๋Š” classโ€‘based, objectโ€‘oriented, platformโ€‘independent, strongly typed ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. ์ฃผ์š” ํŠน์ง• - Platform...

์„œ๋น„์Šค ์„ธ๋ถ„์„ฑ: ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค๋Š” ์–ธ์ œ ์ง„์ •์œผ๋กœ โ€œ๋งˆ์ดํฌ๋กœโ€์ธ๊ฐ€?

๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค ์ดˆ์ฐฝ๊ธฐ์—๋Š” โ€œ์ž‘๊ณ  ๋…๋ฆฝ์ โ€์ด๋ผ๋Š” ๊ฒƒ์ด ์ถฉ๋ถ„ํžˆ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋“ค๋ ธ๋‹ค. ํŒ€๋“ค์€ ๋ชจ๋†€๋ฆฌ์Šค๋ฅผ ๋ถ„ํ•ดํ•˜๊ณ , ์—ด ๊ฐœ๊ฐ€ ๋„˜๋Š” ์ƒˆ๋กœ์šด ์„œ๋น„์Šค๋ฅผ ๋„์›Œ ๋†“์œผ๋ฉฐ ์„ ์–ธํ–ˆ๋‹ค.

Java์˜ expm1() ๋ฉ”์„œ๋“œ ์„ค๋ช…: ์™œ Math.exp(x)-1์ด ๋ถ€์กฑํ•œ๊ฐ€

Java์˜ Math.expm1 ๋ฉ”์„œ๋“œ๋Š” e^x - 1์„ ์ง์ ‘ ๊ณ„์‚ฐํ•˜์—ฌ, ๋งค์šฐ ์ž‘์€ x์— ๋Œ€ํ•ด Math.expx - 1์„ ํ‰๊ฐ€ํ•  ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ์ •๋ฐ€๋„ ์†์‹ค์„ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค. ์ •ํ™•ํžˆ M์€ ๋ฌด์—‡์ธ๊ฐ€์š”?