<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:series="https://publishpress.com/"
	
	>
<channel>
	<title>
	Comments on: SpringBoot2로 Rest api 만들기(8) –  SpringSecurity 를 이용한 인증 및 권한부여	</title>
	<atom:link href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/</link>
	<description>기저귀 갈면서 코딩해야 프로다!</description>
	<lastBuildDate>Thu, 17 Feb 2022 09:54:17 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.5</generator>
	<item>
		<title>
		By: tttt		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12757</link>

		<dc:creator><![CDATA[tttt]]></dc:creator>
		<pubDate>Thu, 23 Dec 2021 02:29:11 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12757</guid>

					<description><![CDATA[JwtTokenProvider의

getAuthentication 메소드에서

User user = User.builder().uid(String.valueOf(parseInfo.get(&quot;msrl&quot;))).roles((List)parseInfo.get(&quot;authorities&quot;)).build();

부분에 User의 uid에 왜 msrl를 넣는건가요 ??

이러면 나중에 유저 단건조회에서 에러나던데요...]]></description>
			<content:encoded><![CDATA[<p>JwtTokenProvider의</p>
<p>getAuthentication 메소드에서</p>
<p>User user = User.builder().uid(String.valueOf(parseInfo.get(&#8220;msrl&#8221;))).roles((List)parseInfo.get(&#8220;authorities&#8221;)).build();</p>
<p>부분에 User의 uid에 왜 msrl를 넣는건가요 ??</p>
<p>이러면 나중에 유저 단건조회에서 에러나던데요&#8230;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: happydaddy		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12741</link>

		<dc:creator><![CDATA[happydaddy]]></dc:creator>
		<pubDate>Wed, 28 Jul 2021 06:19:51 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12741</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12738&quot;&gt;dev&lt;/a&gt;.

안녕하세요. 내용을 제가 늦게 확인하였네요. 제가 만든 token은 oauth와 상관이 없는지라 refresh_token을 고려하지 않았습니다. 정석으로 하려면 spring oauth를 통해서 api서버를 구성하시는게 맞을거 같구요. 본문의 api를 활용하려면 일단 로그인후 발급하는 token을 refresh token까지 2개를 생성해서 내려야 할거 같습니다. refresh token은 만료시간을 길게 잡아야 할거 같고, refresh token을 통해서 새로운 token을 발급해주는 api를 하나더 만들어야 할거 같습니다.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12738">dev</a>.</p>
<p>안녕하세요. 내용을 제가 늦게 확인하였네요. 제가 만든 token은 oauth와 상관이 없는지라 refresh_token을 고려하지 않았습니다. 정석으로 하려면 spring oauth를 통해서 api서버를 구성하시는게 맞을거 같구요. 본문의 api를 활용하려면 일단 로그인후 발급하는 token을 refresh token까지 2개를 생성해서 내려야 할거 같습니다. refresh token은 만료시간을 길게 잡아야 할거 같고, refresh token을 통해서 새로운 token을 발급해주는 api를 하나더 만들어야 할거 같습니다.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: dev		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12738</link>

		<dc:creator><![CDATA[dev]]></dc:creator>
		<pubDate>Wed, 14 Jul 2021 14:34:48 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12738</guid>

					<description><![CDATA[좋은 글 감사드립니다.
한가지 여쭤볼게있어 댓글 남깁니다.
위 소스에 Refresh Token을 적용하고 싶은데 조언 부탁드립니다. 
감사합니다]]></description>
			<content:encoded><![CDATA[<p>좋은 글 감사드립니다.<br />
한가지 여쭤볼게있어 댓글 남깁니다.<br />
위 소스에 Refresh Token을 적용하고 싶은데 조언 부탁드립니다.<br />
감사합니다</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: happydaddy		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12733</link>

		<dc:creator><![CDATA[happydaddy]]></dc:creator>
		<pubDate>Tue, 29 Jun 2021 10:12:17 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12733</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12732&quot;&gt;pimang&lt;/a&gt;.

안녕하세요~! 답변이 늦었습니다. 꽤나 오래전에 작성한 코드라 분석하는데 시간이 좀 걸렸네요.
일단 구조적인 문제가 있어 리팩토링이 필요할거 같습니다. 다만 쉽게 처리하려면 다음과 같이 처리하시면 됩니다. 다만 이렇게 할경우 CUserNotFoundException이 발생하는 것이 아니라 권한 없음 결과가 나오므로 참고 하시기 바랍니다.

JwtAuthenticationFilter.java
&lt;code&gt;
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        String token = jwtTokenProvider.resolveToken((HttpServletRequest) request);
        if (token != null &amp;&amp; jwtTokenProvider.validateToken(token)) {
            Authentication auth = null;
            try {
                auth = jwtTokenProvider.getAuthentication(token);
            } catch (Exception e) {
                e.printStackTrace();
            }
            SecurityContextHolder.getContext().setAuthentication(auth);
        }
        filterChain.doFilter(request, response);
    }
&lt;/code&gt;

결과
&lt;code&gt;
{
  &quot;success&quot;: false,
  &quot;code&quot;: -1002,
  &quot;msg&quot;: &quot;해당 리소스에 접근하기 위한 권한이 없습니다.&quot;
}
&lt;/code&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12732">pimang</a>.</p>
<p>안녕하세요~! 답변이 늦었습니다. 꽤나 오래전에 작성한 코드라 분석하는데 시간이 좀 걸렸네요.<br />
일단 구조적인 문제가 있어 리팩토링이 필요할거 같습니다. 다만 쉽게 처리하려면 다음과 같이 처리하시면 됩니다. 다만 이렇게 할경우 CUserNotFoundException이 발생하는 것이 아니라 권한 없음 결과가 나오므로 참고 하시기 바랍니다.</p>
<p>JwtAuthenticationFilter.java<br />
<code><br />
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {<br />
        String token = jwtTokenProvider.resolveToken((HttpServletRequest) request);<br />
        if (token != null &#038;& jwtTokenProvider.validateToken(token)) {<br />
            Authentication auth = null;<br />
            try {<br />
                auth = jwtTokenProvider.getAuthentication(token);<br />
            } catch (Exception e) {<br />
                e.printStackTrace();<br />
            }<br />
            SecurityContextHolder.getContext().setAuthentication(auth);<br />
        }<br />
        filterChain.doFilter(request, response);<br />
    }<br />
</code></p>
<p>결과<br />
<code><br />
{<br />
  "success": false,<br />
  "code": -1002,<br />
  "msg": "해당 리소스에 접근하기 위한 권한이 없습니다."<br />
}<br />
</code></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: pimang		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12732</link>

		<dc:creator><![CDATA[pimang]]></dc:creator>
		<pubDate>Sun, 27 Jun 2021 17:43:50 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12732</guid>

					<description><![CDATA[좋은글 작성해 주셔서 많은 공부가 되고 있습니다. 감사합니다.

알려주신 대로 작성을 해서 테스트를 해보고 있는데.

public UserDetails loadUserByUsername(String userPk) {
      return userJpaRepo.findById(Long.valueOf(userPk))
                            .orElseThrow(CUserNotFoundException::new);
}

위의 로그인 부분에서 존재하지 않는 아이디를 조회하려고 할경우 CUserNotFoundException 호출하도록 되어 있는데. 6장에서 알려주신 @RestControllerAdvice 응답값 형태로 처리가 되는 다른 예외처리와 다르게 아래와 같이 오류가 발생합니다.

단건회원 조회등 다른 컨트롤러나 서비스등에서 CUserNotFoundException 예외호출하면 정상적으로 &#039;-1000 코드, 존재하지 않는 회원입니다&#039; 라는 결과가 나오는걸 봐서 CUserNotFoundException 관련 오류 처리 부분에는 이상이 없는거 같은데

이상하게 loadUserByUsername() 에서 호출할경우는 아래와 오류가 발생합니다.

제가 개발하면서 먼가 잘못했나 싶어 본문 링크에 올려주신 깃허브 소스파일을 내려받아 실행해 봐도 같은 현상이네요.

loadUserByUsername() 에서도 아래와 같은 오류가 아니라 json 형태의 응답값으로 반환하려면  어떤 작업을 해야 할까요?


-----------------------오류내용--------------------------------

ERROR 18488 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception

com.rest.advice.exception.CUserNotFoundException: null
	at java.base/java.util.Optional.orElseThrow(Optional.java:408) ~[na:na]
	at com.rest.service.CustomUserDetailService.loadUserByUsername(CustomUserDetailService.java:18) ~[main/:na]
	at com.rest.config.security.JwtTokenProvider.getAuthentication(JwtTokenProvider.java:53) ~[main/:na]
	at com.rest.config.security.JwtAuthenticationFilter.doFilter(JwtAuthenticationFilter.java:28) ~[main/:na]]]></description>
			<content:encoded><![CDATA[<p>좋은글 작성해 주셔서 많은 공부가 되고 있습니다. 감사합니다.</p>
<p>알려주신 대로 작성을 해서 테스트를 해보고 있는데.</p>
<p>public UserDetails loadUserByUsername(String userPk) {<br />
      return userJpaRepo.findById(Long.valueOf(userPk))<br />
                            .orElseThrow(CUserNotFoundException::new);<br />
}</p>
<p>위의 로그인 부분에서 존재하지 않는 아이디를 조회하려고 할경우 CUserNotFoundException 호출하도록 되어 있는데. 6장에서 알려주신 @RestControllerAdvice 응답값 형태로 처리가 되는 다른 예외처리와 다르게 아래와 같이 오류가 발생합니다.</p>
<p>단건회원 조회등 다른 컨트롤러나 서비스등에서 CUserNotFoundException 예외호출하면 정상적으로 &#8216;-1000 코드, 존재하지 않는 회원입니다&#8217; 라는 결과가 나오는걸 봐서 CUserNotFoundException 관련 오류 처리 부분에는 이상이 없는거 같은데</p>
<p>이상하게 loadUserByUsername() 에서 호출할경우는 아래와 오류가 발생합니다.</p>
<p>제가 개발하면서 먼가 잘못했나 싶어 본문 링크에 올려주신 깃허브 소스파일을 내려받아 실행해 봐도 같은 현상이네요.</p>
<p>loadUserByUsername() 에서도 아래와 같은 오류가 아니라 json 형태의 응답값으로 반환하려면  어떤 작업을 해야 할까요?</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;오류내용&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>ERROR 18488 &#8212; [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception</p>
<p>com.rest.advice.exception.CUserNotFoundException: null<br />
	at java.base/java.util.Optional.orElseThrow(Optional.java:408) ~[na:na]<br />
	at com.rest.service.CustomUserDetailService.loadUserByUsername(CustomUserDetailService.java:18) ~[main/:na]<br />
	at com.rest.config.security.JwtTokenProvider.getAuthentication(JwtTokenProvider.java:53) ~[main/:na]<br />
	at com.rest.config.security.JwtAuthenticationFilter.doFilter(JwtAuthenticationFilter.java:28) ~[main/:na]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: happydaddy		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12702</link>

		<dc:creator><![CDATA[happydaddy]]></dc:creator>
		<pubDate>Tue, 06 Apr 2021 12:14:06 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12702</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12699&quot;&gt;돈술사&lt;/a&gt;.

안녕하세요. 저도 스터디겸 올린거라 부족한점이 많습니다. 만약 실무에 사용하시려면 많은 부분 개선이 필요할 것입니다. 즐거운 코딩 하시기 바랍니다.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12699">돈술사</a>.</p>
<p>안녕하세요. 저도 스터디겸 올린거라 부족한점이 많습니다. 만약 실무에 사용하시려면 많은 부분 개선이 필요할 것입니다. 즐거운 코딩 하시기 바랍니다.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: happydaddy		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12701</link>

		<dc:creator><![CDATA[happydaddy]]></dc:creator>
		<pubDate>Tue, 06 Apr 2021 12:12:35 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12701</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12700&quot;&gt;돈술사&lt;/a&gt;.

안녕하세요.  
기능에 변화는 없지만 언급해주신데로 protected 타입을 쓰는게 맞는거 같습니다.  감사합니다~!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12700">돈술사</a>.</p>
<p>안녕하세요.<br />
기능에 변화는 없지만 언급해주신데로 protected 타입을 쓰는게 맞는거 같습니다.  감사합니다~!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: 돈술사		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12700</link>

		<dc:creator><![CDATA[돈술사]]></dc:creator>
		<pubDate>Tue, 06 Apr 2021 01:30:57 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12700</guid>

					<description><![CDATA[@ExceptionHandler(CAuthenticationEntryPointException.class)
public CommonResult authenticationEntryPointException(HttpServletRequest request, CAuthenticationEntryPointException e) {
        return responseService.getFailResult(Integer.valueOf(getMessage(&quot;entryPointException.code&quot;)), getMessage(&quot;entryPointException.msg&quot;));
}

@ExceptionHandler(AccessDeniedException.class)
public CommonResult AccessDeniedException(HttpServletRequest request, AccessDeniedException e) {
        return responseService.getFailResult(Integer.valueOf(getMessage(&quot;accessDenied.code&quot;)), getMessage(&quot;accessDenied.msg&quot;));
}

선생님 마지막 ExceptionAdvice 두메서드는 protected 타입이 아니고 public 타입인게 맞는건가요?]]></description>
			<content:encoded><![CDATA[<p>@ExceptionHandler(CAuthenticationEntryPointException.class)<br />
public CommonResult authenticationEntryPointException(HttpServletRequest request, CAuthenticationEntryPointException e) {<br />
        return responseService.getFailResult(Integer.valueOf(getMessage(&#8220;entryPointException.code&#8221;)), getMessage(&#8220;entryPointException.msg&#8221;));<br />
}</p>
<p>@ExceptionHandler(AccessDeniedException.class)<br />
public CommonResult AccessDeniedException(HttpServletRequest request, AccessDeniedException e) {<br />
        return responseService.getFailResult(Integer.valueOf(getMessage(&#8220;accessDenied.code&#8221;)), getMessage(&#8220;accessDenied.msg&#8221;));<br />
}</p>
<p>선생님 마지막 ExceptionAdvice 두메서드는 protected 타입이 아니고 public 타입인게 맞는건가요?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: happydaddy		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12698</link>

		<dc:creator><![CDATA[happydaddy]]></dc:creator>
		<pubDate>Tue, 06 Apr 2021 00:37:01 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12698</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12697&quot;&gt;돈술사&lt;/a&gt;.

안녕하세요. 
다시 답변 주신 내용을 보면 AccesToken과 RefreshToken을 사용하는것으로 보아 Oauth와 비슷한 형태의 인증을 구현하시는거 같습니다.
보안을 위해  매번 새로운 accessToken을 발급시키는 과정을 거치는 것은 DB부하를 일으킬 수 밖에 없는 구조인거 같습니다. 이 구조를 가지고 가야한다면
endpoint단에서 db 조회하는 부분을  redis로 캐싱하는게 좋을거 같습니다. 토큰 발급받을때는 유저정보를 조회할것이므로 유저정보를 캐시해 두면 될것이고
토큰으로 리소스를 요청하는 부분에서는  accessToken의 진위여부를 위해 DB조회가 필요할태니 해당 부분을 캐싱하는게 좋을거 같습니다. 만약 JWT를 이용한다면 회원 정보를 토큰안에 심을수 있으므로 DB조회 횟수를 accessToken에 비해서는 줄일 수 있을거 같습니다. 
제가 포스팅한 내용은 단순히 JWT를 발급하고 먄료시간을 크게두고 사용하는것이라 별다른 DB 부하는 없을것입니다. 다만 JWT 세팅시 expire시간을 세팅한다해도  토큰의 특성상 서버에서 직접 만료시킬 방법이 없습니다. 특정회원이 단 한개의 토큰만 가지도록 맨 마지막 발행한 토큰만 저장하고 있다가 비교하는 방식을 사용하던지, 작성자 분처럼 매번 새로운 토큰을 발행하는 방법으로 유효성을 검증하는 방법을 사용해야 할거 같습니다. 그리고 oauth에서도 일반 bearer토큰 발행 이외에 jwt로도 발행가능한 부분이 있으니 spring oauth를 검색해서 찾아보시면 도움이 될거라 생각합니다.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12697">돈술사</a>.</p>
<p>안녕하세요.<br />
다시 답변 주신 내용을 보면 AccesToken과 RefreshToken을 사용하는것으로 보아 Oauth와 비슷한 형태의 인증을 구현하시는거 같습니다.<br />
보안을 위해  매번 새로운 accessToken을 발급시키는 과정을 거치는 것은 DB부하를 일으킬 수 밖에 없는 구조인거 같습니다. 이 구조를 가지고 가야한다면<br />
endpoint단에서 db 조회하는 부분을  redis로 캐싱하는게 좋을거 같습니다. 토큰 발급받을때는 유저정보를 조회할것이므로 유저정보를 캐시해 두면 될것이고<br />
토큰으로 리소스를 요청하는 부분에서는  accessToken의 진위여부를 위해 DB조회가 필요할태니 해당 부분을 캐싱하는게 좋을거 같습니다. 만약 JWT를 이용한다면 회원 정보를 토큰안에 심을수 있으므로 DB조회 횟수를 accessToken에 비해서는 줄일 수 있을거 같습니다.<br />
제가 포스팅한 내용은 단순히 JWT를 발급하고 먄료시간을 크게두고 사용하는것이라 별다른 DB 부하는 없을것입니다. 다만 JWT 세팅시 expire시간을 세팅한다해도  토큰의 특성상 서버에서 직접 만료시킬 방법이 없습니다. 특정회원이 단 한개의 토큰만 가지도록 맨 마지막 발행한 토큰만 저장하고 있다가 비교하는 방식을 사용하던지, 작성자 분처럼 매번 새로운 토큰을 발행하는 방법으로 유효성을 검증하는 방법을 사용해야 할거 같습니다. 그리고 oauth에서도 일반 bearer토큰 발행 이외에 jwt로도 발행가능한 부분이 있으니 spring oauth를 검색해서 찾아보시면 도움이 될거라 생각합니다.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: 돈술사		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12699</link>

		<dc:creator><![CDATA[돈술사]]></dc:creator>
		<pubDate>Mon, 05 Apr 2021 17:41:33 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12699</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12698&quot;&gt;happydaddy&lt;/a&gt;.

깊이있는 답변 주셔서 너무 감사합니다. 아직 완벽히 구현하기에는 힘든 실력이지만 선생님이 올려주신 포스팅 보면서 많은 도움이 되고 있습니다. 다시 한번 감사드립니다.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12698">happydaddy</a>.</p>
<p>깊이있는 답변 주셔서 너무 감사합니다. 아직 완벽히 구현하기에는 힘든 실력이지만 선생님이 올려주신 포스팅 보면서 많은 도움이 되고 있습니다. 다시 한번 감사드립니다.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: 돈술사		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12697</link>

		<dc:creator><![CDATA[돈술사]]></dc:creator>
		<pubDate>Mon, 05 Apr 2021 12:36:31 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12697</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12695&quot;&gt;happydaddy&lt;/a&gt;.

답변이 늦어 죄송합니다. 제가 초보라 질문 내용도 많이 부족합니다
xss와 csrf를 어느정도라도 대응하고자 access token 와 refresh token을 운용하려고 했습니다. 발행할 때 refresh는 httponly 쿠키로 주고 클라이언트는 페이지가 바뀌거나 리소스에 접속 할 때마다 계속 refresh를 통한 access token 인증을 시키려고 했는데 이 과정이 너무 들락날락 거리는것 같은데 DB에 무리를 주지는 않는가? 싶어서 in memory 타입인 redis를 이용해서 해결 해보려고 했습니다. 나중에 OAuth2.0으로 확장할 생각도 했었는데 너무 어려워서 포기하고 싶네요ㅠㅠ 아직도 JWT에 대한 이해도가 낮아서 질문도 맞게 했는지 모르겠습니다. 감사합니다.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12695">happydaddy</a>.</p>
<p>답변이 늦어 죄송합니다. 제가 초보라 질문 내용도 많이 부족합니다<br />
xss와 csrf를 어느정도라도 대응하고자 access token 와 refresh token을 운용하려고 했습니다. 발행할 때 refresh는 httponly 쿠키로 주고 클라이언트는 페이지가 바뀌거나 리소스에 접속 할 때마다 계속 refresh를 통한 access token 인증을 시키려고 했는데 이 과정이 너무 들락날락 거리는것 같은데 DB에 무리를 주지는 않는가? 싶어서 in memory 타입인 redis를 이용해서 해결 해보려고 했습니다. 나중에 OAuth2.0으로 확장할 생각도 했었는데 너무 어려워서 포기하고 싶네요ㅠㅠ 아직도 JWT에 대한 이해도가 낮아서 질문도 맞게 했는지 모르겠습니다. 감사합니다.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: happydaddy		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12695</link>

		<dc:creator><![CDATA[happydaddy]]></dc:creator>
		<pubDate>Sun, 04 Apr 2021 00:11:57 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12695</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12694&quot;&gt;돈술사&lt;/a&gt;.

안녕하세요. 돈술사님
질문해 주신것에 대한 답을 드리기엔 질문이 모호합니다. 좀더 추가 설명이 필요할거 같습니다.

선생님 코드를 redis와 연동하여 인증처리하고 앱이나 웹에서도 사용가능 하게 만들어 봐야겠다는 결론
=&#062;&#062; 제 코드를 redis와 연동해서 인증처리해야 하는 이유가 뭔가요?
어디를 어떻게 바꿔서 redis의 시너지 효과를 볼 수 있을지?
=&#062;&#062; 어떤 시너지 효과를 원하시는 건가요?

돈술사님이 어떤 서비스를 준비하고 있고 해당 api서버를 만드는데 제 코드가 참고가 되고 있다는 건 알겠습니다. 그런데 그 과정에서 뭔가 더 필요한 기능이나 개선해야 할 부분이 있는데  코드 상 어떤 부분을 고쳐야 할지 모르겠다 라는 질문이 있어야 하는데 그 부분이 빠져 있어서 답변 드리기가 어려울거 같습니다. 
좀 더 구체적으로 설명해 주시면 다시 답변 드릴 수 있을거 같습니다.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12694">돈술사</a>.</p>
<p>안녕하세요. 돈술사님<br />
질문해 주신것에 대한 답을 드리기엔 질문이 모호합니다. 좀더 추가 설명이 필요할거 같습니다.</p>
<p>선생님 코드를 redis와 연동하여 인증처리하고 앱이나 웹에서도 사용가능 하게 만들어 봐야겠다는 결론<br />
=&gt;&gt; 제 코드를 redis와 연동해서 인증처리해야 하는 이유가 뭔가요?<br />
어디를 어떻게 바꿔서 redis의 시너지 효과를 볼 수 있을지?<br />
=&gt;&gt; 어떤 시너지 효과를 원하시는 건가요?</p>
<p>돈술사님이 어떤 서비스를 준비하고 있고 해당 api서버를 만드는데 제 코드가 참고가 되고 있다는 건 알겠습니다. 그런데 그 과정에서 뭔가 더 필요한 기능이나 개선해야 할 부분이 있는데  코드 상 어떤 부분을 고쳐야 할지 모르겠다 라는 질문이 있어야 하는데 그 부분이 빠져 있어서 답변 드리기가 어려울거 같습니다.<br />
좀 더 구체적으로 설명해 주시면 다시 답변 드릴 수 있을거 같습니다.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: 돈술사		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12694</link>

		<dc:creator><![CDATA[돈술사]]></dc:creator>
		<pubDate>Sat, 03 Apr 2021 00:28:58 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12694</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12682&quot;&gt;happydaddy&lt;/a&gt;.

안녕하세요 인증처리 때문에 골머리를 썩이다가
조언좀 구하고자 결국 댓글을 남깁니다.
집에 있는 남는컴을 이용해 실제 서비스를 할 목적으로 보안상에 문제도 발생하지 않게 해야하고 성능도 챙겨야하는 상황인지라 이것저것 찾던중
DB나 세션으로 주고 받는 것은 서버에 부담을 준다는 말을 듣고
귀가 얇아져서 또 이것저것 생각해보면서 구글링하다가 선생님 코드를 redis와 연동하여 인증처리하고 앱이나 웹에서도 사용가능 하게 만들어 봐야겠다는 결론에 도달했습니다. 그런데 어디를 어떻게 바꿔서 redis의 시너지 효과를 볼 수 있을지 잘 모르겠습니다.ㄷㄷ
이 부분 조언좀 주시면 안될까요?
선생님 코드가 너무 체계적이고 배울점이 많아 스스로 만들던 프로젝트 갈아엎고
보면서 10일째 밤낮으로 하나하나 손으로 타이핑 해가며 적용하고 있습니다.
교과서처럼 하나하나 도움 주셔서 너무 감사합니다.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12682">happydaddy</a>.</p>
<p>안녕하세요 인증처리 때문에 골머리를 썩이다가<br />
조언좀 구하고자 결국 댓글을 남깁니다.<br />
집에 있는 남는컴을 이용해 실제 서비스를 할 목적으로 보안상에 문제도 발생하지 않게 해야하고 성능도 챙겨야하는 상황인지라 이것저것 찾던중<br />
DB나 세션으로 주고 받는 것은 서버에 부담을 준다는 말을 듣고<br />
귀가 얇아져서 또 이것저것 생각해보면서 구글링하다가 선생님 코드를 redis와 연동하여 인증처리하고 앱이나 웹에서도 사용가능 하게 만들어 봐야겠다는 결론에 도달했습니다. 그런데 어디를 어떻게 바꿔서 redis의 시너지 효과를 볼 수 있을지 잘 모르겠습니다.ㄷㄷ<br />
이 부분 조언좀 주시면 안될까요?<br />
선생님 코드가 너무 체계적이고 배울점이 많아 스스로 만들던 프로젝트 갈아엎고<br />
보면서 10일째 밤낮으로 하나하나 손으로 타이핑 해가며 적용하고 있습니다.<br />
교과서처럼 하나하나 도움 주셔서 너무 감사합니다.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: happydaddy		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12682</link>

		<dc:creator><![CDATA[happydaddy]]></dc:creator>
		<pubDate>Fri, 12 Mar 2021 03:11:52 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12682</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12681&quot;&gt;남기석&lt;/a&gt;.

안녕하세요. 댓글을 제가 늦게 봤네요. 죄송합니다.
프론트와 연동 시키려면 프론트에서 맨처음에 로그인 api를 호출해서 token을 발급받아 로컬 어딘가에 저장하고 있어야 합니다. (ex. cookie, session, local storage등...)
그리고 프론트에서는 해당 token을 실어서 요청하고자 하는 api를 호출하면 됩니다. 만약 로그아웃이 발생하면 보관하고 있던 토큰을 삭제하면 됩니다.
제 블로그의 또다른 글에 보면 angular front framework와 연동한 부분이 있습니다. 여기서는 local storage에 저장해서 처리했습니다.
http://3.36.120.4/post/6433/spring-rest-api-angular-framework-signin-siginup
=&gt;&gt; localstorage.setItem(~~~~)
그런데 이러한 방식은 보안상 문제가 있으니 실 서비스에서는 https(ssl)통신을 이용해서 서비스가 진행 되야 합니다.

답변이 되었는지 모르겠네요.
즐거운 불금 되세요~!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12681">남기석</a>.</p>
<p>안녕하세요. 댓글을 제가 늦게 봤네요. 죄송합니다.<br />
프론트와 연동 시키려면 프론트에서 맨처음에 로그인 api를 호출해서 token을 발급받아 로컬 어딘가에 저장하고 있어야 합니다. (ex. cookie, session, local storage등&#8230;)<br />
그리고 프론트에서는 해당 token을 실어서 요청하고자 하는 api를 호출하면 됩니다. 만약 로그아웃이 발생하면 보관하고 있던 토큰을 삭제하면 됩니다.<br />
제 블로그의 또다른 글에 보면 angular front framework와 연동한 부분이 있습니다. 여기서는 local storage에 저장해서 처리했습니다.<br />
<a href="http://3.36.120.4/post/6433/spring-rest-api-angular-framework-signin-siginup" rel="nofollow ugc">http://3.36.120.4/post/6433/spring-rest-api-angular-framework-signin-siginup</a><br />
=>> localstorage.setItem(~~~~)<br />
그런데 이러한 방식은 보안상 문제가 있으니 실 서비스에서는 https(ssl)통신을 이용해서 서비스가 진행 되야 합니다.</p>
<p>답변이 되었는지 모르겠네요.<br />
즐거운 불금 되세요~!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: 남기석		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12681</link>

		<dc:creator><![CDATA[남기석]]></dc:creator>
		<pubDate>Thu, 11 Mar 2021 00:34:40 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12681</guid>

					<description><![CDATA[안녕하세요. 
우선 덕분에 많이 배웠습니다!! 감사합니다
한 가지 여쭤보고 싶은게 있어서 글을 남깁니다!.
인증 정보가 필요한 요청의 경우 매 요청마다 헤더에 토큰값을 포함한 채 요청을 보내야한다고 생각했습니다. postman을 이용할 땐 제가 헤더에 토큰값을 넣은채로 요청을 보냈지만 만약 프론트와 함께 서비스를 만드는 경우에는 누가!,어떻게! 헤더에 토큰값을 넣어주는 것인지 여쭤보고 싶습니다!!]]></description>
			<content:encoded><![CDATA[<p>안녕하세요.<br />
우선 덕분에 많이 배웠습니다!! 감사합니다<br />
한 가지 여쭤보고 싶은게 있어서 글을 남깁니다!.<br />
인증 정보가 필요한 요청의 경우 매 요청마다 헤더에 토큰값을 포함한 채 요청을 보내야한다고 생각했습니다. postman을 이용할 땐 제가 헤더에 토큰값을 넣은채로 요청을 보냈지만 만약 프론트와 함께 서비스를 만드는 경우에는 누가!,어떻게! 헤더에 토큰값을 넣어주는 것인지 여쭤보고 싶습니다!!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: happydaddy		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12669</link>

		<dc:creator><![CDATA[happydaddy]]></dc:creator>
		<pubDate>Sat, 20 Feb 2021 02:46:22 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12669</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12668&quot;&gt;vividswan&lt;/a&gt;.

안녕하세요~ 로그아웃에 대한건 따로 작성한 글이 없습니다.
로그아웃이란건 생각해보면 간단한 것이라... 따로 작성하지 않았습니다.
로그인 중이라면 클라쪽에서는 아마도 로컬 저장소에 토큰을 저장하고 있을텐데요. 
해당 토큰을 클라쪽에서 삭제해 버리면 더 이상 인증이 필요한 api를 호출하지 못하게 되므로 로그아웃이나 마찬가지입니다.
rest api 자체가 stateless api로서 서버에서 상태를 따로 저장하지 않습니다. 인증된 토큰을 클라에서 가지고 있는게 로그인이라고 보시면 됩니다.
아 그런데 그래도 서버쪽에서 확실하게 로그아웃을 처리하고 싶다...하면
로그인 요청시 jwt토큰 발행할때 마지막에 발급한 토큰을 서버에서 갱신하면서 저장하고 있으면 됩니다. 
클라쪽에서 보내온 토큰이 서버에 마지막 저장된 토큰이랑 맞지 않던가, 또는 서버에 저장된 토큰이 없으면 로그아웃 또는 만료된 토큰으로 간주하고 
재 로그인 요청을 하도록 처리하면 됩니다.
명시적 로그아웃 처리도 서버에 저장된 마지막 토큰을 지워버리면 됩니다.

적당한 답변이 되었는지 모르겠네요~! 즐거운 주말 되시기 바랍니다.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12668">vividswan</a>.</p>
<p>안녕하세요~ 로그아웃에 대한건 따로 작성한 글이 없습니다.<br />
로그아웃이란건 생각해보면 간단한 것이라&#8230; 따로 작성하지 않았습니다.<br />
로그인 중이라면 클라쪽에서는 아마도 로컬 저장소에 토큰을 저장하고 있을텐데요.<br />
해당 토큰을 클라쪽에서 삭제해 버리면 더 이상 인증이 필요한 api를 호출하지 못하게 되므로 로그아웃이나 마찬가지입니다.<br />
rest api 자체가 stateless api로서 서버에서 상태를 따로 저장하지 않습니다. 인증된 토큰을 클라에서 가지고 있는게 로그인이라고 보시면 됩니다.<br />
아 그런데 그래도 서버쪽에서 확실하게 로그아웃을 처리하고 싶다&#8230;하면<br />
로그인 요청시 jwt토큰 발행할때 마지막에 발급한 토큰을 서버에서 갱신하면서 저장하고 있으면 됩니다.<br />
클라쪽에서 보내온 토큰이 서버에 마지막 저장된 토큰이랑 맞지 않던가, 또는 서버에 저장된 토큰이 없으면 로그아웃 또는 만료된 토큰으로 간주하고<br />
재 로그인 요청을 하도록 처리하면 됩니다.<br />
명시적 로그아웃 처리도 서버에 저장된 마지막 토큰을 지워버리면 됩니다.</p>
<p>적당한 답변이 되었는지 모르겠네요~! 즐거운 주말 되시기 바랍니다.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: vividswan		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12668</link>

		<dc:creator><![CDATA[vividswan]]></dc:creator>
		<pubDate>Fri, 19 Feb 2021 15:13:51 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12668</guid>

					<description><![CDATA[안녕하세요! 혹시 로그아웃에 대한건 따로 쓰신 글이 없으실까요?? 항상 감사히 보고 있습니다!]]></description>
			<content:encoded><![CDATA[<p>안녕하세요! 혹시 로그아웃에 대한건 따로 쓰신 글이 없으실까요?? 항상 감사히 보고 있습니다!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: vividswan		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12666</link>

		<dc:creator><![CDATA[vividswan]]></dc:creator>
		<pubDate>Sat, 13 Feb 2021 12:59:40 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12666</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12665&quot;&gt;happydaddy&lt;/a&gt;.

이해가 됐습니다. 바쁘실텐데 상세하게 답변해주셔서 감사하고 블로그에 정성스럽게 올려주신 글 열심히 감사히 보고 있습니다!!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12665">happydaddy</a>.</p>
<p>이해가 됐습니다. 바쁘실텐데 상세하게 답변해주셔서 감사하고 블로그에 정성스럽게 올려주신 글 열심히 감사히 보고 있습니다!!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: happydaddy		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12665</link>

		<dc:creator><![CDATA[happydaddy]]></dc:creator>
		<pubDate>Sat, 13 Feb 2021 09:01:50 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12665</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12664&quot;&gt;vividswan&lt;/a&gt;.

안녕하세요.댓글스팸이 많아서 승인해야 보이기 때문입니다.  댓글은 잘 등록 되었습니다.  질문에 대한 답변을 드리면 쓰고 싶어도 못쓴다 입니다.  csrf는 서버에서 세션 기반으로 토큰을 발행해서 요청시 클라의 세션과 토큰이 일치하는지 확인하여 요청을 유효한지 확인하는 방법입니다. 그러나 rest api의 경우 stateless 라고 해서 상태가 존재하지 않는 구조를 지니고 있습니다. 즉 세션과 무관하게 작동됩니다. 세션을 사용하지 않고 JWT 토큰을 활용하여 진행하고 REST API를 만드는 작업이기때문에 csrf 사용은 disable 처리합니다. 만약 세션인증을 사용하고 싶으면 rest api가 서버에 요청할때마다 동일한 세션을 가지게 구조를 잡아야 하는데 그게 어렵기도 하고  rest의 의도에도 맞지 않습니다]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12664">vividswan</a>.</p>
<p>안녕하세요.댓글스팸이 많아서 승인해야 보이기 때문입니다.  댓글은 잘 등록 되었습니다.  질문에 대한 답변을 드리면 쓰고 싶어도 못쓴다 입니다.  csrf는 서버에서 세션 기반으로 토큰을 발행해서 요청시 클라의 세션과 토큰이 일치하는지 확인하여 요청을 유효한지 확인하는 방법입니다. 그러나 rest api의 경우 stateless 라고 해서 상태가 존재하지 않는 구조를 지니고 있습니다. 즉 세션과 무관하게 작동됩니다. 세션을 사용하지 않고 JWT 토큰을 활용하여 진행하고 REST API를 만드는 작업이기때문에 csrf 사용은 disable 처리합니다. 만약 세션인증을 사용하고 싶으면 rest api가 서버에 요청할때마다 동일한 세션을 가지게 구조를 잡아야 하는데 그게 어렵기도 하고  rest의 의도에도 맞지 않습니다</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: vividswan		</title>
		<link>https://www.daddyprogrammer.org/post/636/springboot2-springsecurity-authentication-authorization/#comment-12664</link>

		<dc:creator><![CDATA[vividswan]]></dc:creator>
		<pubDate>Sat, 13 Feb 2021 04:04:31 +0000</pubDate>
		<guid isPermaLink="false">http://3.36.120.4/?p=636#comment-12664</guid>

					<description><![CDATA[댓글을 작성했는데 작성이 안된 것 같아서 다시 올립니다 ㅠ 왜 rest api로 설계하면 csrf.disable() 옵션을 설정해도 되는걸까요? 글 잘 읽고 있습니다. 감사합니다!]]></description>
			<content:encoded><![CDATA[<p>댓글을 작성했는데 작성이 안된 것 같아서 다시 올립니다 ㅠ 왜 rest api로 설계하면 csrf.disable() 옵션을 설정해도 되는걸까요? 글 잘 읽고 있습니다. 감사합니다!</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
