Example usage for javax.naming Name toString

List of usage examples for javax.naming Name toString

Introduction

In this page you can find the example usage for javax.naming Name toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:de.micromata.genome.util.runtime.jndi.SimpleNamingContext.java

/**
 * To string.//from   w w w.j  a va  2s.  com
 *
 * @param name the name
 * @return the string
 */
protected String toString(Name name) {
    return name.toString();
}

From source file:com.dattack.naming.AbstractContext.java

@Override
public NameParser getNameParser(final Name name) throws NamingException {

    if (name == null || name.isEmpty() || (name.size() == 1 && name.toString().equals(getNameInNamespace()))) {
        return nameParser;
    }/*from   w w w.j a  v a2 s  .co m*/

    final Name subName = name.getPrefix(1);
    if (subContexts.containsKey(subName)) {
        return subContexts.get(subName).getNameParser(name.getSuffix(1));
    }

    throw new NotContextException();
}

From source file:de.sub.goobi.helper.ldap.LdapUser.java

@Override
public Attributes getAttributes(Name name) throws NamingException {
    return getAttributes(name.toString());
}

From source file:se.inera.axel.shs.broker.directory.internal.LdapDirectoryAdminService.java

@Override
public void removeAgreement(Organization organization, Agreement agreement) {
    Name dn = buildDn(organization, agreement);
    ldapTemplate.unbind(dn);//from  w w  w .  j  a  va  2  s. c om
    log.debug("agreement {} deleted in directory", dn.toString());
}

From source file:se.inera.axel.shs.broker.directory.internal.LdapDirectoryAdminService.java

@Override
public void removeAddress(Organization organization, Address address) {
    Name dn = buildDn(organization, address);
    ldapTemplate.unbind(dn);/*from  w  w  w.  j  av a2s  .co m*/
    log.debug("address {} deleted in directory", dn.toString());

    try {
        dn = build11Dn(organization, address);
        ldapTemplate.unbind(dn);
    } catch (Exception e) {
        log.warn("Error removing address from o=Myndighetsaddresser: {}", address.toString());
    }
}

From source file:se.inera.axel.shs.broker.directory.internal.LdapDirectoryAdminService.java

@Override
public void removeProduct(Organization organization, ProductType product) {

    Name dn = buildDn(organization, product);
    ldapTemplate.unbind(dn);// w w  w  .jav a 2s . co  m
    log.debug("product {} deleted in directory", dn.toString());

    try {
        dn = build11Dn(organization, product);
        ldapTemplate.unbind(dn);
    } catch (Exception e) {
        log.warn("Error removing product from o=Myndighetsprodukter: {}", product.toString());
    }
}

From source file:de.sub.goobi.helper.ldap.LdapUser.java

@Override
public Attributes getAttributes(Name name, String[] ids) throws NamingException {
    return getAttributes(name.toString(), ids);
}

From source file:org.apache.cxf.sts.claims.LdapGroupClaimsHandler.java

public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claims, ClaimsParameters parameters) {

    boolean found = false;
    for (Claim claim : claims) {
        if (claim.getClaimType().toString().equals(this.groupURI)) {
            found = true;//from w w  w .  j a v a 2  s.co m
            break;
        }
    }
    if (!found) {
        return new ProcessedClaimCollection();
    }

    String user = null;

    Principal principal = parameters.getPrincipal();
    if (principal instanceof KerberosPrincipal) {
        KerberosPrincipal kp = (KerberosPrincipal) principal;
        StringTokenizer st = new StringTokenizer(kp.getName(), "@");
        user = st.nextToken();
    } else if (principal instanceof X500Principal) {
        X500Principal x500p = (X500Principal) principal;
        LOG.warning("Unsupported principal type X500: " + x500p.getName());
    } else if (principal != null) {
        user = principal.getName();
        if (user == null) {
            LOG.warning("Principal name must not be null");
        }
    } else {
        LOG.warning("Principal is null");
    }
    if (user == null) {
        return new ProcessedClaimCollection();
    }

    if (!LdapUtils.isDN(user)) {
        Name dn = LdapUtils.getDnOfEntry(ldap, this.userBaseDn, this.getUserObjectClass(),
                this.getUserNameAttribute(), user);
        if (dn != null) {
            user = dn.toString();
            LOG.fine("DN for (" + this.getUserNameAttribute() + "=" + user + ") found: " + user);
        } else {
            LOG.warning("DN not found for user '" + user + "'");
            return new ProcessedClaimCollection();
        }
    }

    if (LOG.isLoggable(Level.FINER)) {
        LOG.finer("Retrieve groups for user " + user);
    }

    List<String> groups = null;
    groups = LdapUtils.getAttributeOfEntries(ldap, this.groupBaseDn, this.getGroupObjectClass(),
            this.groupMemberAttribute, user, "cn");

    if (groups == null || groups.size() == 0) {
        if (LOG.isLoggable(Level.INFO)) {
            LOG.info("No groups found for user '" + user + "'");
        }
        return new ProcessedClaimCollection();
    }

    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Groups for user '" + parameters.getPrincipal().getName() + "': " + groups);
    }

    String scope = null;
    if (getAppliesToScopeMapping() != null && getAppliesToScopeMapping().size() > 0
            && parameters.getAppliesToAddress() != null) {
        scope = getAppliesToScopeMapping().get(parameters.getAppliesToAddress());
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("AppliesTo matchs with scope: " + scope);
        }
    }

    String regex = this.groupNameGlobalFilter;
    regex = regex.replaceAll(ROLE, ".*");
    Pattern globalPattern = Pattern.compile(regex);

    //If AppliesTo value can be mapped to a Scope Name
    //ex. https://localhost/doubleit/services/doubleittransport  -> Demo
    Pattern scopePattern = null;
    if (scope != null) {
        regex = this.groupNameScopedFilter;
        regex = regex.replaceAll(SCOPE, scope).replaceAll(ROLE, ".*");
        scopePattern = Pattern.compile(regex);
    }

    List<String> filteredGroups = new ArrayList<String>();
    for (String group : groups) {
        if (scopePattern != null && scopePattern.matcher(group).matches()) {
            //Group matches the scoped filter
            //ex. (default groupNameScopeFilter)
            //  Demo_User -> Role=User
            //  Demo_Admin -> Role=Admin
            String filter = this.groupNameScopedFilter;
            String role = null;
            if (isUseFullGroupNameAsValue()) {
                role = group;
            } else {
                role = parseRole(group, filter.replaceAll(SCOPE, scope));
            }
            filteredGroups.add(role);
        } else {
            if (globalPattern.matcher(group).matches()) {
                //Group matches the global filter
                //ex. (default groupNameGlobalFilter)
                //  User -> Role=User
                //  Admin -> Role=Admin
                String role = null;
                if (isUseFullGroupNameAsValue()) {
                    role = group;
                } else {
                    role = parseRole(group, this.groupNameGlobalFilter);
                }
                filteredGroups.add(role);
            } else {
                LOG.finer("Group '" + group + "' doesn't match scoped and global group filter");
            }
        }
    }

    LOG.info("Filtered groups: " + filteredGroups);
    if (filteredGroups.size() == 0) {
        LOG.info("No matching groups found for user '" + principal + "'");
        return new ProcessedClaimCollection();
    }

    ProcessedClaimCollection claimsColl = new ProcessedClaimCollection();
    ProcessedClaim c = new ProcessedClaim();
    c.setClaimType(URI.create(this.groupURI));
    c.setPrincipal(principal);
    c.setValues(new ArrayList<Object>(filteredGroups));
    // c.setIssuer(issuer);
    // c.setOriginalIssuer(originalIssuer);
    // c.setNamespace(namespace);
    claimsColl.add(c);

    return claimsColl;
}

From source file:com.frameworkset.commons.dbcp2.BasicDataSourceFactory.java

/**
 * Collects warnings and info messages.  Warnings are generated when an obsolete
 * property is set.  Unknown properties generate info messages.
 *
 * @param ref Reference to check properties of
 * @param name Name provided to getObject
 * @param warnings container for warning messages
 * @param infoMessages container for info messages
 *//*  w  w w  . j ava2  s .  co  m*/
private void validatePropertyNames(Reference ref, Name name, List<String> warnings, List<String> infoMessages) {
    final List<String> allPropsAsList = Arrays.asList(ALL_PROPERTIES);
    final String nameString = name != null ? "Name = " + name.toString() + " " : "";
    if (NUPROP_WARNTEXT != null && !NUPROP_WARNTEXT.keySet().isEmpty()) {
        for (String propertyName : NUPROP_WARNTEXT.keySet()) {
            final RefAddr ra = ref.get(propertyName);
            if (ra != null && !allPropsAsList.contains(ra.getType())) {
                final StringBuilder stringBuilder = new StringBuilder(nameString);
                final String propertyValue = ra.getContent().toString();
                stringBuilder.append(NUPROP_WARNTEXT.get(propertyName)).append(" You have set value of \"")
                        .append(propertyValue).append("\" for \"").append(propertyName)
                        .append("\" property, which is being ignored.");
                warnings.add(stringBuilder.toString());
            }
        }
    }

    final Enumeration<RefAddr> allRefAddrs = ref.getAll();
    while (allRefAddrs.hasMoreElements()) {
        final RefAddr ra = allRefAddrs.nextElement();
        final String propertyName = ra.getType();
        // If property name is not in the properties list, we haven't warned on it
        // and it is not in the "silent" list, tell user we are ignoring it.
        if (!(allPropsAsList.contains(propertyName) || NUPROP_WARNTEXT.keySet().contains(propertyName)
                || SILENT_PROPERTIES.contains(propertyName))) {
            final String propertyValue = ra.getContent().toString();
            final StringBuilder stringBuilder = new StringBuilder(nameString);
            stringBuilder.append("Ignoring unknown property: ").append("value of \"").append(propertyValue)
                    .append("\" for \"").append(propertyName).append("\" property");
            infoMessages.add(stringBuilder.toString());
        }
    }
}

From source file:se.inera.axel.shs.broker.directory.internal.LdapDirectoryAdminService.java

/**
 * Save a product entry in v1.1 branch o=Myndighetsprodukter
 * /*from  w  ww .jav a2 s. co  m*/
 * @param organization
 * @param product
 */
private void saveProduct11(Organization organization, ProductType product) {
    DirContextAdapter context = null;
    Name dn = build11Dn(organization, product);
    boolean isNew = false;
    try {
        context = (DirContextAdapter) ldapTemplate.lookupContext(dn);
    } catch (NameNotFoundException e) {
        isNew = true;
        context = new DirContextAdapter(dn);
    }

    ProductTypeMapper.mapToContext(organization, product, context);

    if (isNew) {
        ldapTemplate.bind(context);
        log.debug("product {} created in directory o=Myndighetsprodukter", dn.toString());
    } else {
        ldapTemplate.modifyAttributes(context);
        log.debug("product {} updated in directory o=Myndighetsprodukter", dn.toString());
    }
}