當前位置: 首頁>>代碼示例>>Java>>正文


Java DirContextOperations.getNameInNamespace方法代碼示例

本文整理匯總了Java中org.springframework.ldap.core.DirContextOperations.getNameInNamespace方法的典型用法代碼示例。如果您正苦於以下問題:Java DirContextOperations.getNameInNamespace方法的具體用法?Java DirContextOperations.getNameInNamespace怎麽用?Java DirContextOperations.getNameInNamespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.ldap.core.DirContextOperations的用法示例。


在下文中一共展示了DirContextOperations.getNameInNamespace方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: mapUserFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
public UserDetails mapUserFromContext(DirContextOperations ctx, String username,
                                      Collection<? extends GrantedAuthority> authorities) {
    String dn = ctx.getNameInNamespace();

    logger.debug("Mapping user details from context with DN: " + dn);

    // User must be defined in Airsonic, unless auto-shadowing is enabled.
    User user = securityService.getUserByName(username, false);
    if (user == null && !settingsService.isLdapAutoShadowing()) {
        throw new BadCredentialsException("User does not exist.");
    }

    if (user == null) {
        User newUser = new User(username, "", null, true, 0L, 0L, 0L);
        newUser.setStreamRole(true);
        newUser.setSettingsRole(true);
        securityService.createUser(newUser);
        logger.info("Created local user '" + username + "' for DN " + dn);
        user = securityService.getUserByName(username, false);
    }

    // LDAP authentication must be enabled for the given user.
    if (!user.isLdapAuthenticated()) {
        throw new BadCredentialsException("LDAP authentication disabled for user.");
    }

    LdapUserDetailsImpl.Essence essence = new LdapUserDetailsImpl.Essence();
    essence.setDn(dn);

    Object passwordValue = ctx.getObjectAttribute(passwordAttributeName);

    if (passwordValue != null) {
        essence.setPassword(mapPassword(passwordValue));
    }

    essence.setUsername(user.getUsername());

    // Add the supplied authorities
    for (GrantedAuthority authority : securityService.getGrantedAuthorities(user.getUsername())) {
        essence.addAuthority(authority);
    }

    // Check for PPolicy data

    PasswordPolicyResponseControl ppolicy = (PasswordPolicyResponseControl) ctx
            .getObjectAttribute(PasswordPolicyControl.OID);

    if (ppolicy != null) {
        essence.setTimeBeforeExpiration(ppolicy.getTimeBeforeExpiration());
        essence.setGraceLoginsRemaining(ppolicy.getGraceLoginsRemaining());
    }

    return essence.createUserDetails();

}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:56,代碼來源:CustomUserDetailsContextMapper.java

示例2: getUserFromLdapSearch

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
private LdapUser getUserFromLdapSearch(LdapTemplate ldapTemplate, String userName, LdapSetting settings) {
    DirContextOperations contextOperations = searchUserInLdap(ldapTemplate, userName, settings);
    if (contextOperations == null) {
        return null;
    }
    return new LdapUser(userName, contextOperations.getNameInNamespace());
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:8,代碼來源:LdapServiceImpl.java

示例3: getAdditionalRoles

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
 *
 * This function returns a list of roles from the given set of groups
 * based on the value of the <code>groupToRoleMap</code> property.
 * 
 * @return a {@link java.util.Set} object.
 */
@Override
protected Set<GrantedAuthority> getAdditionalRoles(final DirContextOperations user, final String username) {
	final String userDn = user.getNameInNamespace();
	final Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();

	if (super.getGroupSearchBase() == null) {
		return authorities;
	}

	if (logger.isDebugEnabled()) {
		logger.debug("Searching for roles for user '" + username + "', DN = " + "'" + userDn + "', with filter "
				+ this.groupSearchFilter + " in search base '" + super.getGroupSearchBase() + "'");
	}

	final Set<String> userRoles = ldapTemplate.searchForSingleAttributeValues(
			super.getGroupSearchBase(), 
			this.groupSearchFilter,
			new String[]{userDn, username}, 
			this.groupRoleAttribute
	);

	for(String group : userRoles) {
		final List<String> rolesForGroup = this.groupToRoleMap.get(group);
		logger.debug("Checking " + group + " for an associated role");
		if (rolesForGroup != null) {
			for(String role : rolesForGroup) {
				authorities.add(new SimpleGrantedAuthority(role));
				logger.debug("Added role: " + role + " based on group " + group);
			}
		}
	}

	return authorities;
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:42,代碼來源:UserGroupLdapAuthoritiesPopulator.java

示例4: getAdditionalRoles

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
 *
 * This function returns a list of roles from the given set of groups
 * based on the value of the <code>groupToRoleMap</code> property.
 * 
 * @return a {@link java.util.Set} object.
 */
@Override
protected Set<GrantedAuthority> getAdditionalRoles(final DirContextOperations user, final String username) {
	final String userDn = user.getNameInNamespace();
	final Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();

	if (super.getGroupSearchBase() == null) {
		return authorities;
	}

	if (logger.isDebugEnabled()) {
		logger.debug("Searching for roles for user '" + username + "', DN = " + "'" + userDn + "', with filter "
				+ this.groupSearchFilter + " in search base '" + super.getGroupSearchBase() + "'");
	}

	@SuppressWarnings("unchecked")
	final Set<String> userRoles = ldapTemplate.searchForSingleAttributeValues(
			super.getGroupSearchBase(), 
			this.groupSearchFilter,
			new String[]{userDn, username}, 
			this.groupRoleAttribute
	);

	for(String group : userRoles) {
		final List<String> rolesForGroup = this.groupToRoleMap.get(group);
		logger.debug("Checking " + group + " for an associated role");
		if (rolesForGroup != null) {
			for(String role : rolesForGroup) {
				authorities.add(new GrantedAuthorityImpl(role));
				logger.debug("Added role: " + role + " based on group " + group);
			}
		}
	}

	return authorities;
}
 
開發者ID:vishwaabhinav,項目名稱:OpenNMS,代碼行數:43,代碼來源:UserGroupLdapAuthoritiesPopulator.java

示例5: doMapFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
@Override
protected String doMapFromContext(DirContextOperations ctx) {
	return ctx.getNameInNamespace();
}
 
開發者ID:spring-projects,項目名稱:spring-ldap,代碼行數:5,代碼來源:LdapContextSourceIntegrationTest.java

示例6: doMapFromContext

import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
/**
 * Method to map user from ldap attributes
 *
 * @param ctx The ldap context
 * @return The mapped ldap user {@link org.artifactory.api.security.ldap.LdapUser}
 */
@Override
protected LdapUser doMapFromContext(DirContextOperations ctx) {
    String uidFromLdap = ctx.getStringAttribute("uid");
    return new LdapUser(uidFromLdap, ctx.getNameInNamespace());
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:12,代碼來源:UserContextMapper.java


注:本文中的org.springframework.ldap.core.DirContextOperations.getNameInNamespace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。