001: /*
002: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.romaframework.module.users.install;
018:
019: import java.security.NoSuchAlgorithmException;
020: import java.util.Date;
021:
022: import org.romaframework.aspect.persistence.PersistenceAspect;
023: import org.romaframework.core.flow.ObjectContext;
024: import org.romaframework.module.admin.InfoHelper;
025: import org.romaframework.module.admin.domain.Info;
026: import org.romaframework.module.admin.domain.InfoCategory;
027: import org.romaframework.module.admin.install.AdminApplicationInstaller;
028: import org.romaframework.module.users.ActivityLogCategories;
029: import org.romaframework.module.users.UsersHelper;
030: import org.romaframework.module.users.UsersInfoConstants;
031: import org.romaframework.module.users.domain.ActivityLog;
032: import org.romaframework.module.users.domain.BaseAccount;
033: import org.romaframework.module.users.domain.BaseProfile;
034:
035: public class UsersApplicationInstaller extends
036: AdminApplicationInstaller {
037:
038: protected BaseProfile pAdmin;
039: protected Info defStatus;
040:
041: @Override
042: public synchronized boolean install() {
043: if (!super .install())
044: return false;
045:
046: PersistenceAspect db = ObjectContext.getInstance()
047: .getComponent(PersistenceAspect.class);
048:
049: InfoCategory accountCategory = InfoHelper.getInstance()
050: .getInfoCategory(
051: UsersInfoConstants.ACCOUNT_CATEGORY_NAME);
052:
053: if (accountCategory != null)
054: return false;
055:
056: createInfos(db);
057: createProfiles();
058: try {
059: createAccounts();
060: } catch (NoSuchAlgorithmException e) {
061: e.printStackTrace();
062: }
063:
064: return true;
065: }
066:
067: protected void createInfos(PersistenceAspect db) {
068: InfoCategory cat = InfoHelper.getInstance().setInfoCategory(
069: UsersInfoConstants.ACCOUNT_CATEGORY_NAME);
070: defStatus = InfoHelper.getInstance().setInfo(cat,
071: UsersInfoConstants.STATUS_ACTIVE);
072: InfoHelper.getInstance().setInfo(cat,
073: UsersInfoConstants.STATUS_UNACTIVE);
074: InfoHelper.getInstance().setInfo(cat,
075: UsersInfoConstants.STATUS_SUSPENDED);
076:
077: InfoHelper.getInstance().setInfoCategory(
078: ActivityLog.LOG_CATEGORY_NAME);
079: InfoHelper.getInstance().setInfo(ActivityLog.LOG_CATEGORY_NAME,
080: ActivityLogCategories.CATEGORY_SYSTEM);
081: InfoHelper.getInstance().setInfo(ActivityLog.LOG_CATEGORY_NAME,
082: ActivityLogCategories.CATEGORY_LOGIN);
083: InfoHelper.getInstance().setInfo(ActivityLog.LOG_CATEGORY_NAME,
084: ActivityLogCategories.CATEGORY_ADMIN);
085: }
086:
087: protected void createAccounts() throws NoSuchAlgorithmException {
088: BaseAccount aAdmin = new BaseAccount();
089: aAdmin.setName("admin");
090: aAdmin.setPassword("admin");
091: aAdmin.setSignedOn(new Date());
092: aAdmin.setStatus(defStatus);
093: aAdmin.setLastModified(aAdmin.getSignedOn());
094: aAdmin.setProfile(pAdmin);
095:
096: UsersHelper.getInstance().setAccount(aAdmin);
097: }
098:
099: protected void createProfiles() {
100: pAdmin = new BaseProfile();
101: pAdmin.setName("Amministratore");
102: pAdmin.setHomePage("HomePage");
103: pAdmin.setMode(BaseProfile.MODE_ALLOW_ALL_BUT);
104: UsersHelper.getInstance().setProfile(pAdmin);
105: }
106: }
|