View Javadoc
1   package fr.paris.lutece.plugins.mylutece.service;
2   
3   import java.util.Collection;
4   import java.util.HashSet;
5   import java.util.List;
6   import java.util.Set;
7   
8   import fr.paris.lutece.portal.service.security.LuteceUser;
9   import fr.paris.lutece.portal.service.spring.SpringContextService;
10  
11  
12  /**
13   * The Class MyluteceExternalRoleService.
14   */
15  public class MyluteceExternalRoleService implements IMyluteceExternalRoleService{
16  
17  	
18       /** The Constant BEAN_MY_LUTECE_ROLE_SERVICE. */
19       private static final String BEAN_MY_LUTECE_ROLE_SERVICE = "mylutece.myLuteceExternalRoleService";
20  	 
21   	/** The singleton. */
22   	private static volatile IMyluteceExternalRoleService  _singleton;
23  	 
24  	 
25  	 
26  	 
27  	 /**
28   	 * Get the instance of the MyLuteceExternalIdentityService service.
29   	 *
30   	 * @return the instance of the MyLuteceExternalIdentityService service
31   	 */
32  	    public static IMyluteceExternalRoleService getInstance( )
33  	    {
34  	        if ( _singleton == null )
35  	        {
36  	            synchronized( IMyluteceExternalRoleService.class )
37  	            {
38  	            	IMyluteceExternalRoleService service = SpringContextService.getBean( BEAN_MY_LUTECE_ROLE_SERVICE );
39  	                _singleton = service;
40  	                
41  	            }
42  	        }
43  
44  	        return _singleton;
45  	    }
46  	/**
47       * {@inheritDoc}
48       */
49  	@Override
50  	public Collection<String> providesRoles(LuteceUser user) {
51  	    // Get the external roles
52          Set<String> listRoles = new HashSet<>( );
53          for ( IMyLuteceExternalRolesProvider roleProvider : getProviders() )
54          {
55              listRoles.addAll( roleProvider.providesRoles( user ) );
56          }
57          
58          return listRoles;
59  	}
60  
61  	/**
62       * {@inheritDoc}
63       */
64  	@Override
65  	public List<IMyLuteceExternalRolesProvider> getProviders() {
66  
67  		return SpringContextService.getBeansOfType( IMyLuteceExternalRolesProvider.class );
68  	}
69  
70  	
71  
72  }