public OUser createMetadata ( ) { final ODatabaseDocument database = getDatabase ( ) ; OClass identityClass = database . getMetadata ( ) . getSchema ( ) . getClass ( OIdentity . CLASS_NAME ) ; // SINCE 1.2.0 if ( identityClass == null ) identityClass = database . getMetadata ( ) . getSchema ( ) . createAbstractClass ( OIdentity . CLASS_NAME ) ; OClass roleClass = createOrUpdateORoleClass ( database , identityClass ) ; createOrUpdateOUserClass ( database , identityClass , roleClass ) ; // CREATE ROLES AND USERS ORole adminRole = getRole ( ORole . ADMIN ) ; if ( adminRole == null ) { adminRole = createRole ( ORole . ADMIN , ORole . ALLOW_MODES . ALLOW_ALL_BUT ) ; adminRole . addRule ( ORule . ResourceGeneric . BYPASS_RESTRICTED , null , ORole . PERMISSION_ALL ) . save ( ) ; } OUser adminUser = getUser ( OUser . ADMIN ) ; if ( adminUser == null ) { // This will return the global value if a local storage context configuration value does not exist. boolean createDefUsers = getDatabase ( ) . getStorage ( ) . getConfiguration ( ) . getContextConfiguration ( ) . getValueAsBoolean ( OGlobalConfiguration . CREATE_DEFAULT_USERS ) ; if ( createDefUsers ) { adminUser = createUser ( OUser . ADMIN , OUser . ADMIN , adminRole ) ; } } // SINCE 1.2.0 createOrUpdateORestrictedClass ( database ) ; return adminUser ; }
Repairs the security structure if broken by creating the ADMIN role and user with default password .