feat: implement PostgresClaimMappingRepository and wire beans
- JdbcTemplate-based CRUD for claim_mapping_rules table - RbacBeanConfig wires ClaimMappingRepository and ClaimMappingService beans Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
package com.cameleer3.server.app.config;
|
||||||
|
|
||||||
|
import com.cameleer3.server.app.storage.PostgresClaimMappingRepository;
|
||||||
|
import com.cameleer3.server.core.rbac.ClaimMappingRepository;
|
||||||
|
import com.cameleer3.server.core.rbac.ClaimMappingService;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the {@link ClaimMappingRepository} and {@link ClaimMappingService} beans.
|
||||||
|
* <p>
|
||||||
|
* Follows the established pattern: core module plain class, app module bean config.
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RbacBeanConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ClaimMappingRepository claimMappingRepository(JdbcTemplate jdbcTemplate) {
|
||||||
|
return new PostgresClaimMappingRepository(jdbcTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ClaimMappingService claimMappingService() {
|
||||||
|
return new ClaimMappingService();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.cameleer3.server.app.storage;
|
||||||
|
|
||||||
|
import com.cameleer3.server.core.rbac.ClaimMappingRepository;
|
||||||
|
import com.cameleer3.server.core.rbac.ClaimMappingRule;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PostgresClaimMappingRepository implements ClaimMappingRepository {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbc;
|
||||||
|
|
||||||
|
public PostgresClaimMappingRepository(JdbcTemplate jdbc) {
|
||||||
|
this.jdbc = jdbc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ClaimMappingRule> findAll() {
|
||||||
|
return jdbc.query("""
|
||||||
|
SELECT id, claim, match_type, match_value, action, target, priority, created_at
|
||||||
|
FROM claim_mapping_rules ORDER BY priority, created_at
|
||||||
|
""", (rs, i) -> new ClaimMappingRule(
|
||||||
|
rs.getObject("id", UUID.class),
|
||||||
|
rs.getString("claim"),
|
||||||
|
rs.getString("match_type"),
|
||||||
|
rs.getString("match_value"),
|
||||||
|
rs.getString("action"),
|
||||||
|
rs.getString("target"),
|
||||||
|
rs.getInt("priority"),
|
||||||
|
rs.getTimestamp("created_at").toInstant()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<ClaimMappingRule> findById(UUID id) {
|
||||||
|
var results = jdbc.query("""
|
||||||
|
SELECT id, claim, match_type, match_value, action, target, priority, created_at
|
||||||
|
FROM claim_mapping_rules WHERE id = ?
|
||||||
|
""", (rs, i) -> new ClaimMappingRule(
|
||||||
|
rs.getObject("id", UUID.class),
|
||||||
|
rs.getString("claim"),
|
||||||
|
rs.getString("match_type"),
|
||||||
|
rs.getString("match_value"),
|
||||||
|
rs.getString("action"),
|
||||||
|
rs.getString("target"),
|
||||||
|
rs.getInt("priority"),
|
||||||
|
rs.getTimestamp("created_at").toInstant()
|
||||||
|
), id);
|
||||||
|
return results.isEmpty() ? Optional.empty() : Optional.of(results.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID create(String claim, String matchType, String matchValue, String action, String target, int priority) {
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
jdbc.update("""
|
||||||
|
INSERT INTO claim_mapping_rules (id, claim, match_type, match_value, action, target, priority)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
|
""", id, claim, matchType, matchValue, action, target, priority);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(UUID id, String claim, String matchType, String matchValue, String action, String target, int priority) {
|
||||||
|
jdbc.update("""
|
||||||
|
UPDATE claim_mapping_rules
|
||||||
|
SET claim = ?, match_type = ?, match_value = ?, action = ?, target = ?, priority = ?
|
||||||
|
WHERE id = ?
|
||||||
|
""", claim, matchType, matchValue, action, target, priority, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(UUID id) {
|
||||||
|
jdbc.update("DELETE FROM claim_mapping_rules WHERE id = ?", id);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user