Repository navigation
Expand file tree
/
Copy pathSecurityPolicyChecker.java
More file actions
81 lines (81 loc) · 3.05 KB
/
Copy pathSecurityPolicyChecker.java
File metadata and controls
81 lines (81 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//package com.abn.design.leetcode;
//
//import java.util.ArrayDeque;
//import java.util.ArrayList;
//import java.util.Deque;
//import java.util.List;
//import java.util.Stack;
//
//public class SecurityPolicyChecker {
//
// /**
// * Parses an Okta routing policy string. Validates syntax and extracts the deepest sub-expression.
// * @param expression The raw string policy to validate and parse.
// * @return The inner-most core expression string.
// */
// public List<String> parseAndExtractDeepest(String expression) {
// if (expression == null || expression.isEmpty()) {
// return List.of();
// }
//
// // --- Pass 1: validate + find maxDepth ---
// Deque<Integer> stack = new ArrayDeque<>();
// int maxDepth = 0;
// int depth = 0;
//
// for (int i = 0; i < expression.length(); i++) {
// char c = expression.charAt(i);
// if (c == '(') {
// stack.push(i);
// depth++;
// maxDepth = Math.max(maxDepth, depth);
// } else if (c == ')') {
// if (stack.isEmpty()) throw new IllegalArgumentException(
// "Unbalanced closing bracket at index " + i);
// stack.pop();
// depth--;
// }
// }
// if (!stack.isEmpty()) throw new IllegalArgumentException(
// "Unbalanced opening bracket(s) remain unclosed.");
// // --- Pass 2: collect every substring that sits at maxDepth ---
// List<String> results = new ArrayList<>();
// depth = 0;
// int start = -1;
//
// for (int i = 0; i < expression.length(); i++) {
// char c = expression.charAt(i);
// if (c == '(') {
// depth++;
// if (depth == maxDepth) start = i; // entered a maxDepth group
// } else if (c == ')') {
// if (depth == maxDepth && start != -1) {
// results.add(expression.substring(start + 1, i).trim());
// start = -1;
// }
// depth--;
// }
// }
//
// return results;
//
// }
//
// public static void main(String[] args) {
// com.abn.dsalgos.algo.twoPointers.SecurityPolicyChecker parser = new com.abn.dsalgos.algo.twoPointers.SecurityPolicyChecker();
//
// // Example Happy Path
// String validPolicy = "((Group == 'Eng') AND (Location == 'US') AND (((device == 'iPhone'))) AND (((OS == 'iOS'))))";
// System.out.println("Deepest Rule Found: " + parser.parseAndExtractDeepest(validPolicy));
// // Output: Group == 'Eng'
//
// // Example Error Path (Unbalanced)
// try {
// String brokenPolicy = "((Group == 'Eng')";
// parser.parseAndExtractDeepest(brokenPolicy);
// } catch (IllegalArgumentException e) {
// System.out.println("\nCaught expected framework error: " + e.getMessage());
// // Output: Malformed policy: Unbalanced opening bracket(s) remain unclosed.
// }
// }
//}