Grailsインストール+簡単な認証付きアプリをサックリ作成して動作確認。
いまさらだけど書いてみる
- ここからダウンロード → http://grails.org/Download
ダウンロードページからBinary ZIPあたりをダウンロード
ダウンロードしたzipファイルを解凍
- 環境変数設定
解凍先が/opt/grails-1.0.3の場合
$ export GRAILS_HOME=/opt/grails-1.0.3
- PATHを通す
$ export PATH=$PATH:$GRAILS_HOME/bin
- 動作確認(1)
$ grails Welcome to Grails 1.0.3 - http://grails.org/ Licensed under Apache Standard License 2.0 Grails home is set to: /opt/grails-1.0.3
- 動作確認(2)
$ grails create-app simple ←アプリ作成 ..省略.. [copy] Copying 1 file to /works/tmp/junk/simple [copy] Copying 1 file to /works/tmp/junk/simple [copy] Copying 1 file to /works/tmp/junk/simple [copy] Copying 1 file to /works/tmp/junk/simple [propertyfile] Updating property file: /works/tmp/junk/simple/application.properties Created Grails Application at /works/tmp/junk/simple $ cd simple ←ディレクトリに移動 $ grails create-domain-class message ← ドメインクラス作成 $ tee grails-app/domain/Message.groovy <<EOF ←ドメインクラス編集 class Message { String title String message Date dateCreated Date lastUpdated static constraints = { title(nullable:false) message(maxSize:5000) } } EOF $ grails generate-all Message ←スカッフォルド実行 ..省略.. Generating views for domain class Message ... Generating controller for domain class Message ... Finished generation for domain class Message $ grails run-app ←アプリ起動 ..省略.. 2008-09-15 16:27:49.903:/simple:INFO: Initializing Spring FrameworkServlet 'grails' 2008-09-15 16:27:49.034::INFO: Started SelectChannelConnector@0.0.0.0:8080 Server running. Browse to http://localhost:8080/simple
ブラウザで確認、http://localhost:8080/simple/
- 動作確認(3) 認証を・・
↓ Acegiプラグインインストール $ grails install-plugin http://svn.codehaus.org/grails-plugins/grails-acegi/tags/RELEASE_0_3/grails-acegi-0.3.zip ..省略.. Loading with installed plug-ins: ["acegi"] ... Executing acegi-0.3 plugin post-install script ... Plugin acegi-0.3 installed Plug-in provides the following new scripts: ------------------------------------------ grails create-auth-domains grails generate-manager grails generate-registration grails security-targets $ grails create-auth-domains ← 認証用ドメイン生成 $ grails generate-manager ← 仮の認証用ドメイン管理ページなど生成 $ grails run-app ←アプリ起動
ロールを追加
http://localhost:8080/simple/role/create
ユーザを追加
http://localhost:8080/simple/user/create
権限を追加
http://localhost:8080/simple/requestmap/create
以下のページをみようとすると・・
http://localhost:8080/simple/message
ログインページへ飛ばされます。
http://localhost:8080/simple/login/auth
作成したユーザID&パスワードでログインできます。