or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

annotation-support.mdindex.mdjndi-integration.mdsecurity-services.md

index.mddocs/

0

# Jetty Plus

1

2

JNDI support for Eclipse Jetty web server providing comprehensive enterprise Java features including dependency injection, lifecycle management, JNDI resource binding, and database-backed security services.

3

4

## Package Information

5

6

- **Package Name**: org.eclipse.jetty:jetty-plus

7

- **Language**: Java

8

- **Installation**: Maven: `<groupId>org.eclipse.jetty</groupId><artifactId>jetty-plus</artifactId><version>12.0.21</version>`

9

10

## Core Imports

11

12

```java

13

// Dependency injection and lifecycle management

14

import org.eclipse.jetty.plus.annotation.Injection;

15

import org.eclipse.jetty.plus.annotation.InjectionCollection;

16

import org.eclipse.jetty.plus.annotation.LifeCycleCallback;

17

import org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection;

18

import org.eclipse.jetty.plus.annotation.PostConstructCallback;

19

import org.eclipse.jetty.plus.annotation.PreDestroyCallback;

20

21

// JNDI resource binding

22

import org.eclipse.jetty.plus.jndi.NamingEntry;

23

import org.eclipse.jetty.plus.jndi.Resource;

24

import org.eclipse.jetty.plus.jndi.EnvEntry;

25

import org.eclipse.jetty.plus.jndi.Link;

26

import org.eclipse.jetty.plus.jndi.Transaction;

27

import org.eclipse.jetty.plus.jndi.DataSourceCloser;

28

import org.eclipse.jetty.plus.jndi.NamingEntryUtil;

29

30

// Database security

31

import org.eclipse.jetty.plus.security.DataSourceLoginService;

32

```

33

34

## Basic Usage

35

36

```java

37

import org.eclipse.jetty.plus.jndi.Resource;

38

import org.eclipse.jetty.plus.annotation.InjectionCollection;

39

import org.eclipse.jetty.plus.security.DataSourceLoginService;

40

import javax.sql.DataSource;

41

42

// 1. JNDI Resource Binding

43

// Bind a DataSource to JNDI for application use

44

DataSource dataSource = // ... your datasource configuration

45

Resource dsResource = new Resource("jdbc/MyDB", dataSource);

46

47

// 2. Dependency Injection Setup

48

// Configure injection collection for webapp

49

InjectionCollection injections = new InjectionCollection();

50

// Add to webapp context as attribute

51

context.setAttribute(InjectionCollection.INJECTION_COLLECTION, injections);

52

53

// 3. Database-backed Authentication

54

// Configure login service with database

55

DataSourceLoginService loginService = new DataSourceLoginService("MyRealm");

56

loginService.setJndiName("jdbc/MyDB");

57

loginService.setUserTableName("users");

58

loginService.setUserTableUserField("username");

59

loginService.setUserTablePasswordField("password");

60

loginService.setRoleTableName("roles");

61

server.addBean(loginService);

62

```

63

64

## Architecture

65

66

The jetty-plus module is organized into three main functional areas:

67

68

- **Annotation Support**: Handles JavaEE-style dependency injection and lifecycle callbacks (@PostConstruct, @PreDestroy)

69

- **JNDI Integration**: Provides comprehensive JNDI naming services for resource binding and lookup

70

- **Security Services**: Database-backed authentication and authorization through JNDI DataSources

71

72

This modular design allows applications to use only the features they need while maintaining full JEE compatibility for enterprise Java applications.

73

74

## Capabilities

75

76

### Dependency Injection and Lifecycle Management

77

78

Complete annotation-based dependency injection system with lifecycle callback support. Handles @Resource, @PostConstruct, and @PreDestroy annotations for enterprise Java applications.

79

80

```java { .api }

81

// Core injection functionality

82

class Injection {

83

Injection(Class<?> clazz, Field field, Class<?> resourceType, String jndiName, String mappingName);

84

Injection(Class<?> clazz, Method method, Class<?> arg, Class<?> resourceType, String jndiName, String mappingName);

85

void inject(Object injectable);

86

Object lookupInjectedValue() throws NamingException;

87

}

88

89

class InjectionCollection {

90

void add(Injection injection);

91

Set<Injection> getInjections(String className);

92

void inject(Object injectable);

93

}

94

95

// Lifecycle management

96

class LifeCycleCallbackCollection {

97

void add(LifeCycleCallback callback);

98

void callPostConstructCallback(Object o) throws Exception;

99

void callPreDestroyCallback(Object o) throws Exception;

100

}

101

```

102

103

[Dependency Injection and Lifecycle](./annotation-support.md)

104

105

### JNDI Resource Binding

106

107

Comprehensive JNDI naming and resource binding capabilities. Supports environment entries, resources, links, and transactions with full webapp context integration.

108

109

```java { .api }

110

// Core JNDI functionality

111

abstract class NamingEntry {

112

void bindToENC(String localName) throws NamingException;

113

void unbindENC();

114

String getJndiName();

115

}

116

117

class Resource extends NamingEntry {

118

Resource(Object scope, String jndiName, Object objToBind) throws NamingException;

119

Resource(String jndiName, Object objToBind) throws NamingException;

120

}

121

122

class NamingEntryUtil {

123

static boolean bindToENC(Object scope, String asName, String mappedName) throws NamingException;

124

static Object lookup(Object scope, String jndiName) throws NamingException;

125

static Context getContextForScope(Object scope) throws NamingException;

126

}

127

```

128

129

[JNDI Resource Binding](./jndi-integration.md)

130

131

### Database Security Services

132

133

Database-backed authentication and authorization using JNDI DataSources. Configurable user/role schema with full Jetty security integration.

134

135

```java { .api }

136

class DataSourceLoginService extends AbstractLoginService {

137

DataSourceLoginService();

138

DataSourceLoginService(String name);

139

140

// Configuration

141

void setJndiName(String jndi);

142

void setUserTableName(String name);

143

void setUserTableUserField(String tableUserField);

144

void setUserTablePasswordField(String tablePasswordField);

145

void setRoleTableName(String tableName);

146

147

// Core authentication

148

UserPrincipal loadUserInfo(String username);

149

List<RolePrincipal> loadRoleInfo(UserPrincipal user);

150

}

151

```

152

153

[Database Security Services](./security-services.md)

154

155

## Dependencies

156

157

**Required Dependencies:**

158

- `org.eclipse.jetty:jetty-security` - Core Jetty security framework

159

- `org.eclipse.jetty:jetty-util` - Jetty utilities

160

- `org.slf4j:slf4j-api` - Logging framework

161

162

**Module Requirements:**

163

- `java.naming` - Java Naming and Directory Interface

164

- `java.sql` - SQL database connectivity (for DataSourceLoginService)

165

166

## Common Integration Patterns

167

168

### Webapp Context Configuration

169

170

```java

171

// Configure JNDI and injection for a webapp

172

WebAppContext webapp = new WebAppContext();

173

174

// Set up injection collection

175

InjectionCollection injections = new InjectionCollection();

176

webapp.setAttribute(InjectionCollection.INJECTION_COLLECTION, injections);

177

178

// Set up lifecycle callbacks

179

LifeCycleCallbackCollection callbacks = new LifeCycleCallbackCollection();

180

webapp.setAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION, callbacks);

181

182

// Bind JNDI resources

183

Resource dataSource = new Resource(webapp, "jdbc/MyDB", myDataSource);

184

EnvEntry maxConnections = new EnvEntry(webapp, "maxConnections", 100);

185

```

186

187

### Enterprise Application Setup

188

189

```java

190

// Complete enterprise setup combining all features

191

Server server = new Server();

192

193

// Database login service

194

DataSourceLoginService loginService = new DataSourceLoginService("MyRealm");

195

loginService.setJndiName("jdbc/SecurityDB");

196

loginService.setCreateTables(false);

197

server.addBean(loginService);

198

199

// Security handler with database authentication

200

SecurityHandler security = new SecurityHandler();

201

security.setLoginService(loginService);

202

203

// Webapp with JNDI and injection support

204

WebAppContext webapp = new WebAppContext();

205

webapp.setSecurityHandler(security);

206

207

// Configure JNDI resources

208

Resource securityDB = new Resource("jdbc/SecurityDB", createSecurityDataSource());

209

Resource appDB = new Resource("jdbc/AppDB", createApplicationDataSource());

210

211

// Transaction support

212

Transaction.bindTransactionToENC(webapp.toString());

213

```