Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TofuUserApprovalHandler: Refactor setAuthTime. #1501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.approval.UserApprovalHandler;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

Expand Down Expand Up @@ -238,24 +239,30 @@ public AuthorizationRequest updateAfterApproval(AuthorizationRequest authorizati
return authorizationRequest;
}

private Date getAuthTime(AuthorizationRequest authorizationRequest) {
RequestAttributes attr = RequestContextHolder.currentRequestAttributes();
if(attr instanceof ServletRequestAttributes) {
ServletRequestAttributes sattr = (ServletRequestAttributes) attr;
HttpSession session = sattr.getRequest().getSession(false);
if (session != null) {
Date authTime = (Date) session.getAttribute(AuthenticationTimeStamper.AUTH_TIMESTAMP);
return authTime;
}
}
return null;
}

/**
* Get the auth time out of the current session and add it to the
* auth request in the extensions map.
*
* @param authorizationRequest
*/
private void setAuthTime(AuthorizationRequest authorizationRequest) {
// Get the session auth time, if we have it, and store it in the request
ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
if (attr != null) {
HttpSession session = attr.getRequest().getSession();
if (session != null) {
Date authTime = (Date) session.getAttribute(AuthenticationTimeStamper.AUTH_TIMESTAMP);
if (authTime != null) {
String authTimeString = Long.toString(authTime.getTime());
authorizationRequest.getExtensions().put(AuthenticationTimeStamper.AUTH_TIMESTAMP, authTimeString);
}
}
Date authTime = getAuthTime(authorizationRequest);
if (authTime != null) {
String authTimeString = Long.toString(authTime.getTime());
authorizationRequest.getExtensions().put(AuthenticationTimeStamper.AUTH_TIMESTAMP, authTimeString);
}
}

Expand Down