use of org.apache.knox.gateway.security.PrimaryPrincipal in project knox by apache.
the class HadoopGroupProviderFilterTest method badConfigTest.
/**
* Test for a bad config (nonexistent). This test proves, we are not falling
* back on {@link ShellBasedUnixGroupsMapping} because we explicitly use
* {@link LdapGroupsMapping} and in case of bad config we get empty groups
* (Hadoop way).
*
* @throws ServletException
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void badConfigTest() throws ServletException {
final List<String> keysList = Arrays.asList("hadoop.security.group.mapping", "hadoop.security.group.mapping.ldap.bind.user", "hadoop.security.group.mapping.ldap.bind.password", "hadoop.security.group.mapping.ldap.url", "hadoop.security.group.mapping.ldap.search.filter.group", "hadoop.security.group.mapping.ldap.search.attr.member", "hadoop.security.group.mapping.ldap.search.filter.user");
final FilterConfig config = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.expect(config.getInitParameter("principal.mapping")).andReturn("").anyTimes();
ServletContext context = EasyMock.createNiceMock(ServletContext.class);
EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes();
EasyMock.expect(context.getInitParameter("principal.mapping")).andReturn("").anyTimes();
EasyMock.expect(config.getInitParameter("hadoop.security.group.mapping")).andReturn("org.apache.hadoop.security.LdapGroupsMapping").anyTimes();
EasyMock.expect(config.getInitParameter("hadoop.security.group.mapping.ldap.bind.user")).andReturn("uid=dummy,ou=people,dc=hadoop,dc=apache,dc=org").anyTimes();
EasyMock.expect(config.getInitParameter("hadoop.security.group.mapping.ldap.bind.password")).andReturn("unbind-me-please").anyTimes();
EasyMock.expect(config.getInitParameter("hadoop.security.group.mapping.ldap.url")).andReturn("ldap://nomansland:33389").anyTimes();
EasyMock.expect(config.getInitParameter("hadoop.security.group.mapping.ldap.search.filter.group")).andReturn("(objectclass=groupOfNames)").anyTimes();
EasyMock.expect(config.getInitParameter("hadoop.security.group.mapping.ldap.search.attr.member")).andReturn("member").anyTimes();
EasyMock.expect(config.getInitParameter("hadoop.security.group.mapping.ldap.search.filter.user")).andReturn("(&(|(objectclass=person)(objectclass=applicationProcess))(cn={0}))").anyTimes();
EasyMock.expect(config.getInitParameterNames()).andReturn(Collections.enumeration((keysList))).anyTimes();
EasyMock.replay(config);
EasyMock.replay(context);
final HadoopGroupProviderFilter filter = new HadoopGroupProviderFilter();
final Subject subject = new Subject();
subject.getPrincipals().add(new PrimaryPrincipal(username));
filter.init(config);
final String principal = filter.mapUserPrincipal(((Principal) subject.getPrincipals(PrimaryPrincipal.class).toArray()[0]).getName());
final String[] groups = filter.mapGroupPrincipals(principal, subject);
assertThat(principal, is(username));
/*
* Unfortunately, Hadoop does not let us know what went wrong all we get is
* empty groups
*/
assertThat(groups.length, is(0));
}
use of org.apache.knox.gateway.security.PrimaryPrincipal in project knox by apache.
the class RegexIdentityAssertionFilterTest method testMapDomain.
@Test
public void testMapDomain() throws Exception {
FilterConfig config = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.expect(config.getInitParameter("principal.mapping")).andReturn("").anyTimes();
ServletContext context = EasyMock.createNiceMock(ServletContext.class);
EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes();
EasyMock.expect(context.getInitParameter("principal.mapping")).andReturn("").anyTimes();
EasyMock.replay(config);
EasyMock.replay(context);
RegexIdentityAssertionFilter filter = new RegexIdentityAssertionFilter();
Subject subject = new Subject();
subject.getPrincipals().add(new PrimaryPrincipal("member@us.apache.org"));
subject.getPrincipals().add(new GroupPrincipal("user"));
subject.getPrincipals().add(new GroupPrincipal("admin"));
String actual;
// Test dictionary lookup.
config = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.expect(config.getInitParameter("principal.mapping")).andReturn("").anyTimes();
context = EasyMock.createNiceMock(ServletContext.class);
EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes();
EasyMock.expect(context.getInitParameter("principal.mapping")).andReturn("").anyTimes();
EasyMock.expect(config.getInitParameter("input")).andReturn("(.*)@(.*?)\\..*").anyTimes();
EasyMock.expect(config.getInitParameter("output")).andReturn("prefix_{1}_suffix:{[2]}").anyTimes();
EasyMock.expect(config.getInitParameter("lookup")).andReturn("us=USA;ca=CANADA").anyTimes();
EasyMock.replay(config);
EasyMock.replay(context);
filter.init(config);
actual = filter.mapUserPrincipal("member1@us.apache.org");
assertThat(actual, is("prefix_member1_suffix:USA"));
actual = filter.mapUserPrincipal("member2@ca.apache.org");
assertThat(actual, is("prefix_member2_suffix:CANADA"));
actual = filter.mapUserPrincipal("member3@nj.apache.org");
assertThat(actual, is("prefix_member3_suffix:"));
}
use of org.apache.knox.gateway.security.PrimaryPrincipal in project knox by apache.
the class SwitchCaseIdentityAssertionFilterTest method testDefaultConfig.
@Test
public void testDefaultConfig() throws Exception {
FilterConfig config = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.expect(config.getInitParameter("principal.mapping")).andReturn("").anyTimes();
ServletContext context = EasyMock.createNiceMock(ServletContext.class);
EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes();
EasyMock.expect(context.getInitParameter("principal.mapping")).andReturn("").anyTimes();
EasyMock.replay(config);
EasyMock.replay(context);
SwitchCaseIdentityAssertionFilter filter = new SwitchCaseIdentityAssertionFilter();
Subject subject = new Subject();
subject.getPrincipals().add(new PrimaryPrincipal("Member@us.apache.org"));
subject.getPrincipals().add(new GroupPrincipal("users"));
subject.getPrincipals().add(new GroupPrincipal("Admin"));
filter.init(config);
String actual = filter.mapUserPrincipal(((Principal) subject.getPrincipals(PrimaryPrincipal.class).toArray()[0]).getName());
String[] groups = filter.mapGroupPrincipals(actual, subject);
assertThat(actual, is("member@us.apache.org"));
assertThat(groups, is(arrayContainingInAnyOrder("admin", "users")));
}
use of org.apache.knox.gateway.security.PrimaryPrincipal in project knox by apache.
the class SwitchCaseIdentityAssertionFilterTest method testNonePrincipalAndGroups.
@Test
public void testNonePrincipalAndGroups() throws Exception {
FilterConfig config = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.expect(config.getInitParameter("principal.case")).andReturn("none").anyTimes();
EasyMock.expect(config.getInitParameter("group.principal.case")).andReturn("NONE").anyTimes();
ServletContext context = EasyMock.createNiceMock(ServletContext.class);
EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes();
EasyMock.expect(context.getInitParameter("principal.mapping")).andReturn("").anyTimes();
EasyMock.replay(config);
EasyMock.replay(context);
SwitchCaseIdentityAssertionFilter filter = new SwitchCaseIdentityAssertionFilter();
Subject subject = new Subject();
subject.getPrincipals().add(new PrimaryPrincipal("Member@us.apache.org"));
filter.init(config);
String actual = filter.mapUserPrincipal(((Principal) subject.getPrincipals(PrimaryPrincipal.class).toArray()[0]).getName());
String[] groups = filter.mapGroupPrincipals(actual, subject);
assertThat(actual, is("Member@us.apache.org"));
assertThat(groups, is(nullValue()));
}
use of org.apache.knox.gateway.security.PrimaryPrincipal in project knox by apache.
the class SwitchCaseIdentityAssertionFilterTest method testNoGroups.
@Test
public void testNoGroups() throws Exception {
FilterConfig config = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.expect(config.getInitParameter("principal.case")).andReturn("upper").anyTimes();
EasyMock.expect(config.getInitParameter("group.principal.case")).andReturn("upper").anyTimes();
EasyMock.expect(config.getInitParameter("principal.mapping")).andReturn("").anyTimes();
ServletContext context = EasyMock.createNiceMock(ServletContext.class);
EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes();
EasyMock.expect(context.getInitParameter("principal.mapping")).andReturn("").anyTimes();
EasyMock.replay(config);
EasyMock.replay(context);
SwitchCaseIdentityAssertionFilter filter = new SwitchCaseIdentityAssertionFilter();
Subject subject = new Subject();
subject.getPrincipals().add(new PrimaryPrincipal("Member@us.apache.org"));
filter.init(config);
String actual = filter.mapUserPrincipal(((Principal) subject.getPrincipals(PrimaryPrincipal.class).toArray()[0]).getName());
String[] groups = filter.mapGroupPrincipals(actual, subject);
assertThat(actual, is("MEMBER@US.APACHE.ORG"));
assertThat(groups, is(nullValue()));
}
Aggregations