<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: YEJIN LEE</title>
    <description>The latest articles on DEV Community by YEJIN LEE (@316nancy).</description>
    <link>https://dev.to/316nancy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2474797%2Fdc25ff6b-705f-4453-9e6a-a917ce632309.png</url>
      <title>DEV Community: YEJIN LEE</title>
      <link>https://dev.to/316nancy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/316nancy"/>
    <language>en</language>
    <item>
      <title>Definition of Jwt and Use</title>
      <dc:creator>YEJIN LEE</dc:creator>
      <pubDate>Mon, 16 Dec 2024 02:13:40 +0000</pubDate>
      <link>https://dev.to/316nancy/definition-of-jwt-and-use-55cg</link>
      <guid>https://dev.to/316nancy/definition-of-jwt-and-use-55cg</guid>
      <description>&lt;p&gt;Jwt(Json Web Token)is an open standard for securely transmitting information between parties as a Json object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Structure of Jwt
&lt;/h2&gt;

&lt;p&gt;Jwt consist of three parts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkdk30dvosha9yj0mixu7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkdk30dvosha9yj0mixu7.png" alt="Image description" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Header&lt;/strong&gt; : Contain metadata about the token, such as the algorithm used for signing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Payload&lt;/strong&gt; : Include the actual data you want to share.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Signature&lt;/strong&gt; : A cryptographic "seal" that ensures the data hasn't been tempered with.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These three parts are combined into a single, encoded String that is sent between the client and the server.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why use Jwt
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt; : After a user logs in, the server generates a Jwt and send it to client. The client stores this token and send it back with every request to prove, "I'm authenticated user!" &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authorization&lt;/strong&gt; : The Jwt can include roles, So the server can easily check what the user is allowed to do.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How Jwt works
&lt;/h2&gt;

&lt;p&gt;1- The user logs in with their credentials (username, pw etc..)&lt;br&gt;
2- The server creates 'Refresh Token' and 'Access Token' and then send both token to client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Refresh Token&lt;/strong&gt;: A short lived token (ex) 15min)&lt;br&gt;
&lt;strong&gt;Access Token&lt;/strong&gt;: A long lived token (ex) 7 days)&lt;/p&gt;

&lt;p&gt;3- The client stores &lt;br&gt;
the Access Token (ex) RAM mememory, HttpOnly cookie)&lt;br&gt;
and Refresh Token. (ex) HttpOnly cookie)&lt;/p&gt;

&lt;p&gt;To store token in localStorage or SessionStorage isn't recommended, Because they are vulnerable to &lt;strong&gt;XSS(Cross-Site Scripting) attack&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;4- The client sends the access token with every request to the server (Authorization header as Bearer )&lt;/p&gt;

&lt;p&gt;5- The server verifies the token and processes the request.&lt;/p&gt;

&lt;p&gt;6- Once the access token expires, the client can't use it anymore protected resources, So we should be issued access token by using refresh token.&lt;/p&gt;

&lt;p&gt;7- If the refresh token expires, the user should log in again with their credentials. &lt;/p&gt;




&lt;h2&gt;
  
  
  How to use
&lt;/h2&gt;

&lt;p&gt;(Planned to be added)&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding
&lt;/h2&gt;

&lt;p&gt;XSS: XSS allows attackers to inject and excute malicious scripts in a user's browser.&lt;br&gt;
CSRF: CSRF tricks an authentication user into performing unintended actions on the website where the user is already authenticated.&lt;/p&gt;

</description>
      <category>jwt</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Custom Annotation</title>
      <dc:creator>YEJIN LEE</dc:creator>
      <pubDate>Mon, 02 Dec 2024 10:25:55 +0000</pubDate>
      <link>https://dev.to/316nancy/custom-annotation-1aim</link>
      <guid>https://dev.to/316nancy/custom-annotation-1aim</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is the Custom Annotation?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;An annotation is a form of metadata that provides additional information about a program. It can influence how the program is compiled, run, or processed by tools and frameworks.&lt;/p&gt;

&lt;p&gt;(metadata: Describe or provide info about &lt;br&gt;
program elements like classes, methods, variables..)&lt;/p&gt;

&lt;p&gt;Literally, a &lt;code&gt;custom annotation&lt;/code&gt; refers to creating your own annotaion in Java!&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;How can we make Custom Anotation?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;1 &lt;strong&gt;- Defining&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Retention(RetentionPolicy.RUNTIME) 
@Target(ElementType.METHOD)
public @interface MyAnnotation {
    String value() default "default value";
    int count() default 1;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'll explain KeyComponent like @Retention, @Target later&lt;/p&gt;

&lt;p&gt;2 &lt;strong&gt;- Using&lt;/strong&gt;&lt;br&gt;
Applying the Annotation that you made.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MyService {
   @MyAnnotation(value = "Hello! 안녕예진!", count = 3) &amp;lt;- !!
   public void myMethod() {
      System.out.println("Excuting myMethod");
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Accessing Annotation Values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class AnnotationProcessor {
   public static void main(String[] args) throws Exception {
     Method method = MyService.class.getMethod("myMethod");

     if (method.isAnnotationPresent(MyAnnotation.class)) {
       MyAnnotation annotation = method.getAnnotation(MyAnnotation.class)

     //Print annotation values
     System.out.println("value: " + annotation.value());
     System.out.println("Count: " + annotation.count());
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Key Components of Annotations&lt;/strong&gt;
&lt;/h2&gt;

&lt;h4&gt;
  
  
  @Retention
&lt;/h4&gt;

&lt;p&gt;specifies how long the annotation is retained!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;RetentionPolicy.SOURCE&lt;/code&gt; : &lt;br&gt;
Discarded during compliation. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;RetentionPolicy.CLASS&lt;/code&gt; : &lt;br&gt;
Retained in the class file but not available at runtime.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;RetentionPolicy.RUNTIME&lt;/code&gt; :&lt;br&gt;
Available at runtime via reflection.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  @Target
&lt;/h4&gt;

&lt;p&gt;specifies where the annotation can be applied.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ElementType.TYPE&lt;/code&gt; : Classes, interfaces, or enums.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ElementType.METHOD&lt;/code&gt; : Methods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ElementType.FIELD&lt;/code&gt; : Fileds.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Others include PARAMETER, CONSTRUCTOR, etc.&lt;/p&gt;

&lt;h4&gt;
  
  
  Attributes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Attributes in annotation are defined like methods inside the &lt;a class="mentioned-user" href="https://dev.to/interface"&gt;@interface&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All attributes in a custom annotation require a value unless a default is provided using default keyword.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All attributes must have a return type (String,int ..)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All attributes can't have parameters.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;When I can use Custom Anotation.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There is a lot. I'll show you one.&lt;/p&gt;

&lt;p&gt;1 &lt;strong&gt;- Defining&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Constraint(validateBy = NameValidator.class) 
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ValidName {
    String message() dafault "Not found username";
    Class&amp;lt;?&amp;gt;[] groups() default {};
    Class&amp;lt;? extends Payload&amp;gt;[] pay() default {};
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;@Constraint is an annotation used in the Bean Validation API. It is applied to define custom validation annotations. &lt;br&gt;
(validateBy = NameValidator.class) means that&lt;br&gt;
the NameValidator class contains the logic to validate the annotated element.&lt;/p&gt;

&lt;p&gt;2 &lt;strong&gt;- Using&lt;/strong&gt;&lt;br&gt;
Applying the Annotation that you made.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public class NameValidator implements ConstraintValidator&amp;lt;ValidName, String&amp;gt; {
   @Override
   public boolean isValid(String value, ConstraintValidatorContext context) {
      return value != ull &amp;amp;&amp;amp; value.matches("^[가-힣a-zA-Z]+$"); //permit only Kor or Eng
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class UserRequest{
   @ValidName
   private String name;
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using annotations, it became possible to use only Korean and English for names.&lt;/p&gt;

&lt;p&gt;Like these, It must improve your code readability and be reusable logic! &lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>java</category>
    </item>
    <item>
      <title>Multi Threading</title>
      <dc:creator>YEJIN LEE</dc:creator>
      <pubDate>Mon, 02 Dec 2024 04:22:19 +0000</pubDate>
      <link>https://dev.to/316nancy/multi-threading-3733</link>
      <guid>https://dev.to/316nancy/multi-threading-3733</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is the Multi Thread?&lt;/strong&gt;&lt;br&gt;
A thread is the smallest unit of execution, and multithreading improves performance by enabling taskes to run &lt;strong&gt;simultaneously&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0io210obnyq1vla0hxa6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0io210obnyq1vla0hxa6.png" alt="Image description" width="704" height="406"&gt;&lt;/a&gt;&lt;br&gt;
(sharing code, data, files)&lt;/p&gt;

&lt;p&gt;It refers to the ability of a processor to execute multiple threads concurrently within a single process!&lt;/p&gt;

&lt;p&gt;On a single-core CPU, threads are executed one at a time, switching so quickly that it apprears they run simultaneously.&lt;/p&gt;

&lt;p&gt;For example, Google Chrome uses multithreading when handling multiple tabs and rendering web pages. Each tab is a separate process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Page Rendering&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You're scrolling a web page(Main Thread)&lt;/li&gt;
&lt;li&gt;At the same time, a background thread is processing a large Json file fetched from an API.(Worker Thread)&lt;/li&gt;
&lt;li&gt;The web page remains smooth and responsive because the heavy computation is offloaded to a worker thread.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tabs and Isolation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You open two tabs, one playing a YouTube and the other loading a news website.&lt;/li&gt;
&lt;li&gt;The video tab uses thread for video decoding, audio playback, and rendering, while the news tabs uses threads to load and display content!&lt;/li&gt;
&lt;li&gt;Even if the news tab's scripts are slow, the video playback in the other tab remains unaffected. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;but, It can also make problem..&lt;br&gt;
&lt;strong&gt;DisAdvantages of Multithreading&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1 - &lt;strong&gt;Race condition&lt;/strong&gt; occurs when two or more threads attempt to modify shared data at the same time, leading to unpredictable results.&lt;/p&gt;

&lt;p&gt;let's imagine two threads accessing a bank account balance.&lt;br&gt;
if both thread read the balance at the same time, modify it without proper synchronization, the final balance could be incorrect ㅜ.ㅜ&lt;/p&gt;

&lt;p&gt;2 - &lt;strong&gt;Deadlock&lt;/strong&gt; happens when two or more threads are waiting for each other to release resources, resulting in a standstill.&lt;br&gt;
This causes the threads to be stuck indefinitely, as no one can continue.&lt;/p&gt;

&lt;p&gt;Thread A locks resource 1 and waits for resource 2,&lt;br&gt;
while Thread B locks resource 2 and waits for resource 1.&lt;br&gt;
Both threads are now blocked, causing a deadlock.&lt;/p&gt;

&lt;p&gt;3 - &lt;strong&gt;Context Switching&lt;/strong&gt; is the process where the CPU switches from executing one thread to another. When threre are many threads, the CPU spends a significant amount of time saving and loading states, which leads to performance degradation!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can I use MultiThreading in server engineering?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A server needs to handle many incoming requests from multiple clients. the server can handle multiple client requests at the same time. Each request is assigned to a separate thread or thread pool, allowing them to be processed concurrently.
without it, each request would have to be processed sequentially, which could significantly slow down response.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Session Login</title>
      <dc:creator>YEJIN LEE</dc:creator>
      <pubDate>Sun, 24 Nov 2024 06:04:18 +0000</pubDate>
      <link>https://dev.to/316nancy/session-login-1j3p</link>
      <guid>https://dev.to/316nancy/session-login-1j3p</guid>
      <description>&lt;p&gt;In a project conducted as a Springboot class, I was assign to make Session Login code. This project just require a simple CRUD with theme like bookstore, checkList and blog etc.. So I worked on the project with light heart, but I had a problem solving the error code for 10 hours.. Let me explain about session first!&lt;/p&gt;

&lt;h2&gt;
  
  
  Session
&lt;/h2&gt;

&lt;p&gt;: It is temporary connection between a client and a server that allows the server to remember the client's state across multiple requests. &lt;br&gt;
It ensures that the interation feels continuous, even though HTTP itself is stateless.(The server treats every request as new without remembering anyting about the client)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Session ID&lt;/strong&gt;: A unique ID for each session created by the server. It is usually stored in a &lt;strong&gt;cookie&lt;/strong&gt; on the client's browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lifecycle&lt;/strong&gt;: A session starts when a user connects to the server(ex) login) and ends when they logout, the session times out, or the sever terminates it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If I use session when making login,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;user connects to the server &lt;/li&gt;
&lt;li&gt;publish SessionID &lt;/li&gt;
&lt;li&gt;stock in a cookie &lt;/li&gt;
&lt;li&gt;every subsequent request, the browser automatically includes the sessionID stored in the cookie&lt;/li&gt;
&lt;li&gt;the server checks the sessionID against &lt;strong&gt;its session storage&lt;/strong&gt; to confirm the user is authenticated and retreieves the associated user data.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;excute the corresponding logic based on whether the session ID is valid.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the user logout or remains inactive for too long, the session expires.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Problem Solving
&lt;/h2&gt;

&lt;p&gt;When I look a log, I realized that the request was not coming to the desired controller of the url due to SecurityConfig. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSRF(Cross-Site Request Forgery) :&lt;/strong&gt; &lt;br&gt;
It is security issue where a malicious site tricks a logged-in user in making unauthorized requests to another trusted site.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Why API Requests Fail Without CSRF Token&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Spring Security expects the CSRF token to be sent with state-changing HTTP methods (ex) POST, PUT..). If the token is missing, the server rejects the request with 403 Forbidden&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Why SSR View Requests Work Fine&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In SSR (Server-Side Rendering), CSRF tokens are automatically included in HTML forms or cookies. When users submit a form, the token is sent with the request, allowing it to pass CSRF validation.&lt;/p&gt;

&lt;p&gt;Since GET requests for HTML views are typically non-state-chainging, they don't require CSRF tokens.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Issue with Postman API Requests&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When testing with Postman, the API request may not include the CSRF token. Since Postman doesn't automatically handle CSRF tokens like a browser does.&lt;br&gt;
This is why the request didn't map correctly..ㅜ.ㅜ&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5hr2fc9zr5u103uwu273.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5hr2fc9zr5u103uwu273.png" alt="Image description" width="674" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fortunately, I found the error on my own and fixed it! It was valuable experience as I realized the shortcomings of relying only on JWT token based login.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
