~graziano.obertelli/eucalyptus/lp683800

« back to all changes in this revision

Viewing changes to clc/modules/authentication/src/main/java/com/eucalyptus/auth/CredentialProvider.java

- initial implementation of get/set property with support for static and db-singletons, tools in clc/tools/src/
- initial implementation of user control, tools in clc/tools/src
- basic stubs of client tools for register-component (only for CC right now)
- support for binding discovery (no need to seed bindings anymore)
- fixes invocation of defered initializers in the remote vs. local case
- support for pluggable "discovery" during bootstrap; e.g., see BootstrapperDiscovery

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
import com.eucalyptus.bootstrap.Depends;
80
80
import com.eucalyptus.bootstrap.Provides;
81
81
import com.eucalyptus.bootstrap.Resource;
82
 
import com.eucalyptus.util.DatabaseUtil;
83
 
import com.eucalyptus.util.EntityWrapper;
 
82
import com.eucalyptus.entities.DatabaseUtil;
 
83
import com.eucalyptus.entities.EntityWrapper;
84
84
import com.eucalyptus.util.EucalyptusCloudException;
85
85
import com.google.common.collect.Lists;
86
86
 
284
284
    return user;
285
285
  }
286
286
  
 
287
  public static List<User> getEnabledUsers( ) {
 
288
    EntityWrapper<User> db = Credentials.getEntityWrapper( );
 
289
    try {
 
290
      return db.query( new User( null, true ) );
 
291
    } finally {
 
292
      db.commit( );
 
293
    }
 
294
  }
 
295
 
287
296
  public static List<User> getAllUsers( ) {
288
297
    EntityWrapper<User> db = Credentials.getEntityWrapper( );
289
298
    try {
290
 
      return db.query( new User( null, true ) );
 
299
      return db.query( new User( null ) );
291
300
    } finally {
292
301
      db.commit( );
293
302
    }
294
303
  }
 
304
 
295
305
  
296
306
  public static User addUser( String userName, Boolean isAdmin, String queryId, String secretKey ) throws UserExistsException {
297
 
    User newUser = new User( userName, true );
 
307
    return CredentialProvider.addUser( userName, isAdmin, queryId, secretKey, true );
 
308
  }
 
309
  public static User addUser( String userName, Boolean isAdmin, String queryId, String secretKey, Boolean isEnabled ) throws UserExistsException {
 
310
    User newUser = new User( userName);
298
311
    newUser.setQueryId( queryId );
299
312
    newUser.setSecretKey( secretKey );
300
313
    newUser.setIsAdministrator( isAdmin );
 
314
    newUser.setIsEnabled( isEnabled );
301
315
    EntityWrapper<User> db = Credentials.getEntityWrapper( );
302
316
    try {
303
317
      db.add( newUser );
304
318
      db.commit( );
305
 
    } catch ( Exception e ) {
 
319
    } catch ( Throwable t ) {
306
320
      db.rollback( );
307
 
      throw new UserExistsException( e );
 
321
      throw new UserExistsException( t );
308
322
    }
309
323
    return newUser;
310
324
  }
311
 
  
 
325
 
 
326
  public static User addDisabledUser( String userName, Boolean isAdmin ) throws UserExistsException {
 
327
    String queryId = Hashes.getDigestBase64( userName, Hashes.Digest.SHA224, false ).replaceAll( "\\p{Punct}", "" );
 
328
    String secretKey = Hashes.getDigestBase64( userName, Hashes.Digest.SHA224, true ).replaceAll( "\\p{Punct}", "" );
 
329
    return CredentialProvider.addUser( userName, isAdmin, queryId, secretKey, false );
 
330
  }
312
331
  public static User addUser( String userName, Boolean isAdmin ) throws UserExistsException {
313
332
    String queryId = Hashes.getDigestBase64( userName, Hashes.Digest.SHA224, false ).replaceAll( "\\p{Punct}", "" );
314
333
    String secretKey = Hashes.getDigestBase64( userName, Hashes.Digest.SHA224, true ).replaceAll( "\\p{Punct}", "" );
344
363
      throw new NoSuchUserException( e );
345
364
    }
346
365
  }
 
366
  
 
367
  public static String generateConfirmationCode( String userName ) {
 
368
    return Hashes.getDigestBase64( userName, Hashes.Digest.SHA512, true ).replaceAll("\\p{Punct}", "" );
 
369
  }
 
370
 
 
371
  public static String generateCertificateCode( String userName ) {
 
372
    return Hashes.getDigestBase64( userName, Hashes.Digest.SHA512, true ).replaceAll("\\p{Punct}", "" );
 
373
  }
 
374
 
 
375
  public static String generateSecretKey( String userName ) {
 
376
    return Hashes.getDigestBase64( userName, Hashes.Digest.SHA224, true ).replaceAll("\\p{Punct}", "" );
 
377
  }
 
378
 
 
379
  public static String generateQueryId( String userName ) {
 
380
    return Hashes.getDigestBase64( userName, Hashes.Digest.MD5, false ).replaceAll("\\p{Punct}", "" );
 
381
  }
 
382
 
347
383
}