use of org.springframework.web.context.request.ServletRequestAttributes in project esup-papercut by EsupPortail.
the class ContextUserDetails method getAuthorities.
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes != null && requestAttributes instanceof ServletRequestAttributes) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
String papercutContext = WebUtils.getContext(request);
if (contextAuthorities.get(papercutContext) != null && !contextAuthorities.get(papercutContext).isEmpty()) {
return contextAuthorities.get(papercutContext);
}
}
return defaultAuthorities;
}
use of org.springframework.web.context.request.ServletRequestAttributes in project esup-papercut by EsupPortail.
the class ContextUserDetails method getUsername.
@Override
public String getUsername() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes != null && requestAttributes instanceof ServletRequestAttributes) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
String papercutContext = WebUtils.getContext(request);
if (contextUids.get(papercutContext) != null && !contextUids.get(papercutContext).isEmpty()) {
return contextUids.get(papercutContext);
}
}
return username;
}
use of org.springframework.web.context.request.ServletRequestAttributes in project esup-papercut by EsupPortail.
the class ContextUserDetails method getEmail.
public String getEmail() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes != null && requestAttributes instanceof ServletRequestAttributes) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
String papercutContext = WebUtils.getContext(request);
if (contextEmails.get(papercutContext) != null && !contextEmails.get(papercutContext).isEmpty()) {
return contextEmails.get(papercutContext);
}
}
return null;
}
use of org.springframework.web.context.request.ServletRequestAttributes in project plumdo-work by wengwh.
the class AuthCheckAspect method doAuth.
@Around("webRequestAuth()&& webRequestNotAuth()")
public Object doAuth(ProceedingJoinPoint pjp) throws Throwable {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
String userId = null;
String token = request.getHeader("Token");
if (ObjectUtils.isEmpty(token)) {
token = request.getParameter("token");
}
logger.info("token:" + token);
if (ObjectUtils.isEmpty(token)) {
exceptionFactory.throwAuthError(CoreConstant.HEADER_TOKEN_NOT_FOUND);
}
if (!token.startsWith("Bearer ")) {
exceptionFactory.throwAuthError(CoreConstant.HEADER_TOKEN_ILLEGAL);
}
try {
Claims claims = Jwts.parser().setSigningKey(CoreConstant.JWT_SECRET).parseClaimsJws(token.substring(7)).getBody();
userId = claims.getId();
if (ObjectUtils.isEmpty(userId)) {
exceptionFactory.throwAuthError(CoreConstant.TOKEN_USER_ID_NOT_FOUND);
}
Date expiration = claims.getExpiration();
if (expiration != null && expiration.before(new Date())) {
exceptionFactory.throwAuthError(CoreConstant.TOKEN_EXPIRE_OUT);
}
} catch (Exception e) {
exceptionFactory.throwAuthError(CoreConstant.TOKEN_AUTH_CHECK_ERROR);
}
try {
Authentication.setToken(token);
Authentication.setUserId(userId);
return pjp.proceed(pjp.getArgs());
} finally {
Authentication.clear();
}
}
use of org.springframework.web.context.request.ServletRequestAttributes in project leopard by tanhaichao.
the class ImageDfsServiceImpl method isWeb.
/**
* 是否web环境
*
* @return
*/
protected boolean isWeb() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes == null) {
return false;
}
HttpServletRequest request = attributes.getRequest();
if (request == null) {
return false;
}
return true;
}
Aggregations