OSDN Git Service

アカウントに管理者属性を追加
authorsenju <senju@users.sourceforge.jp>
Tue, 18 Aug 2009 04:51:10 +0000 (13:51 +0900)
committersenju <senju@users.sourceforge.jp>
Tue, 18 Aug 2009 04:51:10 +0000 (13:51 +0900)
Accoutモデル変更。
最初の管理者を設定ファイルで設定可能に。
@Service属性ついてると自動で作成されてしまうので除去。

src/jp/sourceforge/rabbitBTS/models/Account.java
src/jp/sourceforge/rabbitBTS/services/AccountService.java
war/WEB-INF/rabbitBTS-servlet.xml

index 9453a89..289f16a 100644 (file)
@@ -70,6 +70,12 @@ public class Account {
        @Persistent
        private Date lastAccess;
 
+       /**
+        * 管理者権限を持つかどうか
+        */
+       @Persistent
+       private boolean isAdmin;
+
        public Long getAccountId() {
                return this.accountId;
        }
@@ -134,4 +140,19 @@ public class Account {
        public void setEmail(String email) {
                this.email = email;
        }
+
+       /**
+        * @return the isAdmin
+        */
+       public boolean isAdmin() {
+               return this.isAdmin;
+       }
+
+       /**
+        * @param isAdmin
+        *            the isAdmin to set
+        */
+       public void setAdmin(boolean isAdmin) {
+               this.isAdmin = isAdmin;
+       }
 }
index c953709..7293d38 100644 (file)
@@ -29,8 +29,6 @@ import jp.sourceforge.rabbitBTS.exceptions.NotRegisteredException;
 import jp.sourceforge.rabbitBTS.exceptions.RabbitBTSException;
 import jp.sourceforge.rabbitBTS.models.Account;
 
-import org.springframework.stereotype.Service;
-
 import com.google.appengine.api.users.User;
 
 /**
@@ -38,10 +36,14 @@ import com.google.appengine.api.users.User;
  * 
  * @author senju
  */
-@Service()
 public class AccountService {
 
        /**
+        * システムに最初管理者として登録されるユーザーのアドレス
+        */
+       private String firstSuperUser;
+
+       /**
         * 現在ログイン中のgoogleアカウントのアカウントを取得する。
         * 
         * @return 取得したアカウント。ログインしていない場合はnull
@@ -92,6 +94,13 @@ public class AccountService {
                                // OK
                        }
 
+                       // 最初のスーパーユーザーかチェック
+                       if (account.getEmail().equals(this.firstSuperUser)) {
+                               account.setAdmin(true);
+                               Sht.log(this).warning(
+                                               "Admin Account Created. " + this.firstSuperUser);
+                       }
+
                        // 登録処理
                        account.setLastAccess(new Date());
                        pm.makePersistent(account);
@@ -105,4 +114,19 @@ public class AccountService {
                        }
                }
        }
+
+       /**
+        * @return the firstSuperUser
+        */
+       public String getFirstSuperUser() {
+               return this.firstSuperUser;
+       }
+
+       /**
+        * @param firstSuperUser
+        *            the firstSuperUser to set
+        */
+       public void setFirstSuperUser(String firstSuperUser) {
+               this.firstSuperUser = firstSuperUser;
+       }
 }
index 3b544e8..dde7a1c 100644 (file)
                class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"
                /> <bean class="jp.sourceforge.rabbitBTS.TestAspect" />
        -->
+       
+       <bean class="jp.sourceforge.rabbitBTS.services.AccountService">
+       <property name="firstSuperUser" value="test@example.com" />
+       </bean>
+       
        <!-- validator -->
        <bean id="configurationLoader"
                class="org.springmodules.validation.bean.conf.loader.annotation.AnnotationBeanValidationConfigurationLoader" />