public UaaAuthenticationDetails(HttpServletRequest request, String clientId) { WebAuthenticationDetails webAuthenticationDetails = new WebAuthenticationDetails(request); this.origin = webAuthenticationDetails.getRemoteAddress(); this.sessionId = webAuthenticationDetails.getSessionId(); if (clientId == null) { this.clientId = request.getParameter("client_id"); if(!StringUtils.hasText(this.clientId)) { String authHeader = request.getHeader("Authorization"); if(StringUtils.hasText(authHeader) && authHeader.startsWith("Basic ")) { String decodedCredentials = new String(Base64.decode(authHeader.substring("Basic ".length()))); String[] split = decodedCredentials.split(":"); if (split == null || split.length == 0) throw new BadCredentialsException("Invalid basic authentication token"); this.clientId = split[0]; } } } else { this.clientId = clientId; } this.addNew = Boolean.parseBoolean(request.getParameter(ADD_NEW)); this.loginHint = UaaLoginHint.parseRequestParameter(request.getParameter("login_hint")); this.parameterMap = request.getParameterMap(); }
/** * @return Currently logged in user's session id. */ protected String getLoggedInUserSessionId() { return ((WebAuthenticationDetails)SecurityContextHolder.getContext().getAuthentication().getDetails()).getSessionId(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()).append(": "); sb.append("RemoteIpAddress: ").append(this.getRemoteAddress()).append("; "); sb.append("SessionId: ").append(this.getSessionId()); return sb.toString(); } }
@Override public boolean equals(Object obj) { if (obj instanceof WebAuthenticationDetails) { WebAuthenticationDetails rhs = (WebAuthenticationDetails) obj; if ((remoteAddress == null) && (rhs.getRemoteAddress() != null)) { return false; } if ((remoteAddress != null) && (rhs.getRemoteAddress() == null)) { return false; } if (remoteAddress != null) { if (!remoteAddress.equals(rhs.getRemoteAddress())) { return false; } } if ((sessionId == null) && (rhs.getSessionId() != null)) { return false; } if ((sessionId != null) && (rhs.getSessionId() == null)) { return false; } if (sessionId != null) { if (!sessionId.equals(rhs.getSessionId())) { return false; } } return true; } return false; }
@Override public void onApplicationEvent(AbstractSubProtocolEvent ev) { if(ev instanceof SessionSubscribeEvent) { sendHistoryToNewSubscriber(ev); } else if(ev instanceof SessionConnectEvent || ev instanceof SessionDisconnectEvent) { Authentication user = (Authentication)ev.getUser(); Object details = user.getDetails(); String sessionId = null; String address = null; if(details instanceof WebAuthenticationDetails) { WebAuthenticationDetails wad = (WebAuthenticationDetails) details; address = wad.getRemoteAddress(); sessionId = wad.getSessionId(); } if(ev instanceof SessionDisconnectEvent) { log.info("WebSocket user \"{}\" was disconnected from {} with HTTP session: {}", user.getName(), address, sessionId); } else { log.info("WebSocket user \"{}\" was connected from {} with HTTP session: {}", user.getName(), address, sessionId); } } }
Object authenticationDetails = userAuthentication.getDetails(); if (authenticationDetails instanceof WebAuthenticationDetails) { detail.setSessionId(((WebAuthenticationDetails) authenticationDetails).getSessionId());