use of org.springframework.security.core.userdetails.UserDetails in project head by mifos.
the class AuthenticationAuthorizationServiceFacadeImpl method reloadUserDetailsForSecurityContext.
@Override
public void reloadUserDetailsForSecurityContext(String username) {
UserDetails userSecurityDetails = loadUserByUsername(username);
MifosUser reloadedUserDetails = (MifosUser) userSecurityDetails;
SecurityContext securityContext = SecurityContextHolder.getContext();
if (securityContext == null) {
securityContext = new SecurityContextImpl();
SecurityContextHolder.setContext(securityContext);
}
Authentication authentication = new UsernamePasswordAuthenticationToken(reloadedUserDetails, reloadedUserDetails, reloadedUserDetails.getAuthorities());
securityContext.setAuthentication(authentication);
}
use of org.springframework.security.core.userdetails.UserDetails in project uPortal by Jasig.
the class PortalPersonUserDetailsTest method testUserDetails.
@Test
public void testUserDetails() {
UserDetails details = new PortalPersonUserDetails(person);
assertEquals("testuser", details.getUsername());
}
use of org.springframework.security.core.userdetails.UserDetails in project Settler by EmhyrVarEmreis.
the class XAuthTokenFilter method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
try {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
String authToken = httpServletRequest.getHeader(XAUTH_TOKEN_HEADER_NAME);
if (!StringUtils.hasText(authToken) && httpServletRequest.getMethod().equals("POST"))
authToken = httpServletRequest.getParameter(XAUTH_TOKEN_HEADER_NAME);
if (StringUtils.hasText(authToken)) {
String username = this.tokenProvider.getUserNameFromToken(authToken);
UserDetails details = this.detailsService.loadUserByUsername(username);
if (tokenProvider.validateToken(authToken, details)) {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(details, details.getPassword(), details.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(token);
httpServletResponse.addHeader(XAUTH_TOKEN_HEADER_NAME, tokenProvider.createToken(details));
}
}
filterChain.doFilter(servletRequest, servletResponse);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.springframework.security.core.userdetails.UserDetails in project motan by weibocom.
the class UserController method getUser.
/**
* Retrieves the currently logged in user.
*
* @return A transfer containing the username and the roles.
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public UserTransfer getUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof AnonymousAuthenticationToken) {
throw new CustomException.UnauthorizedException();
}
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
return new UserTransfer(userDetails.getUsername(), createRoleMap(userDetails));
}
use of org.springframework.security.core.userdetails.UserDetails in project motan by weibocom.
the class AuthenticationTokenProcessingFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = getAsHttpRequest(request);
String authToken = extractAuthTokenFromRequest(httpServletRequest);
String username = TokenUtils.getUserNameFromToken(authToken);
if (username != null) {
UserDetails userDetails = userDetailsService.loadUserByUsername(username);
if (TokenUtils.validateToken(authToken, userDetails)) {
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest));
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
}
}
chain.doFilter(request, response);
}
Aggregations