16.10.2015 Views

Getting Started with WebSphere Application Server

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

152 <strong>Getting</strong> <strong>Started</strong> <strong>with</strong> <strong>WebSphere</strong> <strong>Application</strong> <strong>Server</strong> Community Edition<br />

props.put("java.naming.factory.initial",<br />

"org.openejb.client.RemoteInitialContextFactory");<br />

props.put(Context.SECURITY_PRINCIPAL, "andy");<br />

props.put(Context.SECURITY_CREDENTIALS, "aaa");<br />

props.put("openejb.authentication.realmName","helloRealm");<br />

InitialContext ctx = new InitialContext(props);<br />

Listing 8.10 - Initial properties<br />

8.3.3 Implementing Web security<br />

This section describes how to implement declarative and programmatic Web security.<br />

8.3.3.1 Declarative security<br />

Declarative security restricts access to URLs, such as servlets, JSPs, or even HTTP files or images<br />

served by the Web container through deployment descriptors (web.xml) of the Web application. Listing<br />

8.11 provides an example where you insert in web.xml the roles that will access the Web project.<br />

<br />

super_user<br />

<br />

Listing 8.11 - Declarative security referencing roles in web.xml<br />

Listing 8.12 provides an example where you define role constraints. In the example, the super user can<br />

access the resources where the URI matches the pattern /jsp/* <strong>with</strong> the GET and POST methods.<br />

Listing 8.13 shows the code needed to configure the authentication method.<br />

<br />

<br />

Protected Resource<br />

/jsp/*<br />

GET<br />

POST<br />

<br />

<br />

super_user<br />

<br />

<br />

Listing 8.12 - Security constraint<br />

<br />

BASIC<br />

helloRealm<br />

<br />

Listing 8.13 - Configuring the authentication method

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!