本文整理匯總了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();
}
示例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());
}
示例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;
}
示例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;
}
示例5: doMapFromContext
import org.springframework.ldap.core.DirContextOperations; //導入方法依賴的package包/類
@Override
protected String doMapFromContext(DirContextOperations ctx) {
return ctx.getNameInNamespace();
}
示例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());
}