Changeset 520b4a3 in guacamole


Ignore:
Timestamp:
04/18/12 15:02:23 (13 months ago)
Author:
Michal Kotas <miko@…>
Branches:
master, guacamole-debian-parent, rpm, unstable, unstable-websocket
Children:
7545277
Parents:
729e196
git-author:
Michal Kotas <miko@…> (04/18/12 15:01:34)
git-committer:
Michael Jumper <zhangmaike@…> (04/18/12 15:02:23)
Message:

Implement multiple authorized connections per user.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/example/user-mapping.xml

    r0c279c6 r520b4a3  
    33    <!-- Per-user authentication and config information --> 
    44    <authorize username="USERNAME" password="PASSWORD"> 
    5         <protocol>vnc</protocol> 
    6         <param name="hostname">localhost</param> 
    7         <param name="port">5900</param> 
    8         <param name="password">VNCPASS</param> 
     5 
     6        <!-- Single authorized connection --> 
     7                <remote-server servername="localhost"> 
     8            <protocol>vnc</protocol> 
     9            <param name="hostname">localhost</param> 
     10            <param name="port">5900</param> 
     11            <param name="password">VNCPASS</param> 
     12        </remote-server> 
     13 
    914    </authorize> 
    1015 
     
    1520            password="319f4d26e3c536b5dd871bb2c52e3178" 
    1621            encoding="md5"> 
    17         <protocol>vnc</protocol> 
    18         <param name="hostname">localhost</param> 
    19         <param name="port">5901</param> 
    20         <param name="password">VNCPASS</param> 
    21     </authorize> 
     22 
     23        <!-- First authorized connection --> 
     24                <remote-server servername="localhost"> 
     25            <protocol>vnc</protocol> 
     26            <param name="hostname">localhost</param> 
     27            <param name="port">5901</param> 
     28            <param name="password">VNCPASS</param> 
     29        </remote-server> 
     30 
     31        <!-- Second authorized connection --> 
     32                <remote-server servername="otherhost"> 
     33            <protocol>vnc</protocol> 
     34            <param name="hostname">otherhost</param> 
     35            <param name="port">5900</param> 
     36            <param name="password">VNCPASS</param> 
     37        </remote-server> 
     38 
     39 </authorize> 
    2240 
    2341</user-mapping> 
  • src/main/java/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider.java

    rc5c5631 r520b4a3  
    4747/** 
    4848 * Authenticates users against a static list of username/password pairs. 
    49  * Each username/password may be associated with exactly one configuration. 
     49 * Each username/password may be associated with multiple configurations. 
    5050 * This list is stored in an XML file which is reread if modified. 
    5151 *  
    52  * @author Michael Jumper 
     52 * This is modified version of BasicFileAuthenticationProvider written by Michael Jumper. 
     53 *  
     54 * @author Michal Kotas 
    5355 */ 
    5456public class BasicFileAuthenticationProvider implements AuthenticationProvider { 
     
    137139        AuthInfo info = mapping.get(credentials.getUsername()); 
    138140        if (info != null && info.validate(credentials.getUsername(), credentials.getPassword())) { 
    139             Map<String, GuacamoleConfiguration> configs = new HashMap<String, GuacamoleConfiguration>(); 
    140             configs.put("DEFAULT", info.getConfiguration()); 
     141             
     142            //Map<String, GuacamoleConfiguration> configs = new HashMap<String, GuacamoleConfiguration>(); 
     143            //configs.put("DEFAULT", info.getConfiguration()); 
     144            //return configs; 
     145             
     146            Map<String, GuacamoleConfiguration> configs = info.getConfigurations();           
    141147            return configs; 
    142148        } 
     
    158164        private Encoding auth_encoding; 
    159165 
    160         private GuacamoleConfiguration config; 
     166        private Map<String, GuacamoleConfiguration> configs; 
    161167 
    162168        public AuthInfo(String auth_username, String auth_password, Encoding auth_encoding) { 
     
    165171            this.auth_encoding = auth_encoding; 
    166172 
    167             config = new GuacamoleConfiguration(); 
     173            configs = new HashMap<String, GuacamoleConfiguration>(); 
    168174        } 
    169175 
     
    221227        } 
    222228 
    223         public GuacamoleConfiguration getConfiguration() { 
    224             return config; 
     229        public GuacamoleConfiguration getConfiguration(String name) { 
     230            //return configs; 
     231            return configs.get(name); 
     232        } 
     233        public Map<String, GuacamoleConfiguration> getConfigurations() { 
     234            return configs; 
     235        } 
     236        public void addConfiguration(String name) { 
     237            configs.put(name, new GuacamoleConfiguration()); 
    225238        } 
    226239 
    227240    } 
    228  
    229241 
    230242    private static class BasicUserMappingContentHandler extends DefaultHandler { 
     
    239251            ROOT, 
    240252            USER_MAPPING, 
     253            REMOTE_SERVER, 
    241254            AUTH_INFO, 
    242255            PROTOCOL, 
     
    248261        private AuthInfo current = null; 
    249262        private String currentParameter = null; 
     263        private String currentRemoteServer = null; 
    250264 
    251265        @Override 
     
    254268            switch (state)  { 
    255269 
    256                 case USER_MAPPING: 
    257  
    258                     if (localName.equals("user-mapping")) { 
    259                         state = State.END; 
    260                         return; 
    261                     } 
    262  
    263                     break; 
    264  
    265                 case AUTH_INFO: 
    266  
    267                     if (localName.equals("authorize")) { 
    268  
    269                         // Finalize mapping for this user 
    270                         authMapping.put( 
    271                             current.auth_username, 
    272                             current 
    273                         ); 
    274  
    275                         state = State.USER_MAPPING; 
    276                         return; 
    277                     } 
    278  
    279                     break; 
    280  
    281                 case PROTOCOL: 
    282  
    283                     if (localName.equals("protocol")) { 
    284                         state = State.AUTH_INFO; 
    285                         return; 
    286                     } 
    287  
    288                     break; 
    289  
    290                 case PARAMETER: 
    291  
    292                     if (localName.equals("param")) { 
    293                         state = State.AUTH_INFO; 
    294                         return; 
    295                     } 
    296  
    297                     break; 
    298  
    299             } 
     270            case USER_MAPPING: 
     271 
     272                if (localName.equals("user-mapping")) { 
     273                    state = State.END; 
     274                    return; 
     275                } 
     276 
     277                break; 
     278 
     279            case AUTH_INFO: 
     280 
     281                if (localName.equals("authorize")) { 
     282 
     283                    // Finalize mapping for this user 
     284                    authMapping.put( 
     285                        current.auth_username, 
     286                        current 
     287                    ); 
     288 
     289                    state = State.USER_MAPPING; 
     290                    return; 
     291                } 
     292 
     293                break; 
     294                 
     295            case REMOTE_SERVER: 
     296 
     297                if (localName.equals("remote-server")) { 
     298                    state = State.AUTH_INFO; 
     299                    return; 
     300                } 
     301 
     302                break;                 
     303 
     304            case PROTOCOL: 
     305 
     306                if (localName.equals("protocol")) { 
     307                    state = State.REMOTE_SERVER; 
     308                    return; 
     309                } 
     310 
     311                break; 
     312 
     313            case PARAMETER: 
     314 
     315                if (localName.equals("param")) { 
     316                    state = State.REMOTE_SERVER; 
     317                    return; 
     318                } 
     319 
     320                break; 
     321 
     322        } 
    300323 
    301324            throw new SAXException("Tag not yet complete: " + localName); 
     
    318341                    break; 
    319342 
    320                 // Only <authorize> tags allowed in main document 
    321343                case USER_MAPPING: 
    322344 
     
    350372                case AUTH_INFO: 
    351373 
     374                    if (localName.equals("remote-server")) { 
     375 
     376                        currentRemoteServer = attributes.getValue("servername"); 
     377                        if (currentRemoteServer == null) 
     378                            throw new SAXException("Attribute \"servername\" required for param tag."); 
     379                         
     380                        current.addConfiguration(currentRemoteServer); 
     381                         
     382                        // Next state 
     383                        state = State.REMOTE_SERVER; 
     384                        return; 
     385                    } 
     386 
     387                    break; 
     388                     
     389                case REMOTE_SERVER: 
     390 
    352391                    if (localName.equals("protocol")) { 
    353392                        // Next state 
     
    367406                    } 
    368407 
    369                     break; 
     408                    break;                    
    370409 
    371410            } 
     
    379418 
    380419            String str = new String(ch, start, length); 
     420    
    381421            switch (state) { 
    382422 
    383423                case PROTOCOL: 
    384                     current.getConfiguration() 
    385                             .setProtocol(str); 
     424                    current.getConfiguration(currentRemoteServer) 
     425                        .setProtocol(str); 
    386426                    return; 
    387427 
    388428                case PARAMETER: 
    389                     current.getConfiguration() 
     429                    current.getConfiguration(currentRemoteServer) 
    390430                            .setParameter(currentParameter, str); 
    391431                    return; 
Note: See TracChangeset for help on using the changeset viewer.