All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.itcb.common.client.security.provider.SecurityContextHolderCredentialsProvider Maven / Gradle / Ivy

Go to download

This module is the common client module for calling webservices (server module). It defines all generic treatements that allows calling webservices

There is a newer version: 0.7.3
Show newest version
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) new ArrayList () );
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy