use of org.apache.shiro.realm.ldap.JndiLdapContextFactory in project neo4j by neo4j.
the class LdapRealmTest method shouldLogFailedAuthorizationQueries.
@Test
public void shouldLogFailedAuthorizationQueries() throws Exception {
// Given
when(config.get(SecuritySettings.ldap_use_starttls)).thenReturn(true);
LdapRealm realm = new TestLdapRealm(config, securityLog, true);
JndiLdapContextFactory jndiLdapContectFactory = mock(JndiLdapContextFactory.class);
when(jndiLdapContectFactory.getUrl()).thenReturn("ldap://myserver.org:12345");
// When
assertException(() -> realm.doGetAuthorizationInfo(new SimplePrincipalCollection("olivia", "LdapRealm")), AuthProviderFailedException.class, "");
// Then
verify(securityLog).error(contains("{LdapRealm}: Failed to get authorization info: " + "'LDAP naming error while attempting to retrieve authorization for user [olivia].'" + " caused by 'Simulated failure'"));
}
use of org.apache.shiro.realm.ldap.JndiLdapContextFactory in project neo4j by neo4j.
the class LdapRealmTest method shouldLogSuccessfulAuthenticationQueriesUsingStartTLS.
@Test
public void shouldLogSuccessfulAuthenticationQueriesUsingStartTLS() throws NamingException {
// Given
when(config.get(SecuritySettings.ldap_use_starttls)).thenReturn(true);
LdapRealm realm = new TestLdapRealm(config, securityLog, false);
JndiLdapContextFactory jndiLdapContectFactory = mock(JndiLdapContextFactory.class);
when(jndiLdapContectFactory.getUrl()).thenReturn("ldap://myserver.org:12345");
// When
realm.queryForAuthenticationInfo(new ShiroAuthToken(map("principal", "olivia", "credentials", "123")), jndiLdapContectFactory);
// Then
verify(securityLog).debug(contains("{LdapRealm}: Authenticated user 'olivia' against 'ldap://myserver.org:12345' using StartTLS"));
}
use of org.apache.shiro.realm.ldap.JndiLdapContextFactory in project airavata by apache.
the class LDAPUserStore method initializeLDAP.
protected void initializeLDAP(String ldapUrl, String systemUser, String systemUserPassword, String userNameTemplate) {
JndiLdapContextFactory jndiLdapContextFactory = new JndiLdapContextFactory();
jndiLdapContextFactory.setUrl(ldapUrl);
jndiLdapContextFactory.setSystemUsername(systemUser);
jndiLdapContextFactory.setSystemPassword(systemUserPassword);
ldapRealm = new JndiLdapRealm();
ldapRealm.setContextFactory(jndiLdapContextFactory);
ldapRealm.setUserDnTemplate(userNameTemplate);
ldapRealm.init();
}
use of org.apache.shiro.realm.ldap.JndiLdapContextFactory in project SSM by Intel-bigdata.
the class GetUserList method getUserList.
/**
* function to extract users from LDAP
*/
public List<String> getUserList(JndiLdapRealm r, String searchText) {
List<String> userList = new ArrayList<>();
String userDnTemplate = r.getUserDnTemplate();
String[] userDn = userDnTemplate.split(",", 2);
String userDnPrefix = userDn[0].split("=")[0];
String userDnSuffix = userDn[1];
JndiLdapContextFactory CF = (JndiLdapContextFactory) r.getContextFactory();
try {
LdapContext ctx = CF.getSystemLdapContext();
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attrIDs = { userDnPrefix };
constraints.setReturningAttributes(attrIDs);
NamingEnumeration result = ctx.search(userDnSuffix, "(" + userDnPrefix + "=*" + searchText + "*)", constraints);
while (result.hasMore()) {
Attributes attrs = ((SearchResult) result.next()).getAttributes();
if (attrs.get(userDnPrefix) != null) {
String currentUser = attrs.get(userDnPrefix).toString();
userList.add(currentUser.split(":")[1].trim());
}
}
} catch (Exception e) {
LOG.error("Error retrieving User list from Ldap Realm", e);
}
LOG.info("UserList: " + userList);
return userList;
}
use of org.apache.shiro.realm.ldap.JndiLdapContextFactory in project SSM by Intel-bigdata.
the class GetUserList method getUserList.
/**
* function to extract users from Zeppelin LdapRealm
*/
public List<String> getUserList(LdapRealm r, String searchText) {
List<String> userList = new ArrayList<>();
if (LOG.isDebugEnabled()) {
LOG.debug("SearchText: " + searchText);
}
String userAttribute = r.getUserSearchAttributeName();
String userSearchRealm = r.getUserSearchBase();
String userObjectClass = r.getUserObjectClass();
JndiLdapContextFactory CF = (JndiLdapContextFactory) r.getContextFactory();
try {
LdapContext ctx = CF.getSystemLdapContext();
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attrIDs = { userAttribute };
constraints.setReturningAttributes(attrIDs);
NamingEnumeration result = ctx.search(userSearchRealm, "(&(objectclass=" + userObjectClass + ")(" + userAttribute + "=" + searchText + "))", constraints);
while (result.hasMore()) {
Attributes attrs = ((SearchResult) result.next()).getAttributes();
if (attrs.get(userAttribute) != null) {
String currentUser;
if (r.getUserLowerCase()) {
LOG.debug("userLowerCase true");
currentUser = ((String) attrs.get(userAttribute).get()).toLowerCase();
} else {
LOG.debug("userLowerCase false");
currentUser = (String) attrs.get(userAttribute).get();
}
if (LOG.isDebugEnabled()) {
LOG.debug("CurrentUser: " + currentUser);
}
userList.add(currentUser.trim());
}
}
} catch (Exception e) {
LOG.error("Error retrieving User list from Ldap Realm", e);
}
return userList;
}
Aggregations