net.sf.itcb.common.client.security.provider.SecurityContextHolderCredentialsProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of itcb-common-client Show documentation
Show all versions of itcb-common-client Show documentation
This module is the common client module for calling webservices (server module). It defines all generic treatements that allows calling webservices
package net.sf.itcb.common.client.security.provider;
import java.util.ArrayList;
import java.util.Collection;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
/**
* This class allows to retrieve the logged in user by retriving it in the Spring SecurityContextHolder {@link org.springframework.security.core.context.SecurityContextHolder}.
* It retrieves it by calling SecurityContextHolder.getContext().getAuthentication().getCredentials().
*
* @author Pierre Le Roux
*/
public class SecurityContextHolderCredentialsProvider implements
SecurementCredentialsProvider {
@Override
public UserDetails getUserCredentials() throws Throwable {
if(SecurityContextHolder.getContext()== null ||
SecurityContextHolder.getContext().getAuthentication() == null ||
SecurityContextHolder.getContext().getAuthentication().getPrincipal() == null ||
SecurityContextHolder.getContext().getAuthentication().getCredentials() == null) {
return null;
}
return new User((String)SecurityContextHolder.getContext().getAuthentication().getPrincipal(), (String)SecurityContextHolder.getContext().getAuthentication().getCredentials(), true, true, true, true, (Collection extends GrantedAuthority>) new ArrayList () );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy