Tag Archives: JSP

How to Secure a Stand-Alone Web Application in JBoss EAP

SampleServlet.java

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.HttpConstraint;
import javax.servlet.annotation.ServletSecurity;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
@WebServlet(name = "SampleServlet", value = "/")
@ServletSecurity(@HttpConstraint(rolesAllowed = "SampleRole"))
public final class SampleServlet extends HttpServlet {

  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException, ServletException {
    final RequestDispatcher dispatcher = req.getRequestDispatcher("/WEB-INF/jsp/index.jsp");

    dispatcher.forward(req, resp);
  }

}

index.jsp


<html>
<head>
  <title>Sample Application</title>
</head>
<body>
  <p><%=request.getRemoteUser()%></p>
  <p><%=request.isUserInRole("SampleRole")%></p>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <login-config>
    <auth-method>BASIC</auth-method> <!-- for HTTP basic authentication -->
    <realm-name>SampleSecurityDomain</realm-name>
  </login-config>
  <security-role>
    <role-name>SampleRole</role-name>
  </security-role>
</web-app>

jboss-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
  <security-domain>SampleSecurityDomain</security-domain>
  <use-jboss-authorization>true</use-jboss-authorization> <!--- default is false -->
  <disabled-audit>false</disable-audit> <!-- default is true -->
</jboss-web>

standalone.xml

<?xml version='1.0' encoding='UTF-8'?>
<server xmlns="urn:jboss:domain:1.3">
  ...
  <profile>
    ...
    <subsystem xmlns="urn:jboss:domain:security:1.2">
      ...
      <security-domains>
        ...
        <security-domain name="SampleSecurityDomain" cache-type="...">
          <mapping>
            <mapping-module code="..." type="..."/>
          </mapping>
          <authentication>
            <login-module code="..." flag="..."/>
          </authentication>
          <authorization>
            <policy-module code="..." flag="..."/>
          </authorization>
          <audit>
            <provider-module code="..."/>
          </audit>
        </security-domain>
      </security-domains>
    </subsystem>
    ...
  </profile>
  ...
</server>

A sample is available here.

Advertisements

How to Create your First Spring Framework Application for GAE

1) Create the application in the console.

2) Add your account to the Maven settings:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>appengine.google.com</id>
      <username><!-- Username --></username>
      <password><!-- Password --></password> <!-- Optional -->
    </server>
  </servers>
  <profiles>
    <profile>
      <id>appengine</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <gae.version>1.7.2</gae.version>
      </properties>
    </profile>
  </profiles>
</settings>

3) Add the Maven GAE Plugin to your project:

<plugin>
  <groupId>net.kindleit</groupId>
  <artifactId>maven-gae-plugin</artifactId>
  <version>0.9.4</version>
  <configuration>
    <serverId>appengine.google.com</serverId>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>net.kindleit</groupId>
      <artifactId>gae-runtime</artifactId>
      <version>1.7.2</version>
      <type>pom</type>
    </dependency>
  </dependencies>
</plugin>

4) Execute the gae:deploy goal to deploy.

A sample is available here.

How to Create your First Java EE Application for GAE

1) Create the application in the console.

2) Add your account to the Maven settings:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>appengine.google.com</id>
      <username><!-- Username --></username>
      <password><!-- Password --></password> <!-- Optional -->
    </server>
  </servers>
  <profiles>
    <profile>
      <id>appengine</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <gae.version>1.7.2</gae.version>
      </properties>
    </profile>
  </profiles>
</settings>

3) Add the Maven GAE Plugin to your project:

<plugin>
  <groupId>net.kindleit</groupId>
  <artifactId>maven-gae-plugin</artifactId>
  <version>0.9.4</version>
  <configuration>
    <serverId>appengine.google.com</serverId>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>net.kindleit</groupId>
      <artifactId>gae-runtime</artifactId>
      <version>1.7.2</version>
      <type>pom</type>
    </dependency>
  </dependencies>
</plugin>

4) Execute the gae:deploy goal to deploy.

A sample is available here.

How to Create your First Spring Framework Application for Jelastic

1) Create the environment in the console.

2) Add your account to the Maven settings:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <profiles>
    <profile>
      <id>jelastic</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <jelastic.username><!-- Username --></jelastic.username>
        <jelastic.password><!-- Password --></jelastic.password>
      </properties>
    </profile>
  </profiles>
</settings>

3) Add the Maven Plugin for Jelastic Cloud Platform to your project:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.jelastic</groupId>
        <artifactId>jelastic-maven-plugin</artifactId>
        <version>1.6</version>
        <configuration>
          <context>ROOT</context>
          <environment><!-- Environment Name --></environment>
          <api_hoster><!-- Hoster's API as in http://jelastic.com/docs/jelastic-hoster-info --></api_hoster>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <pluginRepositories>
    <pluginRepository>
      <id>sonatype-oss-public</id>
      <url>https://oss.sonatype.org/content/groups/public</url>
    </pluginRepository>
  </pluginRepositories>
</project>

4) Execute the jelastic:deploy goal to deploy.

You can find more details here.

A sample is available here.

How to Create your First Java EE Application for Jelastic

1) Create the environment in the console.

2) Add your account to the Maven settings:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <profiles>
    <profile>
      <id>jelastic</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <jelastic.username><!-- Username --></jelastic.username>
        <jelastic.password><!-- Password --></jelastic.password>
      </properties>
    </profile>
  </profiles>
</settings>

3) Add the Maven Plugin for Jelastic Cloud Platform to your project:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.jelastic</groupId>
        <artifactId>jelastic-maven-plugin</artifactId>
        <version>1.6</version>
        <configuration>
          <context>ROOT</context>
          <environment><!-- Environment Name --></environment>
          <api_hoster><!-- Hoster's API as in http://jelastic.com/docs/jelastic-hoster-info --></api_hoster>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <pluginRepositories>
    <pluginRepository>
      <id>sonatype-oss-public</id>
      <url>https://oss.sonatype.org/content/groups/public</url>
    </pluginRepository>
  </pluginRepositories>
</project>

4) Execute the jelastic:deploy goal to deploy.

You can find more details here.

A sample is available here.

How to Create your First Spring Framework Application for Microsoft Azure

1) Install the Windows Azure Plugin for Eclipse with Java.

2) Setup your account.

3) Click on the “New Windows Azure Deployment Project” button in the Windows Azure Toolbar to create a deployment project.

4) Rename the <Worker Role Instance ID>/approot/<Tomcat Install Dir>/webapps/ROOT folder to ROOT.old.

5) Click on the “Publish to Windows Azure Cloud” button in the toolbar.

You can find more information here.

A sample is available here.

How to Create your First Java EE Application for Microsoft Azure

1) Install the Windows Azure Plugin for Eclipse with Java.

2) Setup your account.

3) Click on the “New Windows Azure Deployment Project” button in the Windows Azure Toolbar to create a deployment project.

4) Rename the <Worker Role Instance ID>/approot/<Tomcat Install Dir>/webapps/ROOT folder to ROOT.old. You may also want to remove the HelloWorld.war file.

5) Click on the “Publish to Windows Azure Cloud” button in the toolbar.

You can find more information here.

A sample is available here.