1
package com.eucalyptus.auth;
3
import org.apache.log4j.Logger;
4
import com.eucalyptus.auth.util.AuthBootstrapHelper;
5
import com.eucalyptus.bootstrap.Bootstrap;
6
import com.eucalyptus.bootstrap.Bootstrapper;
7
import com.eucalyptus.bootstrap.Component;
8
import com.eucalyptus.bootstrap.DependsLocal;
9
import com.eucalyptus.bootstrap.Provides;
10
import com.eucalyptus.bootstrap.RunDuring;
11
import com.eucalyptus.bootstrap.Bootstrap.Stage;
12
import com.eucalyptus.entities.Counters;
13
import com.eucalyptus.entities.EntityWrapper;
14
import com.eucalyptus.entities.VmType;
16
@Provides( Component.bootstrap )
17
@RunDuring( Bootstrap.Stage.UserCredentialsInit )
18
public class DatabaseAuthBootstrapper extends Bootstrapper {
19
private static Logger LOG = Logger.getLogger( DatabaseAuthBootstrapper.class );
21
public static boolean ENABLE = true;
23
public boolean load( Stage current ) throws Exception {
25
DatabaseAuthProvider dbAuth = new DatabaseAuthProvider( );
26
Users.setUserProvider( dbAuth );
27
Groups.setGroupProvider( dbAuth );
28
UserInfoStore.setUserInfoProvider( dbAuth );
33
public boolean start( ) throws Exception {
35
this.checkUserEnabled( );
36
AuthBootstrapHelper.ensureStandardGroupsExists( );
37
AuthBootstrapHelper.ensureAdminExists( );
39
this.ensureCountersExist( );
40
this.ensureVmTypesExist( );
44
private void checkUserEnabled( ) {
45
EntityWrapper<UserEntity> db = Authentication.getEntityWrapper( );
46
for ( UserEntity u : db.query( new UserEntity( ) ) ) {
47
if ( u.isEnabled( ) != Boolean.FALSE ) {
48
u.setEnabled( Boolean.TRUE );
53
private void ensureVmTypesExist( ) {
54
EntityWrapper<VmType> db = new EntityWrapper<VmType>( "eucalyptus_general" );
56
if ( db.query( new VmType( ) ).size( ) == 0 ) { //TODO: make defaults configurable?
57
db.add( new VmType( "m1.small", 1, 2, 128 ) );
58
db.add( new VmType( "c1.medium", 1, 5, 256 ) );
59
db.add( new VmType( "m1.large", 2, 10, 512 ) );
60
db.add( new VmType( "m1.xlarge", 2, 20, 1024 ) );
61
db.add( new VmType( "c1.xlarge", 4, 20, 2048 ) );
64
} catch ( Exception e ) {
69
private void ensureCountersExist( ) {
70
Counters.getNextId( );