KerberosUserMapper extends AbstractUserMapper { @Override public String map(String name) { Context context = new Context(); KerberosName principal = new KerberosName(name); context.put("principal", principal.getFullName()); context.put("primary", principal.getPrimary()); context.put("instance", principal.getInstance()); context.put("realm", principal.getRealm()); for (Rule rule : rulesList) { boolean isApplicable = rule.evaluateIfCondition(context); if (isApplicable) { return rule.evaluateThenExpression(context); } } throw new IllegalArgumentException("Principal `" + name + "` cannot be mapped to a Google identity."); } KerberosUserMapper(); @Override String map(String name);  }
@Test public void testMapKerberosName() { KerberosUserMapper mapper = new KerberosUserMapper(); assertEquals("alice@altostrat.com", mapper.map("alice@EXAMPLE.COM")); assertEquals("hive--example.com@altostrat.com", mapper.map("hive/example.com@EXAMPLE.COM")); assertEquals("robot-yarn@altostrat.org", mapper.map("yarn-app@FOO.ORG")); assertEquals("bob@altostrat.org", mapper.map("bob@FOO.ORG")); assertEquals("bob-super@super-domain.com", mapper.map("bob@SUPER.REALM")); assertEquals("bobby@some-domain.org", mapper.map("bob/6.7.8.9@HELLO")); }
@Test public void testMapShortName() { KerberosUserMapper mapper = new KerberosUserMapper(); assertEquals("alice@altostrat.com", mapper.map("alice")); assertEquals("john-bonjour@altostrat.net", mapper.map("john-hello")); assertEquals("marie-lowercase@altostrat.com.au", mapper.map("MaRiE-lowercase")); }
@Test public void testUnmappableKerberosNames() { KerberosUserMapper mapper = new KerberosUserMapper(); try { mapper.map("alice@BLAH.NET"); fail(); } catch (IllegalArgumentException e) {} try { mapper.map("@EXAMPLE.COM"); fail(); } catch (IllegalArgumentException e) {} try { mapper.map("@"); fail(); } catch (IllegalArgumentException e) {} }