<commit_before>#
#   Licensed to the Apache Software Foundation (ASF) under one
#   or more contributor license agreements.  See the NOTICE file
#   distributed with this work for additional information
#   regarding copyright ownership.  The ASF licenses this file
#   to you under the Apache License, Version 2.0 (the
#   "License"); you may not use this file except in compliance
#   with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing,
#   software distributed under the License is distributed on an
#   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#   KIND, either express or implied.  See the License for the
#   specific language governing permissions and limitations
#   under the License.
#
___________________________________________________________________________________
###################################################################################
INSTRUCTIONS TO ENABLE FORTRESS REALM for a SINGLE Web Context under Tomcat
Last updated: February 9, 2015
-----------------------------------------------------------------------------------
###################################################################################
# Guidelines & Tips
###################################################################################
- This document describes how to enable Fortress Realm to provide security for
  a single context within a Tomcat server host.  Follow these steps and this component will be security
  provider for a single application within a particular Tomcat server instance.

- It is possible to enable Fortress Realm to provide security for all applications within a Tomcat server host.
  Follow the instructions in REALM-HOST-SETUP.txt.

- In the document that follows, replace "[version]" with Fortress Realm version label.
  For example - if Fortress Realm 1.0 release, change fortress-realm-proxy-[version].jar to fortress-realm-proxy-1.0.jar

- Restart Tomcat server after any changes to Tomcat config, Fortress config or lib files.

- Common misconfiguration issues related to Fortress, LDAP and Tomcat are located in section III.
___________________________________________________________________________________
###################################################################################
# SECTION 0.  Prerequisites for Fortress Realm installation and usage with Tomcat
###################################################################################
a. Internet access to retrieve source code from Apache Fortress Realm GIT and binary dependencies from online Maven repo.

b. Java SDK Version 7 or beyond installed to target environment

c. LDAP server installed and configured for Fortress.  (see README in Apache Fortress Core).

d. Apache Tomcat 7 or greater installed to local machine.
_________________________________________________________________________________
###################################################################################
# SECTION 1:  Prepare Machine
###################################################################################
a. Follow instructions in README.txt to build and install fortress realm.

b. copy fortress-realm-proxy-[version].jar to TOMCAT_HOME/lib/

# cp [directory-fortress-realm]/proxy/fortress-realm-proxy-[version].jar TOMCAT_HOME/lib

Where [directory-fortress-core] is base folder of the fortress core source package.

c. Restart tomcat server instance for changes to take effect.
_________________________________________________________________________________
###################################################################################
# SECTION 2:  Enable Tomcat Realm for Web context
###################################################################################
a. Add a context.xml file to the META-INF folder of target web app.

b. Add the following:

<Context path="/commander" reloadable="true">

    <Realm className="org.apache.directory.fortress.realm.tomcat.Tc7AccessMgrProxy"
           debug="0"
           resourceName="UserDatabase"
           defaultRoles=""
           containerType="TomcatContext"
           realmClasspath=""
            />

    </Context>

c. Add security constraints to target web.xml:

        <security-constraint>
            <display-name>Commander Security Constraint</display-name>
            <web-resource-collection>
                <web-resource-name>Protected Area</web-resource-name>
                <!-- Define the context-relative URL(s) to be protected -->
                <url-pattern>/*</url-pattern>
            </web-resource-collection>
            <auth-constraint>
                <!-- Anyone with one of the listed roles may access this area -->
                <role-name>MY_ROLE_NAME</role-name>
                ...

            </auth-constraint>
        </security-constraint>

    <!-- Example of HTTP Basic Authentication Setup. -->
    <login-config>
		<auth-method>BASIC</auth-method>
        <realm-name>FortressSecurityRealm</realm-name>
    </login-config>

    <!-- Security roles referenced by this web application -->
    <security-role>
        <role-name>MY_ROLE_NAME</role-name>
    </security-role>
    ...

Note:  Fortress Realm is compliant with Java EE security semantics.  The above is a one simple example.
For more info:
http://docs.oracle.com/javaee/6/tutorial/doc/bnbwj.html

d. Redeploy web application.

e. Login to the app.  Users that successfully authenticate and have activated at least one role listed in auth-constraints gain access to app resources matching the url-pattern.

f. View the server logs to ensure there are no errors.

g. verify that fortress realm is operating properly by viewing the following in catalina.log:

org.apache.directory.fortress.realm.tomcat.Tc7AccessMgrProxy J2EE Tomcat7 policy agent initialization successful
_________________________________________________________________________________
###################################################################################
# Common troubleshooting tips:
###################################################################################

Found inside REALM-HOST-SETUP.txt<commit_msg>FC-56 - minor realm how-to cleanup<commit_after>#
#   Licensed to the Apache Software Foundation (ASF) under one
#   or more contributor license agreements.  See the NOTICE file
#   distributed with this work for additional information
#   regarding copyright ownership.  The ASF licenses this file
#   to you under the Apache License, Version 2.0 (the
#   "License"); you may not use this file except in compliance
#   with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing,
#   software distributed under the License is distributed on an
#   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#   KIND, either express or implied.  See the License for the
#   specific language governing permissions and limitations
#   under the License.
#
___________________________________________________________________________________
###################################################################################
INSTRUCTIONS TO ENABLE FORTRESS REALM for a SINGLE Web Context under Tomcat
Last updated: February 9, 2015
-----------------------------------------------------------------------------------
###################################################################################
# Guidelines & Tips
###################################################################################
- This document describes how to enable Fortress Realm to provide security for
  a single context within a Tomcat server host.  Follow these steps and this component will be security
  provider for a single application within a particular Tomcat server instance.

- It is possible to enable Fortress Realm to provide security for all applications within a Tomcat server host.
  Follow the instructions in REALM-HOST-SETUP.txt.

- In the document that follows, replace "[version]" with Fortress Realm version label.
  For example - if Fortress Realm 1.0 release, change fortress-realm-proxy-[version].jar to fortress-realm-proxy-1.0.jar

- Restart Tomcat server after any changes to Tomcat config, Fortress config or lib files.

- Common misconfiguration issues related to Fortress, LDAP and Tomcat are located in section III.
___________________________________________________________________________________
###################################################################################
# SECTION 0.  Prerequisites for Fortress Realm installation and usage with Tomcat
###################################################################################
a. Internet access to retrieve source code from Apache Fortress Realm GIT and binary dependencies from online Maven repo.

b. Java SDK Version 7 or beyond installed to target environment

c. LDAP server installed and configured for Fortress.  (see README in Apache Fortress Core).

d. Apache Tomcat 7 or greater installed to local machine.
_________________________________________________________________________________
###################################################################################
# SECTION 1:  Prepare Machine
###################################################################################
a. Follow instructions in README.txt to build and install fortress realm.

b. copy fortress-realm-proxy-[version].jar to TOMCAT_HOME/lib/

# cp [directory-fortress-realm]/proxy/fortress-realm-proxy-[version].jar TOMCAT_HOME/lib

Where [directory-fortress-core] is base folder of the fortress core source package.

c. Restart tomcat server instance for changes to take effect.
_________________________________________________________________________________
###################################################################################
# SECTION 2:  Enable Tomcat Realm for Web context
###################################################################################
a. Add a context.xml file to the META-INF folder of target web app.

b. Add the following:

<Context path="/commander" reloadable="true">

    <Realm className="org.apache.directory.fortress.realm.tomcat.Tc7AccessMgrProxy"
           debug="0"
           resourceName="UserDatabase"
           defaultRoles=""
           containerType="TomcatContext"
           realmClasspath=""
            />
</Context>

c. Add security constraints to target web.xml:

        ...
        <security-constraint>
            <display-name>Commander Security Constraint</display-name>
            <web-resource-collection>
                <web-resource-name>Protected Area</web-resource-name>
                <!-- Define the context-relative URL(s) to be protected -->
                <url-pattern>/*</url-pattern>
            </web-resource-collection>
            <auth-constraint>
                <!-- Anyone with one of the listed roles may access this area -->
                <role-name>MY_ROLE_NAME</role-name>
                ...

            </auth-constraint>
        </security-constraint>

    <!-- Example of HTTP Basic Authentication Setup. -->
    <login-config>
		<auth-method>BASIC</auth-method>
        <realm-name>FortressSecurityRealm</realm-name>
    </login-config>

    <!-- Security roles referenced by this web application -->
    <security-role>
        <role-name>MY_ROLE_NAME</role-name>
    </security-role>
    ...

Note:  Fortress Realm follows standard Java EE security semantics.  The above is a very simple example.
For more info on how Java EE security is used:
http://docs.oracle.com/javaee/6/tutorial/doc/bnbwj.html

d. Redeploy web application to Tomcat.

e. Login to the web application.  Users that successfully authenticate and have activated role(s) listed in auth-constraints have access to all resources matching the url-pattern(s).

f. View the Tomcat server logs to ensure there are no errors.

g. Verify that fortress realm is operating properly by viewing the following in catalina.log:

org.apache.directory.fortress.realm.tomcat.Tc7AccessMgrProxy J2EE Tomcat7 policy agent initialization successful
_________________________________________________________________________________
###################################################################################
# Common troubleshooting tips:
###################################################################################

Found inside REALM-HOST-SETUP.txt
{'fraction_non_alphanumeric': 0.21565189671660823, 'fraction_numerical': 0.003984698756773988, 'mean_word_length': 4.033694344163658, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5158068', 'n_tokens_mistral': 2828, 'n_tokens_neox': 2678, 'n_words': 1088}