Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
session을 사용 하지 않는 웹애플리케이션 개발
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
코바  
View profile   Translate to Translated (View Original)
 More options Feb 9, 2:37 am
From: 코바 <sbc...@gmail.com>
Date: Wed, 8 Feb 2012 23:37:53 -0800 (PST)
Local: Thurs, Feb 9 2012 2:37 am
Subject: session을 사용 하지 않는 웹애플리케이션 개발
안녕하십니까

유령 회원 코바입니다.

다른 아니라 모바일 웹을 개발 하고 있는데, 이번에 고객으로 부터 저런 요청을 받았습니다

oauth를 사용 하여 시스템을 개발 하는데, access토큰만 이용 해서 세션을 사용 하지 않고 개발 해달라고 하는군요

사실 스프링 시큐리티 사용 해서 oauth 프로바인더와 연동해서 로그인하여 사용 하고 있었는데

많이 개발된 시점에서 바꿔 달라고 해서 당황 스럽네요

여러곳을 찾아보니

spring security에서

SecurityContextPersistenceFilter
SecurityContextHolder
HttpSessionSecurityContextRepository
이 클래스를 참조하여
구현 하면된다고 하더군요

그런데 막상 해볼라고 하니 감이 안잡히네요

혹시 이런부분을 구현 해보신분이 계신지 아님 좋은 방법인 존재 하는지

가르쳐 주시면 감사하겠습니다.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
고종봉  
View profile   Translate to Translated (View Original)
 More options Feb 9, 8:46 am
From: 고종봉 <mercujj...@gmail.com>
Date: Thu, 9 Feb 2012 22:46:01 +0900
Local: Thurs, Feb 9 2012 8:46 am
Subject: Re: [KSUG] session을 사용 하지 않는 웹애플리케이션 개발

[image: image.png]

그림을 보시면...

왼쪽에 Security Filter Chain 중 SecurityContextPersistenceFilter에서 요청 시 인증정보를
복구하는 역할을 하는데요.

http://static.springsource.org/spring-security/site/docs/3.0.x/apidoc...

를 보시면,, SecurityContextRepository로부터 SecurityContextHolder를 얻는데요.

이 때 SecurityContextRepository는 구현체가 아니라 자바 인터페이스에요.

기본 구현체로 HttpSessionSecurityContextRepository를 사용하고 있는데,

http://static.springsource.org/spring-security/site/docs/3.0.x/apidoc...

얘 대신 CookieBasedSecurityContextRepository implements
SecurityContextRepository 클래스를 만드시면 되요.

http://static.springsource.org/spring-security/site/docs/3.0.x/apidoc...

SecurityContextRepository 인터페이스에 정의된 메서드들 다 구현해주시면 되구요.

메서드 구현은 HttpSessionSecurityContextRepository 소스를 보고 수정해서 사용하심 되요.

자세한 내용은 저도 소스를 안봐서. ^^;

소스와 API 문서, 레퍼런스만 잘 활용해도 왠만큼은 해결하실 수 있으실 거에요. (영어에 거부감만 없으시다면..ㅎ)

2012년 2월 9일 오후 4:37, 코바 <sbc...@gmail.com>님의 말:

  image.png
255K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
선영욱  
View profile   Translate to Translated (View Original)
 More options Feb 9, 6:05 pm
From: 선영욱 <twinmoon2...@gmail.com>
Date: Fri, 10 Feb 2012 08:05:45 +0900
Local: Thurs, Feb 9 2012 6:05 pm
Subject: Re: [KSUG] session을 사용 하지 않는 웹애플리케이션 개발

와~맵이 정말 도움이 많이 되는 정보인거 같습니다.

감사합니다.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
이상용  
View profile   Translate to Translated (View Original)
 More options Feb 9, 7:30 pm
From: 이상용 <kr.goodwil...@gmail.com>
Date: Fri, 10 Feb 2012 09:30:08 +0900
Local: Thurs, Feb 9 2012 7:30 pm
Subject: Re: [KSUG] session을 사용 하지 않는 웹애플리케이션 개발

멋진 정보 감사합니다^^

오늘도 즐거운 하루 되시기를..^^

2012년 2월 10일 오전 8:05, 선영욱 <twinmoon2...@gmail.com>님의 말:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
박용권  
View profile   Translate to Translated (View Original)
 More options Feb 9, 7:52 pm
From: 박용권 <arawn...@gmail.com>
Date: Fri, 10 Feb 2012 09:52:15 +0900
Local: Thurs, Feb 9 2012 7:52 pm
Subject: Re: [KSUG] session을 사용 하지 않는 웹애플리케이션 개발

스프링 시큐리티는 필터 구조에 대해서 이해하고 사용하면 훨씬 유용하게 사용할 수 있는 녀석이죠 ^^;

좋은 그림입니다! +_+)b

2012년 2월 9일 오후 10:46, 고종봉 <mercujj...@gmail.com>님의 말:

  image.png
255K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
황용대  
View profile  
 More options Feb 9, 8:53 pm
From: 황용대 <sta...@gmail.com>
Date: Fri, 10 Feb 2012 10:53:51 +0900
Local: Thurs, Feb 9 2012 8:53 pm
Subject: Re: [KSUG] session을 사용 하지 않는 웹애플리케이션 개발
ξ Ű ؽ Ʈ 丮 ҽ ص帳 ϴ .

ť Ƽ ؽ Ʈ 丮 ε
http ؽ Ʈ 丮 ҽ ٰ Ű °

public class CookieSecurityContextRepository implements
SecurityContextRepository, InitializingBean {
public static final String SPRING_SECURITY_CONTEXT_KEY =
"SPRING_SECURITY_CONTEXT";

protected final Log logger = LogFactory.getLog(this.getClass());

private Class<? extends SecurityContext> securityContextClass = null;

private boolean disableUrlRewriting = false;
private String cookieName;
private String cookieKey;

private AuthenticationTrustResolver authenticationTrustResolver = new
AuthenticationTrustResolverImpl();

public SecurityContext loadContext(HttpRequestResponseHolder
requestResponseHolder) {
HttpServletRequest request = requestResponseHolder.getRequest();
HttpServletResponse response = requestResponseHolder.getResponse();

Authentication cookie = null;
try {
cookie = getAuthenticationFromCookie(request);

} catch (JsonParseException e) {
logger.error(e);
} catch (JsonMappingException e) {
logger.error(e);
} catch (IOException e) {
logger.error(e);
}

if (cookie == null) {
if (logger.isDebugEnabled()) {
logger.debug("No SecurityContext was available A new one will be created.");
}

return generateNewContext();

}

SecurityContext context = SecurityContextHolder.getContext();
context.setAuthentication(cookie);

requestResponseHolder.setResponse(new
SaveToCookieResponseWrapper(response, context.hashCode()));

return context;

}

private Authentication getAuthenticationFromCookie(HttpServletRequest
request) throws JsonParseException, JsonMappingException, IOException {
logger.debug("getAuthenticationFromCookie");
if (request == null) {
if (logger.isDebugEnabled()) {
logger.debug("No cookie currently exists");

}
return null;
}

Cookie cookie = CookieUtils.getCookieByName(request, cookieName);
if(cookie == null) {
if (logger.isDebugEnabled()) {
logger.debug("No token cookie currently exists");
}
return null;
}

String tokens = CookieUtils.decodeCookie(cookie.getValue(), cookieKey);

logger.debug("CookieName = "+ tokens);
ObjectMapper mapper = new ObjectMapper();
ActionUserDetails user = mapper.readValue(tokens, ActionUserDetails.class);

cookie = CookieUtils.getCookieByName(request, "sign");
if(cookie == null) {
if (logger.isDebugEnabled()) {
logger.debug("No signature cookie currently exists");

}
return null;
}

String credentials = CookieUtils.decodeCookie(cookie.getValue(), cookieKey);

if(credentials == null)
return null;

CookieAuthenticationToken newAuthentication = new
CookieAuthenticationToken(user, credentials, user.getAuthorities());
newAuthentication.setAuthenticated(true);
return newAuthentication;

}

public void saveContext(SecurityContext context, HttpServletRequest
request, HttpServletResponse response) {

}

public boolean containsContext(HttpServletRequest request) {
Cookie cookie = CookieUtils.getCookieByName(request, cookieName);

if (cookie == null) {
return false;

}

if (cookie.getValue().length() == 0) {
return false;

}

return true;

}

/**
* By default, calls {@link SecurityContextHolder#createEmptyContext()} to
* obtain a new context (there should be no context present in the holder
* when this method is called). Using this approach the context creation
* strategy is decided by the {@link SecurityContextHolderStrategy} in use.
* The default implementations will return a new
* <tt>SecurityContextImpl</tt>.
* <p>
* An alternative way of customizing the <tt>SecurityContext</tt>
* implementation is by setting the <tt>securityContextClass</tt> property.
* In this case, the method will attempt to invoke the no-args constructor
* on the supplied class instead and return the created instance.
*
* @return a new SecurityContext instance. Never null.
*/
SecurityContext generateNewContext() {
SecurityContext context = null;

if (securityContextClass == null) {
context = SecurityContextHolder.createEmptyContext();
return context;

}

try {
context = securityContextClass.newInstance();
} catch (Exception e) {

ReflectionUtils.handleReflectionException(e);

}
return context;
}

/**
* Allows the use of session identifiers in URLs to be disabled. Off by
* default.
*
* @param disableUrlRewriting
* set to <tt>true</tt> to disable URL encoding methods in the
* response wrapper and prevent the use of <tt>jsessionid</tt>
* parameters.
*/
public void setDisableUrlRewriting(boolean disableUrlRewriting) {
this.disableUrlRewriting = disableUrlRewriting;

}

public String getCookieName() {
return cookieName;

}

public void setCookieName(String cookieName) {
this.cookieName = cookieName;

}

public String getCookieKey() {
return cookieKey;

}

public void setCookieKey(String cookieKey) {
this.cookieKey = cookieKey;

}

// ~ Inner Classes
//
=========================================================================== =======================

final class SaveToCookieResponseWrapper extends
SaveContextOnUpdateOrErrorResponseWrapper {
private int contextHashBeforeChainExecution;

public SaveToCookieResponseWrapper(HttpServletResponse response, int
contextHashBeforeChainExecution) {
super(response, disableUrlRewriting);
this.contextHashBeforeChainExecution = contextHashBeforeChainExecution;

}

@Override
protected void saveContext(SecurityContext context) {
final Authentication authentication = context.getAuthentication();

// See SEC-776
if (authentication == null ||
authenticationTrustResolver.isAnonymous(authentication)) {
if (logger.isDebugEnabled()) {
logger.debug("SecurityContext is empty or anonymous - context will not
be stored.");

}
return;
}

// If HttpSession exists, store current SecurityContextHolder
// contents but only if the SecurityContext has actually changed
// (see JIRA SEC-37)
// We also check that the session contains the context, in case a
// new session has been created (SEC-1561)
if (context.hashCode() != contextHashBeforeChainExecution) {

}
}
}

@Override
public void afterPropertiesSet() throws Exception {
Assert.hasLength(cookieName, "Cookie name cannot be empty or null");
Assert.hasLength(cookieKey, "Cookie key cannot be empty or null");
}
}

2012 02 09 16:37, ڹ :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
코바  
View profile   Translate to Translated (View Original)
 More options Feb 11, 10:33 am
From: 코바 <sbc...@gmail.com>
Date: Sat, 11 Feb 2012 07:33:56 -0800 (PST)
Local: Sat, Feb 11 2012 10:33 am
Subject: Re: [KSUG] session을 사용 하지 않는 웹애플리케이션 개발

와 늦었지만 좋은 자료 감사합니다 !!! 역시 공부는 더 해야 할듯합니다 !


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
코바  
View profile   Translate to Translated (View Original)
 More options Feb 11, 10:34 am
From: 코바 <sbc...@gmail.com>
Date: Sat, 11 Feb 2012 07:34:34 -0800 (PST)
Local: Sat, Feb 11 2012 10:34 am
Subject: Re: [KSUG] session을 사용 하지 않는 웹애플리케이션 개발

헉 글자가 깨지긴 하지만 소스는 엄청나게 큰 도움이 될 것 같습니다 !!! 정말 감사합니다

역시 좋으신분 많으시네요


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »