Skip to content

Commit d7851f1

Browse files
committed
Added OAuth based security example for agent and weather service
1 parent 5b497ed commit d7851f1

File tree

58 files changed

+4564
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4564
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.10/apache-maven-3.9.10-bin.zip
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Spring AI Agent
2+
3+
A comprehensive AI-powered agent built with Spring AI framework, featuring weather forecasting capabilities and secure OAuth integration.
4+
5+
## Related Documentation
6+
7+
This project is part of a larger microservices ecosystem:
8+
9+
- [Weather Service Documentation](../weather/README.md) - Weather forecast service with global coverage
10+
11+
## Project Overview
12+
13+
### Description
14+
15+
The Spring AI Agent is a demonstration of how to build modern AI-powered applications using the Spring AI framework. It provides weather forecasting capabilities through:
16+
17+
- Weather forecasts for any city worldwide
18+
- Integration with external weather APIs
19+
- Model Context Protocol (MCP) client for connecting to weather services
20+
- Secure OAuth authentication and authorization
21+
22+
The application serves as the central component in a microservices architecture, connecting to the Weather service through the Model Context Protocol (MCP).
23+
24+
### Purpose
25+
26+
This application serves as:
27+
28+
1. A reference implementation for Spring AI integration with weather services
29+
2. A demonstration of secure AI application patterns with OAuth
30+
3. A practical example of building weather assistants with Spring Boot
31+
4. A showcase for integrating with Amazon Bedrock and weather APIs
32+
33+
### Technology Stack
34+
35+
- **Java 21**: Latest LTS version with modern language features
36+
- **Spring Boot 3.5.7**: Core framework for building the application
37+
- **Spring AI 1.0.3**: AI integration framework
38+
- **Spring Security**: OAuth 2.0 authentication and authorization
39+
- **Amazon Bedrock**: AI model provider (Claude Sonnet 4)
40+
- **Docker**: Containerization for application
41+
42+
## Security
43+
44+
### OAuth 2.0 Integration
45+
46+
The application implements OAuth 2.0 for secure authentication and authorization:
47+
48+
- **Authorization Server**: Integrated OAuth 2.0 authorization server
49+
- **Resource Protection**: Secured API endpoints with JWT tokens
50+
- **Token Validation**: Automatic JWT token validation and user context
51+
52+
## Getting Started
53+
54+
### Prerequisites
55+
56+
- Java 21 or higher
57+
- Maven 3.8 or higher
58+
- AWS account with Amazon Bedrock access
59+
60+
### Prerequisites for Full Functionality
61+
62+
Before starting the AI agent, ensure the required services are running:
63+
64+
1. **Start Authorization Server** (port 9000):
65+
```bash
66+
cd ../authorization-server/
67+
mvn spring-boot:run
68+
```
69+
70+
2. **Start Weather Service** (port 8083):
71+
```bash
72+
cd ../weather/
73+
mvn spring-boot:run
74+
```
75+
76+
These services provide OAuth authentication and weather forecasting tools that the AI agent uses.
77+
78+
#### Running the AI Agent
79+
80+
```bash
81+
cd ai-agent/
82+
mvn spring-boot:run
83+
```
84+
85+
This will:
86+
- Configure secure endpoints for weather data access
87+
- Connect to the weather service via MCP for authenticated users only
88+
- Connect to the authorization server for OAuth authentication
89+
- Start the application on port 8080
90+
91+
#### Access Points
92+
93+
Once all applications are running, you can access:
94+
95+
- **Main Application**: `http://localhost:8080/`
96+
97+
### AWS Configuration
98+
99+
1. Configure AWS credentials:
100+
```bash
101+
aws configure
102+
```
103+
104+
2. Ensure you have access to Amazon Bedrock and the required models (Claude Sonnet 4).
105+
106+
### Building and Running the Application
107+
108+
1. **Standard Build and Run:**
109+
```bash
110+
cd ai-agent/
111+
mvn clean package
112+
mvn spring-boot:run
113+
```
114+
115+
2. The application will be available at:
116+
```
117+
http://localhost:8080/
118+
```
119+
120+
### Authentication Flow
121+
122+
1. Navigate to `http://localhost:9000/` (authorization server)
123+
2. Authenticate with your credentials
124+
3. Use the authorization code to obtain an access token
125+
4. Access weather endpoints with the Bearer token
126+
127+
## Contributing
128+
129+
Contributions are welcome! Please feel free to submit a Pull Request.
130+
131+
## License
132+
133+
This project is licensed under the MIT License - see the LICENSE file for details.

0 commit comments

Comments
 (0)