001    package railo.runtime.config;
002    
003    
004    import railo.runtime.exp.PageException;
005    import railo.runtime.functions.other.Encrypt;
006    import railo.runtime.net.proxy.ProxyData;
007    import railo.runtime.net.rpc.client.RPCClient;
008    import railo.runtime.op.Caster;
009    import railo.runtime.spooler.remote.RemoteClientTask;
010    import railo.runtime.type.Struct;
011    import railo.runtime.type.StructImpl;
012    import railo.runtime.type.util.KeyConstants;
013    import railo.runtime.type.util.ListUtil;
014    
015    public class RemoteClientImpl implements RemoteClient {
016    
017            private String url;
018            private String serverUsername;
019            private String serverPassword;
020            private ProxyData proxyData;
021            private String type;
022            private String adminPassword;
023            private String securityKey;
024            private String label;
025            private String usage;
026            private String id;
027    
028            public RemoteClientImpl(String label,String type, String url, String serverUsername, String serverPassword,String adminPassword, ProxyData proxyData, String securityKey,String usage) {
029                    this.label = label;
030                    this.url = url;
031                    this.serverUsername = serverUsername;
032                    this.serverPassword = serverPassword;
033                    this.proxyData = proxyData;
034                    this.type = type;
035                    this.adminPassword = adminPassword;
036                    this.securityKey = securityKey;
037                    this.usage = usage;
038            }
039    
040            /**
041             * @return the url
042             */
043            public String getUrl() {
044                    return url;
045            }
046    
047            /**
048             * @return the serverUsername
049             */
050            public String getServerUsername() {
051                    return serverUsername;
052            }
053    
054            /**
055             * @return the serverPassword
056             */
057            public String getServerPassword() {
058                    return serverPassword;
059            }
060    
061            /**
062             * @return the proxyData
063             */
064            public ProxyData getProxyData() {
065                    return proxyData;
066            }
067    
068            /**
069             * @return the type
070             */
071            public String getType() {
072                    return type;
073            }
074    
075            /**
076             * @return the adminPassword
077             */
078            public String getAdminPassword() {
079                    return adminPassword;
080            }
081    
082            /**
083             * @return the securityKey
084             */
085            public String getSecurityKey() {
086                    return securityKey;
087            }
088    
089            public String getAdminPasswordEncrypted() {
090                    try {
091                            return Encrypt.invoke(getAdminPassword(), getSecurityKey(),"cfmx_compat","uu");
092                    } 
093                    catch (PageException e) {
094                            return null;
095                    }
096            }
097    
098            public String getLabel() {
099                    return label;
100            }
101    
102            public String getUsage() {
103                    return usage;
104            }
105    
106            public boolean hasUsage(String usage) {
107                    return ListUtil.listFindNoCaseIgnoreEmpty(this.usage,usage,',')!=-1 ;
108            }
109    
110            public String getId(Config config) {
111    
112                    if(id!=null) return id;
113                    
114                    Struct attrColl = new StructImpl();
115                    attrColl.setEL(KeyConstants._action, "getToken");
116                    
117                    Struct args = new StructImpl();
118                    args.setEL(KeyConstants._type, getType());
119                    args.setEL(RemoteClientTask.PASSWORD, getAdminPasswordEncrypted());
120                    args.setEL(RemoteClientTask.CALLER_ID, "undefined");
121                    args.setEL(RemoteClientTask.ATTRIBUTE_COLLECTION, attrColl);
122                    
123                    
124                    
125                    try {
126                            RPCClient rpc = RemoteClientTask.getRPCClient(this);
127                            Object result = rpc.callWithNamedValues(config, "invoke", args);
128                            return id=ConfigImpl.getId(securityKey, Caster.toString(result,null), null);
129                            
130                    } 
131                    catch (Throwable t) {t.printStackTrace();
132                            return null;
133                    }
134            }
135            
136    
137    }