| By Philippe Cohen, Paolo de Nictolis | Article Rating: |
|
| October 31, 2007 02:00 PM EDT | Reads: |
15,709 |
Next, we need to enable the preset sa account for access via SQL Server Authentication since it's disabled in the default setting. From the same tool, expand Security > Logins > sa. Right-click and select Properties. Switch to Status page and set Login to Enabled. This sample assumes that you have a blank password for 'sa'. If not, update the password in the JavaDayConnectionString property in the Web.Config file.
Grasshopper's JDBC driver for SQL Server (which is the same as the one provided by Microsoft) supports connections via TCP/IP only, and not Named Pipes, so we'll enable TCP/IP connectivity from the SQL Server Configuration Manager.
Using Master Pages Templates
We'll use ASP.NET 2.0 Master Pages to provide a consistent template for each page. First, create a new application from the File > New > Project > Visual C# for Java EE project template. Make sure to launch the Tomcat Application Server that comes with Grasshopper 2.0.
Add a new Master Page and modify the graphic template using all the necessary ContentPlaceHolder elements; then add them to any page of the project using the MasterPageFile attribute in the @Page directive.
Role-Based Access Control
We can GUI-configure
role-based authentication features provided by Membership and the Role
API using Grasshopper's Web Site Administration Tool (WSAT), which
resides on a pure Java Apache Derby implementation rather than a
Microsoft SQL Express database. Grasshopper 2.0 uses the same
AttachFileDB mechanism and an analogous AspNetDerbyMembershipProvider
defined in the Mainsoft.Web.Security namespace.
Our JDExpenses application will use two components, corresponding to two sub-folders, relevant to authentication features: ExpensesManagement, which enables speakers to input their expenses, and BalancesReport, which will be used by the accounting team to retrieve the account data. The first component will be accessible by the speaker and admin roles; the second by admin only. Compile the application and launch the Grasshopper 2.0 version of the WSAT from the Visual Studio IDE or from within the application runtime via the URL http://localhost:8090/JDExpenses/aspnetconfig/Default.aspx. Then you'll create roles and users, and associate users to roles, using the usual wizard.
In the web.config file, define appropriate allow and deny rules as follows:
<location path="ExpensesManagement">
<system.web>
<authorization>
<allow roles="admin, speaker"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
<location path="BalancesReport">
<system.web>
<authorization>
<allow roles="admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
To change the default App_Data folder used to store authentication data, the system administrator responsible for application deployment will be able to change a new context parameter in the web.xml deployment file:
<context-param>
<param-name>DataDirectory</param-name>
<param-value>App_Data</param-value>
</context-param>
At runtime, the application developer will be able to retrieve the value of this parameter in the program itself:
(string)AppDomain.CurrentDomain.GetData("DataDirectory")
AppDomain.CurrentDomain.SetData("DataDirectory","/usr/tmp");
Controls for Accessing JDExpenses
We take advantage of the authentication tools offered by ASP.NET 2.0 using the Login
controls group of the Visual Studio 2005 Toolbox. In Default.aspx, add
two HyperLink controls and connect them to the ExpensesManagement.aspx
and BalancesReport.aspx pages through the NavigateUrl property. Since
both pages require authentication, the user will be redirected to a
page that contains the login form, which by default is Login.aspx. It's
possible to change the default page from web.config, but it's
unnecessary and would complicate this example.
Let's create a Login.aspx page in which we'll drag the Login control from the Toolbox and personalize its aspect using the associated Smart Tag. We normally assign a value to DestinationPageUrl and MembershipProvider, but in this case it's unnecessary. The destination page will be handled by the HyperLink that calls up Login.aspx handled by Grasshopper.
After logon, we add the classic welcome message and logout links personalized with the username, using LoginView, LoginName, and LoginStatus controls. We can achieve the same results working in the Code view of the page and inputting the simple code below:
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
Authenticated! Welcome,
</LoggedInTemplate>
<AnonymousTemplate>
You're not logged. Click over "Login"
</AnonymousTemplate>
</asp:LoginView>
Published October 31, 2007 Reads 15,709
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Philippe Cohen
Philippe Cohen is the vice president of products for Mainsoft Corporation, where he is responsible for overseeing product management, R&D, and support teams for Mainsoft's product suite.
More Stories By Paolo de Nictolis
Paolo de Nictolis is an Italian Web developer, a technical contributor to MSDN and UGI.NET, and a freelance IT journalist.
![]() |
jnsoneji 10/31/07 10:12:51 PM EDT | |||
Trackback Added: http://jnsoneji.spaces.live.com/Blog/cns!37E7335732E61C89!256.entry; Building Pure Java Apps Using Visual Studio |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?


































