<commit_before># Java SDK for Castle

**[Castle](https://castle.io) adds real-time monitoring of your authentication stack,
instantly notifying you and your users on potential account hijacks.**

To generate the javadoc documentation run:

    mvn clean compile javadoc:javadoc

The javadoc will be located inside the `target/site` directory.

To check test coverage run:

    mvn clean test jacoco:report

The coverage report will be on the page `target/jacoco-ut/index.html`

# Development branch

Branch for development process. The castle-java-example application have a parallel dev branch for test proposes.

To use on example application dev branch, first install locally:

    mvn clean install


# Quickstart

When using Maven, add the following dependency to your `pom.xml` file:
```xml
        <dependency>
            <groupId>io.castle</groupId>
            <artifactId>castle-java</artifactId>
            <version>1.0.2</version>
        </dependency>
```

Go to the settings page of your Castle account and find your **API Secret** and (optionally) your **APP ID**.
Then create a new file named `castle_sdk.properties` with the following content:

```properties
app_id=<API_Secret>
api_secret=<APP_ID>

```

All other settings will be set to their default values.

Place the file in your classpath (for instance in `src/main/resources`).

Next, the SDK must be properly initialized, so that some configuration errors are discovered early.
Make sure this line of code is executed once during the initialization of the application using the SDK:

```java
Castle.verifySdkConfigurationAndInitialize();
```

Once the SDK has been initialized, it suffices to get an instance of the `io.castle.client.api.CastleApi` interface
in the following manner:

```java
CastleApi newAPIRef = Castle.sdk().onRequest(req)
```

Here `req` is an instance of `HttpServletRequest`.

Note that the `req` instance should be bound to the underlying request in order to extract the necessary information.
It means that a safe place to create the `CastleApi` instance is the request handling thread. After creation the
`CastleApi` instance can be passed to any thread independently of the original thread life cycle.

When using Castle.js, calculate a SHA-256 HMAC in hex format using the following javascript code when calling identify:

```
                _castle('secure',
                    '<%= Castle.sdk().secureUserID(someUserID) %>');
```<commit_msg>Add information for jdk 7. Fix #11<commit_after># Java SDK for Castle

**[Castle](https://castle.io) adds real-time monitoring of your authentication stack,
instantly notifying you and your users on potential account hijacks.**

To generate the javadoc documentation run:

    mvn clean compile javadoc:javadoc

The javadoc will be located inside the `target/site` directory.

To check test coverage run:

    mvn clean test jacoco:report

The coverage report will be on the page `target/jacoco-ut/index.html`

# Development branch

Branch for development process. The castle-java-example application have a parallel dev branch for test proposes.

To use on example application dev branch, first install locally:

    mvn clean install


# Quickstart

When using Maven, add the following dependency to your `pom.xml` file:
```xml
        <dependency>
            <groupId>io.castle</groupId>
            <artifactId>castle-java</artifactId>
            <version>1.0.2</version>
        </dependency>
```

Go to the settings page of your Castle account and find your **API Secret** and (optionally) your **APP ID**.
Then create a new file named `castle_sdk.properties` with the following content:

```properties
app_id=<API_Secret>
api_secret=<APP_ID>

```

All other settings will be set to their default values.

Place the file in your classpath (for instance in `src/main/resources`).

Next, the SDK must be properly initialized, so that some configuration errors are discovered early.
Make sure this line of code is executed once during the initialization of the application using the SDK:

```java
Castle.verifySdkConfigurationAndInitialize();
```

Once the SDK has been initialized, it suffices to get an instance of the `io.castle.client.api.CastleApi` interface
in the following manner:

```java
CastleApi newAPIRef = Castle.sdk().onRequest(req)
```

Here `req` is an instance of `HttpServletRequest`.

Note that the `req` instance should be bound to the underlying request in order to extract the necessary information.
It means that a safe place to create the `CastleApi` instance is the request handling thread. After creation the
`CastleApi` instance can be passed to any thread independently of the original thread life cycle.

When using Castle.js, calculate a SHA-256 HMAC in hex format using the following javascript code when calling identify:

```
                _castle('secure',
                    '<%= Castle.sdk().secureUserID(someUserID) %>');
```

## Java 7 configuration

To use the library on a java 7 environment, switch the guava library to the following version:
```xml
        <dependency>
            <groupId>io.castle</groupId>
            <artifactId>castle-java</artifactId>
            <version>1.0.2</version>
            <exclusions>
                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>23.0-android</version>
        </dependency>
```

{'fraction_non_alphanumeric': 0.0818942495994303, 'fraction_numerical': 0.004094712479971515, 'mean_word_length': 3.5379644588045234, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3153234', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1433, 'n_words': 643}