use of opengrok.auth.entity.LdapUser in project OpenGrok by OpenGrok.
the class LdapFilterPluginTest method expandFilterTest1.
@Test
void expandFilterTest1() {
LdapUser ldapUser = new LdapUser();
ldapUser.setAttribute("mail", new TreeSet<>(Collections.singletonList("james@bond")));
ldapUser.setAttribute("uid", new TreeSet<>(Collections.singletonList("bondjame")));
ldapUser.setAttribute("ou", new TreeSet<>(Arrays.asList("MI6", "MI7")));
User user = new User("007", "123", null, true);
assertEquals("(objectclass=james@bond)", plugin.expandFilter("(objectclass=%mail%)", ldapUser, user));
assertEquals("(objectclass=bondjame)", plugin.expandFilter("(objectclass=%uid%)", ldapUser, user));
assertEquals("(objectclass=007)", plugin.expandFilter("(objectclass=%username%)", ldapUser, user));
assertEquals("(objectclass=123)", plugin.expandFilter("(objectclass=%guid%)", ldapUser, user));
ldapUser.setAttribute("role", new TreeSet<>(Collections.singletonList("agent")));
assertEquals("(objectclass=agent)", plugin.expandFilter("(objectclass=%role%)", ldapUser, user));
// doesn't work for more than one value
ldapUser.setAttribute("role", new TreeSet<>(Arrays.asList("agent", "double-agent")));
assertEquals("(objectclass=%role%)", plugin.expandFilter("(objectclass=%role%)", ldapUser, user));
}
use of opengrok.auth.entity.LdapUser in project OpenGrok by OpenGrok.
the class LdapFilterPluginTest method expandFilterTest2.
@Test
void expandFilterTest2() {
LdapUser ldapUser = new LdapUser();
ldapUser.setAttribute("mail", new TreeSet<>(Collections.singletonList("james@bond")));
ldapUser.setAttribute("uid", new TreeSet<>(Collections.singletonList("bondjame")));
ldapUser.setAttribute("ou", new TreeSet<>(Arrays.asList("MI6", "MI7")));
User user = new User("007", "123", null, true);
assertEquals("(objectclass=%james@bond%)", plugin.expandFilter("(objectclass=%%mail%%)", ldapUser, user));
assertEquals("(objectclass=%james@bond%)", plugin.expandFilter("(objectclass=\\%%mail%\\%)", ldapUser, user));
assertEquals("(objectclass=%mail%)", plugin.expandFilter("(objectclass=\\%mail\\%)", ldapUser, user));
assertEquals("(objectclass=%mail)", plugin.expandFilter("(objectclass=\\%mail)", ldapUser, user));
assertEquals("(objectclass=mail)", plugin.expandFilter("(objectclass=mail)", ldapUser, user));
assertEquals("(objectclass=%mail)", plugin.expandFilter("(objectclass=%mail)", ldapUser, user));
assertEquals("(objectclass=%%%%)", plugin.expandFilter("(objectclass=\\%%\\%\\%)", ldapUser, user));
}
use of opengrok.auth.entity.LdapUser in project OpenGrok by OpenGrok.
the class LdapUserPluginTest method testFillSessionWithDnOff.
@Test
void testFillSessionWithDnOff() throws LdapException {
AbstractLdapProvider mockprovider = mock(LdapFacade.class);
Map<String, Set<String>> attrs = new HashMap<>();
attrs.put("mail", Collections.singleton("foo@example.com"));
final String dn = "cn=FOO_BAR,L=EMEA,DC=EXAMPLE,DC=COM";
AbstractLdapProvider.LdapSearchResult<Map<String, Set<String>>> result = new AbstractLdapProvider.LdapSearchResult<>(dn, attrs);
assertNotNull(result);
when(mockprovider.lookupLdapContent(isNull(), isNull(), any(String[].class))).thenReturn(result);
Map<String, Object> params = getParamsMap();
params.put(LdapUserPlugin.ATTRIBUTES, "mail");
params.put(LdapUserPlugin.USE_DN, false);
LdapUserPlugin plugin = new LdapUserPlugin();
plugin.load(params, mockprovider);
assertSame(mockprovider, plugin.getLdapProvider());
HttpServletRequest request = new DummyHttpServletRequestLdap();
User user = new User("foo@example.com", "id");
plugin.fillSession(request, user);
assertNotNull(request.getSession().getAttribute(SESSION_ATTR));
assertEquals(dn, ((LdapUser) request.getSession().getAttribute(SESSION_ATTR)).getDn());
}
use of opengrok.auth.entity.LdapUser in project OpenGrok by OpenGrok.
the class LdapUserPluginTest method testInstance.
@Test
void testInstance() {
Map<String, Object> params = getParamsMap();
params.put(LdapUserPlugin.ATTRIBUTES, "mail");
params.put(LdapUserPlugin.INSTANCE, "42");
plugin.load(params);
HttpServletRequest request = new DummyHttpServletRequestLdap();
LdapUser ldapUser = new LdapUser();
plugin.updateSession(request, ldapUser);
assertEquals(request.getSession().getAttribute(SESSION_ATTR + "42"), ldapUser);
}
use of opengrok.auth.entity.LdapUser in project OpenGrok by OpenGrok.
the class LdapAttrPluginTest method prepareRequest.
private void prepareRequest(String username, String mail, String... ous) {
dummyRequest = new DummyHttpServletRequestLdap();
dummyRequest.setAttribute(UserPlugin.REQUEST_ATTR, new User(username, "123"));
LdapUser ldapUser = new LdapUser();
ldapUser.setAttribute("mail", new TreeSet<>(Collections.singletonList(mail)));
ldapUser.setAttribute("uid", new TreeSet<>(Collections.singletonList("123")));
ldapUser.setAttribute("ou", new TreeSet<>(Arrays.asList(ous)));
dummyRequest.getSession().setAttribute(LdapUserPlugin.SESSION_ATTR, ldapUser);
plugin.setSessionEstablished(dummyRequest, true);
plugin.setSessionUsername(dummyRequest, username);
}
Aggregations