~ubuntu-branches/ubuntu/maverick/eucalyptus/maverick

« back to all changes in this revision

Viewing changes to clc/modules/www/src/main/java/edu/ucsb/eucalyptus/admin/server/EucalyptusManagement.java

  • Committer: Bazaar Package Importer
  • Author(s): Dave Walker (Daviey)
  • Date: 2010-07-21 17:27:10 UTC
  • mfrom: (1.1.38 upstream)
  • Revision ID: james.westby@ubuntu.com-20100721172710-7xv07dmdqgivc3t9
Tags: 2.0~bzr1211-0ubuntu1
* New major upstream version merge, 2.0 (r1211).
* debian/patches/:
  - 01-wsdl-stubs.patch, debian/wsdl.md5sums: wsdl stubs updated.
  - 02-Makefile.patch: Updated to reflect new code layout.
  - 07-local_support_euca_conf-in.patch: Updated to reflect new code layout.
  - 08-ubuntu-default-networking.patch: Refreshed.
  - 09-small-128-192MB.patch: Updated to point to new location.
  - 10-disable-iscsi.patch: Refreshed.
  - 11-state-cleanup-memleakfix.patch: Removed, fixed upstream.
  - 15-fix-default-ramdisk.patch: Updated to point to new location.
  - 16-kvm_libvirt_xml_default_use_kvm.patch: Updated to reflect changes.
  - 17-fix_walrus_OOM_errors.patch: Removed, fixed upstream.
  - 18-priv_security.patch: Updated to reflect upstream changes.
  - 20-brute-force-webui.patch: Updated to reflect upstream changes. 
  - 21-eucalyptus-1.7-with-gwt-1.6.4.patch: New patch, allows 
    eucalyptus-1.7 to be built against gwt 1.6.4. Based on patch courtesy 
    of Dmitrii Zagorodnov, upstream. (LP: #597330)
* debian/eucalyptus-java-common.links: 
  - Changed symlink for groovy, point to groovy.all.jar, making compatiable 
    with groovy versions >1.7. (LP: #595421)
  - Added ant.jar & jetty-rewrite-handler.jar as they are now required.
* debian/control
  - & debian/build-jars: Added libjavassist-java and libjetty-extra-java as 
    build dependencies.
  - Added libjetty-extra-java as a dependency of eucalyptus-java-common
* The binary resulting jar's have been renamed from eucalyptus-*-1.6.2.jar
  to eucalyptus-*-main.jar:    
  - debian/eucalyptus-cc.upstart
  - debian/eucalyptus-cloud.install
  - debian/eucalyptus-common.eucalyptus.upstart
  - debian/eucalyptus-java-common.install
  - debian/eucalyptus-network.upstart
  - debian/eucalyptus-sc.install
  - debian/eucalyptus-walrus.install
* debian/eucalyptus-java-common.install: New upstream jars that have been
  installed:
  - eucalyptus-db-hsqldb-ext-main.jar
  - eucalyptus-component-main.jar
* debian/control:
  - Updated Standards Version to 3.8.4 (no change)
  - Updated the upstream Homepage to: http://open.eucalyptus.com/
  - Changed Vcs-Bzr to reflect new location of Ubuntu hosted development branch.
  - Made the Build Dependency of groovy and the binary eucalyptus-java-common
    package depend on version >=1.7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
import java.io.IOException;
69
69
import java.io.InputStream;
70
70
import java.net.MalformedURLException;
71
 
import java.security.GeneralSecurityException;
 
71
import java.security.Principal;
72
72
import java.util.ArrayList;
 
73
import java.util.Enumeration;
 
74
import java.util.HashSet;
73
75
import java.util.List;
 
76
import java.util.Set;
74
77
import java.util.regex.Matcher;
75
78
import java.util.regex.Pattern;
76
79
import org.apache.commons.httpclient.HttpClient;
 
80
import org.apache.commons.httpclient.ProxyHost;
77
81
import org.apache.commons.httpclient.methods.GetMethod;
78
82
import org.apache.log4j.Logger;
79
 
import com.eucalyptus.auth.CredentialProvider;
 
83
import com.eucalyptus.auth.Groups;
 
84
import com.eucalyptus.auth.NoSuchGroupException;
80
85
import com.eucalyptus.auth.NoSuchUserException;
81
86
import com.eucalyptus.auth.UserExistsException;
 
87
import com.eucalyptus.auth.UserInfo;
 
88
import com.eucalyptus.auth.UserInfoStore;
 
89
import com.eucalyptus.auth.Users;
 
90
import com.eucalyptus.auth.crypto.Crypto;
 
91
import com.eucalyptus.auth.principal.Authorization;
 
92
import com.eucalyptus.auth.principal.AvailabilityZonePermission;
 
93
import com.eucalyptus.auth.principal.Group;
 
94
import com.eucalyptus.auth.principal.User;
 
95
import com.eucalyptus.auth.WrappedUser;
 
96
import com.eucalyptus.bootstrap.HttpServerBootstrapper;
 
97
import com.eucalyptus.entities.EntityWrapper;
82
98
import com.eucalyptus.entities.NetworkRulesGroup;
83
99
import com.eucalyptus.event.EventVetoedException;
84
 
import com.eucalyptus.event.GenericEvent;
85
100
import com.eucalyptus.event.ListenerRegistry;
86
101
import com.eucalyptus.event.SystemConfigurationEvent;
 
102
import com.eucalyptus.images.Image;
 
103
import com.eucalyptus.images.ImageInfo;
 
104
import com.eucalyptus.images.Images;
87
105
import com.eucalyptus.network.NetworkGroupUtil;
 
106
import com.eucalyptus.util.Composites;
88
107
import com.eucalyptus.util.DNSProperties;
89
 
import com.eucalyptus.util.EntityWrapper;
90
108
import com.eucalyptus.util.EucalyptusCloudException;
 
109
import com.eucalyptus.util.Tx;
 
110
import com.google.common.collect.Iterables;
 
111
import com.google.common.collect.Lists;
 
112
import com.google.common.collect.Sets;
91
113
import com.google.gwt.user.client.rpc.SerializableException;
92
114
import edu.ucsb.eucalyptus.admin.client.CloudInfoWeb;
93
115
import edu.ucsb.eucalyptus.admin.client.ImageInfoWeb;
94
116
import edu.ucsb.eucalyptus.admin.client.SystemConfigWeb;
95
117
import edu.ucsb.eucalyptus.admin.client.UserInfoWeb;
96
 
import edu.ucsb.eucalyptus.cloud.entities.Counters;
97
 
import edu.ucsb.eucalyptus.cloud.entities.ImageInfo;
98
118
import edu.ucsb.eucalyptus.cloud.entities.SystemConfiguration;
99
 
import edu.ucsb.eucalyptus.cloud.entities.UserGroupInfo;
100
 
import edu.ucsb.eucalyptus.cloud.entities.UserInfo;
101
 
import edu.ucsb.eucalyptus.util.EucalyptusProperties;
102
 
import edu.ucsb.eucalyptus.util.UserManagement;
103
119
 
104
120
public class EucalyptusManagement {
105
121
 
106
122
        private static Logger LOG = Logger.getLogger( EucalyptusManagement.class );
107
 
 
108
 
        public static UserInfoWeb fromServer( UserInfo source )
109
 
        {
110
 
                UserInfoWeb target = new UserInfoWeb();
111
 
                update( target, source );
112
 
                return target;
113
 
        }
114
 
 
115
 
        public static UserInfo fromClient( UserInfoWeb source )
116
 
        {
117
 
                UserInfo target = new UserInfo();
118
 
                update( target, source );
119
 
                return target;
120
 
        }
121
 
 
122
 
        public static void update( UserInfo target, UserInfo user )
123
 
        {
124
 
                target.setUserName( user.getUserName() );
125
 
                target.setRealName( user.getRealName() );
126
 
                target.setEmail( user.getEmail() );
127
 
                target.setBCryptedPassword( user.getBCryptedPassword() );
128
 
                target.setTelephoneNumber( user.getTelephoneNumber() );
129
 
                target.setAffiliation( user.getAffiliation() );
130
 
                target.setProjectDescription( user.getProjectDescription() );
131
 
                target.setProjectPIName( user.getProjectPIName() );
132
 
                target.setConfirmationCode( user.getConfirmationCode() );
133
 
                target.setCertificateCode( user.getCertificateCode() );
134
 
                target.setIsApproved( user.isApproved() );
135
 
                target.setIsConfirmed( user.isConfirmed() );
136
 
                target.setIsEnabled( user.isEnabled() );
137
 
                target.setIsAdministrator( user.isAdministrator() );
138
 
                target.setPasswordExpires( user.getPasswordExpires() );
139
 
                target.setTemporaryPassword( user.getTemporaryPassword() );
140
 
        }
141
 
 
142
 
        public static void update( UserInfoWeb target, UserInfo user )
143
 
        {
144
 
                target.setUserName( user.getUserName() );
145
 
                target.setRealName( user.getRealName() );
146
 
                target.setEmail( user.getEmail() );
147
 
                target.setBCryptedPassword( user.getBCryptedPassword() );
148
 
                target.setTelephoneNumber( user.getTelephoneNumber() );
149
 
                target.setAffiliation( user.getAffiliation() );
150
 
                target.setProjectDescription( user.getProjectDescription() );
151
 
                target.setProjectPIName( user.getProjectPIName() );
152
 
                target.setConfirmationCode( user.getConfirmationCode() );
153
 
                target.setCertificateCode( user.getCertificateCode() );
154
 
                target.setIsApproved( user.isApproved() );
155
 
                target.setIsConfirmed( user.isConfirmed() );
156
 
                target.setIsEnabled( user.isEnabled() );
157
 
                target.setIsAdministrator( user.isAdministrator() );
158
 
                target.setPasswordExpires( user.getPasswordExpires() );
159
 
                target.setTemporaryPassword( user.getTemporaryPassword() );
160
 
                String queryId = "uninitialized";
161
 
                String secretKey = "uninitialized";
162
 
                try {
163
 
                        queryId = CredentialProvider.getQueryId( user.getUserName( ) );
164
 
                        secretKey = CredentialProvider.getSecretKey( queryId );
165
 
                } catch ( GeneralSecurityException e ) {
166
 
                        LOG.debug( e, e );
167
 
                }
168
 
                target.setQueryId( queryId );
169
 
                target.setSecretKey( secretKey );
170
 
        }
171
 
 
172
 
        public static void update( UserInfo target, UserInfoWeb user )
173
 
        {
174
 
                target.setUserName( user.getUserName() );
175
 
                target.setRealName( user.getRealName() );
176
 
                target.setEmail( user.getEmail() );
177
 
                target.setBCryptedPassword( user.getBCryptedPassword() );
178
 
                target.setTelephoneNumber( user.getTelephoneNumber() );
179
 
                target.setAffiliation( user.getAffiliation() );
180
 
                target.setProjectDescription( user.getProjectDescription() );
181
 
                target.setProjectPIName( user.getProjectPIName() );
182
 
                target.setConfirmationCode( user.getConfirmationCode() );
183
 
                target.setCertificateCode( user.getCertificateCode() );
184
 
                target.setIsApproved( user.isApproved() );
185
 
                target.setIsConfirmed( user.isConfirmed() );
186
 
                target.setIsEnabled( user.isEnabled() );
187
 
                target.setIsAdministrator( user.isAdministrator() );
188
 
                target.setPasswordExpires( user.getPasswordExpires() );
189
 
                target.setTemporaryPassword( user.getTemporaryPassword() );
190
 
        }
191
 
 
192
 
        public static ImageInfoWeb imageConvertToWeb ( ImageInfo source)
193
 
        {
194
 
                ImageInfoWeb target = new ImageInfoWeb();
195
 
 
196
 
                target.setId(source.getId());
197
 
                target.setImageId(source.getImageId());
198
 
                target.setImageLocation(source.getImageLocation());
199
 
                target.setImageState(source.getImageState());
200
 
                target.setImageOwnerId(source.getImageOwnerId());
201
 
                target.setArchitecture(source.getArchitecture());
202
 
                target.setImageType(source.getImageType());
203
 
                target.setKernelId(source.getKernelId());
204
 
                target.setRamdiskId(source.getRamdiskId());
205
 
                target.setPublic(source.getPublic());
206
 
 
207
 
                return target;
208
 
        }
209
 
 
 
123
//grze: see Groups.{ALL,DEFAULT}
 
124
//      private static final String GROUP_ALL = "all";
 
125
//      private static final String GROUP_DEFAULT = "default";
 
126
        
210
127
        public static String getError( String message )
211
128
        {
212
129
                return "<html><title>HTTP/1.0 403 Forbidden</title><body><div align=\"center\"><p><h1>403: Forbidden</h1></p><p><img src=\"themes/active/logo.png\" /></p><p><h3 style=\"font-color: red;\">" + message + "</h3></p></div></body></html>";
215
132
        /* TODO: for now 'pattern' is ignored and all users are returned */
216
133
        public static List <UserInfoWeb> getWebUsers (String pattern) throws SerializableException
217
134
        {
218
 
                UserInfo searchUser = new UserInfo(); /* empty => return all */
219
 
                EntityWrapper<UserInfo> dbWrapper = new EntityWrapper<UserInfo>();
220
 
                List<UserInfo> userList = dbWrapper.query( searchUser );
221
 
 
222
 
                List<UserInfoWeb> webUsersList = new ArrayList<UserInfoWeb>();
223
 
                for ( UserInfo u : userList)
224
 
                        webUsersList.add(fromServer(u));
225
 
                dbWrapper.commit();
 
135
          final List<UserInfoWeb> webUsersList = Lists.newArrayList();
 
136
          for( User u : Users.listAllUsers( ) ) {
 
137
      try {
 
138
        UserInfo userInfo = (( WrappedUser ) u).getUserInfo( );
 
139
        webUsersList.add( Composites.composeNew( UserInfoWeb.class, userInfo, u ) );
 
140
      } catch ( Exception e ) {
 
141
        LOG.debug( e, e );
 
142
      }
 
143
          }
226
144
                return webUsersList;
227
145
        }
228
146
 
229
147
        /* TODO: for now 'pattern' is ignored and all images are returned */
230
 
        public static List <ImageInfoWeb> getWebImages (String pattern) throws SerializableException
231
 
        {
232
 
                ImageInfo searchImage = new ImageInfo(); /* empty => return all */
233
 
                EntityWrapper<ImageInfo> db = new EntityWrapper<ImageInfo>();
234
 
                List<ImageInfo> results= db.query( searchImage );
235
 
                List<ImageInfoWeb> imagesList = new ArrayList<ImageInfoWeb>();
236
 
                for ( ImageInfo i : results )
237
 
                        imagesList.add(imageConvertToWeb(i));
238
 
                db.commit();
239
 
                return imagesList;
240
 
        }
241
 
 
242
 
        public static UserInfoWeb getWebUser( String userName ) throws SerializableException
243
 
        {
244
 
                EntityWrapper<UserInfo> dbWrapper = new EntityWrapper<UserInfo>();
245
 
                List<UserInfo> userList = dbWrapper.query( new UserInfo( userName ) );
246
 
                if ( userList.size() != 1 )
247
 
                {
248
 
                        try {//TODO: temporary hack to support older user info objects
249
 
                                if( "admin".equals( userName )) {
250
 
                                        UserInfo u = UserManagement.generateAdmin( );
251
 
                                        dbWrapper.add( u );
252
 
                                        UserGroupInfo allGroup = new UserGroupInfo( "all" );
253
 
                                        dbWrapper.getSession( ).persist( new Counters( ) );
254
 
                                        dbWrapper.commit( );
255
 
                                        return EucalyptusManagement.fromServer( u );
256
 
                                } else {
257
 
                                        dbWrapper.rollback( );
258
 
                                        throw EucalyptusManagement.makeFault("User does not exist" );           
259
 
                                }
260
 
                        } catch ( Exception e ) {
261
 
                                dbWrapper.rollback( );
262
 
                                throw EucalyptusManagement.makeFault("User does not exist" );
263
 
                        }
264
 
                }
265
 
                dbWrapper.commit();
266
 
                return EucalyptusManagement.fromServer( userList.get( 0 ) );
267
 
        }
268
 
 
269
 
        public static UserInfoWeb getWebUserByEmail( String emailAddress ) throws SerializableException
270
 
        {
271
 
                UserInfo searchUser = new UserInfo( );
272
 
                searchUser.setEmail ( emailAddress );
273
 
                EntityWrapper<UserInfo> dbWrapper = new EntityWrapper<UserInfo>();
274
 
                List<UserInfo> userList = dbWrapper.query( searchUser );
275
 
                if ( userList.size() != 1 )
276
 
                {
277
 
                        dbWrapper.rollback();
278
 
                        throw EucalyptusManagement.makeFault("User does not exist" );
279
 
                }
280
 
                dbWrapper.commit();
281
 
                return EucalyptusManagement.fromServer( userList.get( 0 ) );
282
 
        }
283
 
 
284
 
        public static UserInfoWeb getWebUserByCode( String code ) throws SerializableException
285
 
        {
286
 
                UserInfo searchUser = new UserInfo( );
287
 
                searchUser.setConfirmationCode ( code );
288
 
                EntityWrapper<UserInfo> dbWrapper = new EntityWrapper<UserInfo>();
289
 
                List<UserInfo> userList = dbWrapper.query( searchUser );
290
 
                if ( userList.size() != 1 )
291
 
                {
292
 
                        dbWrapper.rollback();
293
 
                        throw EucalyptusManagement.makeFault("Invalid confirmation code" );
294
 
                }
295
 
                dbWrapper.commit();
296
 
                return EucalyptusManagement.fromServer( userList.get( 0 ) );
297
 
        }
 
148
        public static List <ImageInfoWeb> getWebImages (String pattern) throws SerializableException {
 
149
                List<ImageInfoWeb> ret = Lists.newArrayList( );
 
150
          for( Image i : Images.listAllImages( ) ) {
 
151
        ret.add( Composites.update( i, new ImageInfoWeb( ) ) );
 
152
          }
 
153
    return ret;
 
154
        }
 
155
 
 
156
        public static UserInfoWeb getWebUser( String userName ) throws SerializableException {
 
157
          return EucalyptusManagement.getWebUserByExample( new UserInfo( userName ) );
 
158
        }
 
159
 
 
160
  public static UserInfoWeb getWebUserByEmail( String emailAddress ) throws SerializableException {
 
161
    UserInfo s = new UserInfo( );
 
162
    s.setEmail( emailAddress );
 
163
    return EucalyptusManagement.getWebUserByExample( s );
 
164
  }
 
165
 
 
166
  public static UserInfoWeb getWebUserByCode( String confCode ) throws SerializableException {
 
167
    UserInfo s = new UserInfo( );
 
168
    s.setConfirmationCode( confCode );
 
169
    return EucalyptusManagement.getWebUserByExample( s );
 
170
  }
 
171
  
 
172
  private static UserInfoWeb getWebUserByExample( UserInfo ex ) throws SerializableException {
 
173
    try {
 
174
      UserInfo userInfo = UserInfoStore.getUserInfo( ex );
 
175
      User user = Users.lookupUser( userInfo.getUserName( ) );
 
176
      UserInfoWeb webUser = Composites.composeNew( UserInfoWeb.class, userInfo, user );
 
177
      return webUser;
 
178
    } catch ( NoSuchUserException e ) {
 
179
      throw EucalyptusManagement.makeFault( "User does not exist" );
 
180
    }
 
181
  }
298
182
 
299
183
        public static synchronized void addWebUser( UserInfoWeb webUser ) throws SerializableException
300
184
        {
301
 
                EntityWrapper<UserInfo> dbWrapper = new EntityWrapper<UserInfo>();
302
 
                List<UserInfo> userList = dbWrapper.query( new UserInfo( webUser.getUserName() ) );
303
 
                if ( userList.size() != 0 )
304
 
                {
305
 
                        dbWrapper.rollback();
306
 
                        throw EucalyptusManagement.makeFault("User already exists" );
307
 
                }
308
 
 
309
 
                //String hash = BCrypt.hashpw( webUser.getBCryptedPassword(), BCrypt.gensalt() );
310
 
                //webUser.setBCryptedPassword( hash );
311
 
                //webUser.setIsAdministrator( false );
312
 
                //webUser.setIsApproved( false );
313
 
                //webUser.setIsEnabled( false );
314
 
 
315
 
                // TODO: add web user properly, with all keys and certs generated, too
316
 
                webUser.setConfirmationCode( UserManagement.generateConfirmationCode( webUser.getUserName() ) );
317
 
                webUser.setCertificateCode( UserManagement.generateCertificateCode( webUser.getUserName() ) );
318
 
 
319
 
                webUser.setSecretKey( UserManagement.generateSecretKey( webUser.getUserName() ) );
320
 
                webUser.setQueryId( UserManagement.generateQueryId( webUser.getUserName() ));
321
 
 
322
 
                UserInfo newUser = EucalyptusManagement.fromClient( webUser );
323
 
                newUser.setReservationId( 0l );
324
 
                try {
325
 
                        NetworkGroupUtil.createUserNetworkRulesGroup( newUser.getUserName( ), NetworkRulesGroup.NETWORK_DEFAULT_NAME, "default group" );
326
 
                } catch ( EucalyptusCloudException e1 ) {
327
 
                        LOG.debug( e1, e1 );
328
 
                }
329
 
 
330
 
                dbWrapper.add( newUser );
331
 
                dbWrapper.commit();
332
 
 
333
 
                try {//FIXME: fix this nicely
334
 
                        CredentialProvider.addUser(newUser.getUserName( ),newUser.isAdministrator( ));
335
 
                } catch ( UserExistsException e ) {
336
 
                        LOG.error(e);
337
 
                }
 
185
          User user = null;
 
186
          try {
 
187
      user = Users.lookupUser( webUser.getUserName( ) );
 
188
      throw EucalyptusManagement.makeFault("User already exists" );
 
189
    } catch ( NoSuchUserException e ) {
 
190
      try {
 
191
        user = Users.addUser( webUser.getUserName( ), webUser.isAdministrator( ), webUser.isEnabled( ) );
 
192
        try {
 
193
          UserInfo userInfo = Composites.updateNew( webUser, UserInfo.class );
 
194
          userInfo.setConfirmationCode( Crypto.generateSessionToken( webUser.getUserName() ) );
 
195
          try {
 
196
            NetworkGroupUtil.createUserNetworkRulesGroup( userInfo.getUserName( ), NetworkRulesGroup.NETWORK_DEFAULT_NAME, "default group" );
 
197
          } catch ( EucalyptusCloudException e1 ) {
 
198
            LOG.debug( e1, e1 );
 
199
          }
 
200
          UserInfoStore.addUserInfo( userInfo );
 
201
        } catch ( Exception e1 ) {
 
202
          LOG.error( e1, e1 );
 
203
          throw EucalyptusManagement.makeFault("Error adding user: " + e1.getMessage( ) );
 
204
        }
 
205
      } catch ( UserExistsException e1 ) {
 
206
        LOG.error( e1, e1 );
 
207
        throw EucalyptusManagement.makeFault("User already exists" );
 
208
      } catch ( UnsupportedOperationException e1 ) {
 
209
        LOG.error( e1, e1 );
 
210
        throw EucalyptusManagement.makeFault("Error adding user: " + e1.getMessage( ) );
 
211
      }
 
212
    }     
338
213
        }
339
214
 
340
215
        private static SerializableException makeFault(String message)
352
227
 
353
228
        public static void deleteUser( String userName ) throws SerializableException
354
229
        {
355
 
                EntityWrapper<UserInfo> db = new EntityWrapper<UserInfo>();
356
 
                List<UserInfo> userList = db.query( new UserInfo( userName )  );
357
 
                if ( userList.size() != 1 )
358
 
                {
359
 
                        db.rollback();
360
 
                        throw EucalyptusManagement.makeFault("User already exists" );
361
 
                }
362
 
                db.delete( userList.get(0) );
363
 
                db.commit();
364
 
                try {
365
 
                        CredentialProvider.deleteUser(userName);
366
 
                } catch ( NoSuchUserException e ) {
367
 
                        LOG.error(e);
368
 
                        throw EucalyptusManagement.makeFault( "Unable to delete user" );
369
 
                }
370
 
        }
371
 
 
372
 
        public static void commitWebUser( UserInfoWeb webUser ) throws SerializableException
373
 
        {
374
 
                UserInfo user = fromClient( webUser );
375
 
                commitUser( user );
376
 
        }
377
 
 
378
 
        public static void commitUser( UserInfo user ) throws SerializableException
379
 
        {
380
 
                UserInfo searchUser = new UserInfo( user.getUserName() );
381
 
                EntityWrapper<UserInfo> db = new EntityWrapper<UserInfo>();
382
 
                List<UserInfo> userList = db.query( searchUser );
383
 
                UserInfo target = userList.get( 0 );
384
 
                if ( userList.size() != 1 )
385
 
                {
386
 
                        db.rollback();
387
 
                        throw EucalyptusManagement.makeFault( "User does not exist" );
388
 
                }
389
 
                update( target, user );
390
 
                try {
391
 
                        CredentialProvider.updateUser(user.getUserName(), user.isEnabled());
392
 
                } catch ( NoSuchUserException e ) {
393
 
                        db.rollback();
394
 
                        LOG.error(e);
395
 
                        throw EucalyptusManagement.makeFault( "Unable to update user" );
396
 
                }
397
 
                db.commit();
 
230
          try {
 
231
      Users.deleteUser( userName );
 
232
      UserInfoStore.deleteUserInfo( userName );
 
233
    } catch ( NoSuchUserException e1 ) {
 
234
      LOG.debug( e1, e1 );
 
235
      throw EucalyptusManagement.makeFault( "Unable to delete user" );
 
236
    } catch ( UnsupportedOperationException e1 ) {
 
237
      LOG.debug( e1, e1 );
 
238
      throw EucalyptusManagement.makeFault("Error while deleting user: " + e1.getMessage( ) );      
 
239
    }
 
240
        }
 
241
 
 
242
        public static void commitWebUser( final UserInfoWeb webUser ) throws SerializableException
 
243
        {
 
244
          String userName = webUser.getUserName( );
 
245
    try {
 
246
      Users.updateUser( userName, new Tx<User>( ) {
 
247
        public void fire( User user ) throws Throwable {
 
248
          Composites.project( webUser, user );
 
249
        }
 
250
      });
 
251
      UserInfoStore.updateUserInfo( userName, new Tx<UserInfo>( ) {
 
252
        public void fire( UserInfo info ) throws Throwable {
 
253
          Composites.project( webUser, info );
 
254
        }
 
255
      });
 
256
    } catch ( NoSuchUserException e1 ) {
 
257
      LOG.error( e1, e1 );
 
258
      throw EucalyptusManagement.makeFault( "Unable to update user" );
 
259
    } catch ( UnsupportedOperationException e1 ) {
 
260
      LOG.error( e1, e1 );
 
261
      throw EucalyptusManagement.makeFault("Error while updating user: " + e1.getMessage( ) );      
 
262
    }
398
263
        }
399
264
 
400
265
        public static String getAdminEmail() throws SerializableException
401
266
        {
402
 
                UserInfo searchUser = new UserInfo();
403
 
                searchUser.setIsAdministrator( true );
404
 
                EntityWrapper<UserInfo> db = new EntityWrapper<UserInfo>();
405
 
                List<UserInfo> userList = db.query( searchUser );
406
 
                if ( userList.size() < 1 || userList.isEmpty() )
407
 
                {
408
 
                        db.rollback();
409
 
                        throw EucalyptusManagement.makeFault("Administrator account not found" );
410
 
                }
411
 
 
412
 
                UserInfo first = userList.get( 0 );
413
 
                String addr = first.getEmail();
414
 
                if (addr==null || addr.equals("")) {
415
 
                        db.rollback();
416
 
                        throw EucalyptusManagement.makeFault( "Email address is not set" );
417
 
                }
418
 
                db.commit();
 
267
                String addr = null;
 
268
                try {
 
269
      UserInfo adminUser = UserInfoStore.getUserInfo( new UserInfo("admin") );
 
270
      addr = adminUser.getEmail( );
 
271
    } catch ( NoSuchUserException e ) {
 
272
      throw EucalyptusManagement.makeFault("Administrator account not found" );
 
273
    }
 
274
    if (addr==null || addr.equals("")) {
 
275
      throw EucalyptusManagement.makeFault( "Email address is not set" );
 
276
    }
419
277
                return addr;
420
 
 
421
 
                //return Configuration.getConfiguration().getAdminEmail();
422
278
        }
423
279
 
424
280
        public static void deleteImage(String imageId)
431
287
 
432
288
                if ( imgList.size() > 0 && !imgList.isEmpty() )
433
289
                {
434
 
                        ImageInfo foundimgSearch = imgList.get( 0 );
 
290
                        Image foundimgSearch = imgList.get( 0 );
435
291
                        foundimgSearch.setImageState( "deregistered" );
436
292
                        db.commit();
437
293
                }
444
300
        public static void disableImage(String imageId)
445
301
        throws SerializableException
446
302
        {
447
 
                ImageInfo searchImg = new ImageInfo( );
448
 
                searchImg.setImageId( imageId );
449
 
                EntityWrapper<ImageInfo> db = new EntityWrapper<ImageInfo>();
450
 
                List<ImageInfo> imgList= db.query( searchImg );
451
 
 
452
 
                if ( imgList.size() > 0 && !imgList.isEmpty() )
453
 
                {
454
 
                        ImageInfo foundimgSearch = imgList.get( 0 );
455
 
                        foundimgSearch.setImageState( "deregistered" );
456
 
                        db.commit();
457
 
                }
458
 
                else
459
 
                {
460
 
                        db.rollback();
461
 
                        throw EucalyptusManagement.makeFault ("Specified image was not found, sorry.");
462
 
                }
 
303
          try {
 
304
      new Images._byId( imageId ) {{ new _mutator() {
 
305
          @Override public void set( ImageInfo e ) {
 
306
            e.setImageState( "deregistered" );
 
307
          }}.set( );
 
308
      }};
 
309
    } catch ( EucalyptusCloudException e ) {
 
310
      throw EucalyptusManagement.makeFault ("Specified image was not found, sorry.");
 
311
    }
463
312
        }
464
313
        public static void enableImage(String imageId)
465
314
        throws SerializableException
466
315
        {
467
 
                ImageInfo searchImg = new ImageInfo( );
468
 
                searchImg.setImageId( imageId );
469
 
                EntityWrapper<ImageInfo> db = new EntityWrapper<ImageInfo>();
470
 
                List<ImageInfo> imgList= db.query( searchImg );
471
 
 
472
 
                if ( imgList.size() > 0 && !imgList.isEmpty() )
473
 
                {
474
 
                        ImageInfo foundimgSearch = imgList.get( 0 );
475
 
                        foundimgSearch.setImageState( "available" );
476
 
                        db.commit();
477
 
                }
478
 
                else
479
 
                {
480
 
                        db.rollback();
481
 
                        throw EucalyptusManagement.makeFault ("Specified image was not found, sorry.");
482
 
                }
 
316
    try {
 
317
      new Images._byId( imageId ) {{ new _mutator() {
 
318
          @Override public void set( ImageInfo e ) {
 
319
            e.setImageState( "available" );
 
320
          }}.set( );
 
321
      }};
 
322
    } catch ( EucalyptusCloudException e ) {
 
323
      throw EucalyptusManagement.makeFault ("Specified image was not found, sorry.");
 
324
    }
483
325
        }
484
326
 
485
327
        public static SystemConfigWeb getSystemConfig() throws SerializableException
486
328
        {
487
 
                EntityWrapper<SystemConfiguration> db = new EntityWrapper<SystemConfiguration>();
488
 
                SystemConfiguration sysConf = EucalyptusProperties.getSystemConfiguration();
 
329
                SystemConfiguration sysConf = SystemConfiguration.getSystemConfiguration();
 
330
                LOG.debug( "Sending cloud host: " + sysConf.getCloudHost( ) );
489
331
                return new SystemConfigWeb( 
490
332
                                sysConf.getDefaultKernel(),
491
333
                                sysConf.getDefaultRamdisk(),
492
334
                                sysConf.getMaxUserPublicAddresses(),
493
335
                                sysConf.isDoDynamicPublicAddresses(),
494
336
                                sysConf.getSystemReservedPublicAddresses(),
495
 
                                sysConf.getZeroFillVolumes(),
496
337
                                sysConf.getDnsDomain(),
497
338
                                sysConf.getNameserver(),
498
339
                                sysConf.getNameserverAddress(),
516
357
                        sysConf.setMaxUserPublicAddresses( systemConfig.getMaxUserPublicAddresses() );
517
358
                        sysConf.setDoDynamicPublicAddresses( systemConfig.isDoDynamicPublicAddresses() );
518
359
                        sysConf.setSystemReservedPublicAddresses( systemConfig.getSystemReservedPublicAddresses() );
519
 
                        sysConf.setZeroFillVolumes(systemConfig.getZeroFillVolumes());
520
360
                        db.commit();
521
361
                        DNSProperties.update();
522
362
                }
528
368
                                        systemConfig.getMaxUserPublicAddresses(),
529
369
                                        systemConfig.isDoDynamicPublicAddresses(),
530
370
                                        systemConfig.getSystemReservedPublicAddresses(),
531
 
                                        systemConfig.getZeroFillVolumes(),
532
371
                                        systemConfig.getDnsDomain(),
533
372
                                        systemConfig.getNameserver(),
534
373
                                        systemConfig.getNameserverAddress(),
548
387
        {
549
388
                String ipAddr = null;
550
389
                HttpClient httpClient = new HttpClient();
 
390
                //support for http proxy
 
391
                if(HttpServerBootstrapper.httpProxyHost != null && (HttpServerBootstrapper.httpProxyHost.length() > 0)) {
 
392
                        String proxyHost = HttpServerBootstrapper.httpProxyHost;
 
393
                        if(HttpServerBootstrapper.httpProxyPort != null &&  (HttpServerBootstrapper.httpProxyPort.length() > 0)) {
 
394
                                int proxyPort = Integer.parseInt(HttpServerBootstrapper.httpProxyPort);
 
395
                                httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
 
396
                        } else {
 
397
                                httpClient.getHostConfiguration().setProxyHost(new ProxyHost(proxyHost));
 
398
                        }
 
399
                }
551
400
                // Use Rightscale's "whoami" service
552
401
                GetMethod method = new GetMethod("https://my.rightscale.com/whoami?api_version=1.0&cloud=0");
553
402
                Integer timeoutMs = new Integer(3 * 1000); // TODO: is this working?
585
434
        public static CloudInfoWeb getCloudInfo (boolean setExternalHostPort) throws SerializableException
586
435
        {
587
436
                String cloudRegisterId = null;
588
 
            cloudRegisterId = EucalyptusProperties.getSystemConfiguration().getRegistrationId();
 
437
            cloudRegisterId = SystemConfiguration.getSystemConfiguration().getRegistrationId();
589
438
                CloudInfoWeb cloudInfo = new CloudInfoWeb();
590
 
                cloudInfo.setInternalHostPort (EucalyptusProperties.getInternalIpAddress() + ":8443");
 
439
                cloudInfo.setInternalHostPort (SystemConfiguration.getInternalIpAddress() + ":8443");
591
440
                if (setExternalHostPort) {
592
441
                        String ipAddr = getExternalIpAddress();
593
442
                        if (ipAddr!=null) {
599
448
                return cloudInfo;
600
449
        }
601
450
 
 
451
        private static List<String> getGroupZones(Group group) {
 
452
                List<String> zones = new ArrayList<String>();
 
453
                for (Authorization auth : group.getAuthorizations()) {
 
454
                        if (auth instanceof AvailabilityZonePermission) {
 
455
                                zones.add(auth.getValue());
 
456
                        }
 
457
                }
 
458
                return zones;
 
459
        }
 
460
 
602
461
}