Package org.jspresso.framework.security

Examples of org.jspresso.framework.security.UserPrincipal


    Attributes attrs = ctx.getAttributes(userDN, null);

    NameParser nameParser = ctx.getNameParser(userDN);

    UserPrincipal userPrincipal = (UserPrincipal) getIdentity();

    for (Map.Entry<String, String> option : ((Map<String, String>) options)
        .entrySet()) {
      if (option.getKey().startsWith(CUSTOM_PROPERTY_OPT)) {
        String attributeId = option.getValue();
        if (option.getValue().contains(SLICE_START)) {
          String attributeIdBase = attributeId.substring(0, attributeId
              .indexOf(SLICE_START));

          String[] indices = option.getValue().substring(
              option.getValue().indexOf(SLICE_START) + 1,
              option.getValue().indexOf(SLICE_END)).split(
              SLICE_START + "," + SLICE_END);
          int startIndex = Integer.parseInt(indices[0]);
          int endIndex = Integer.parseInt(indices[1]);

          if ("DN".equalsIgnoreCase(attributeIdBase)) {
            String dnSlice = extractSlice(userDN, nameParser, startIndex,
                endIndex);
            int dotIndex = attributeId.indexOf(".");
            if (dotIndex > -1) {
              Attributes nestedAttrs = ctx.getAttributes(dnSlice, null);
              Attribute attr = nestedAttrs.get(attributeId
                  .substring(dotIndex + 1));
              if (attr != null && attr.size() > 0) {
                if (attr.size() == 1) {
                  userPrincipal.putCustomProperty(option.getKey().substring(
                      CUSTOM_PROPERTY_OPT.length()), attr.get());
                } else {
                  List<Object> values = new ArrayList<Object>();
                  for (NamingEnumeration<?> avne = attr.getAll(); avne
                      .hasMore();) {
                    values.add(avne.next());
                  }
                  userPrincipal.putCustomProperty(option.getKey().substring(
                      CUSTOM_PROPERTY_OPT.length()), values);
                }
              }
            } else {
              userPrincipal.putCustomProperty(option.getKey().substring(
                  CUSTOM_PROPERTY_OPT.length()), dnSlice);
            }
          } else {
            Attribute attr = attrs.get(attributeId);
            if (attr != null && attr.size() > 0) {
              if (attr.size() == 1) {
                userPrincipal.putCustomProperty(option.getKey().substring(
                    CUSTOM_PROPERTY_OPT.length()), extractSlice((String) attr
                    .get(), nameParser, startIndex, endIndex));
              } else {
                List<Object> values = new ArrayList<Object>();
                for (NamingEnumeration<?> avne = attr.getAll(); avne.hasMore();) {
                  values.add(extractSlice((String) avne.next(), nameParser,
                      startIndex, endIndex));
                }
                userPrincipal.putCustomProperty(option.getKey().substring(
                    CUSTOM_PROPERTY_OPT.length()), values);
              }
            }
          }
        } else {
          if ("DN".equalsIgnoreCase(attributeId)) {
            userPrincipal.putCustomProperty(option.getKey().substring(
                CUSTOM_PROPERTY_OPT.length()), userDN);
          } else {
            Attribute attr = attrs.get(attributeId);
            if (attr != null && attr.size() > 0) {
              if (attr.size() == 1) {
                userPrincipal.putCustomProperty(option.getKey().substring(
                    CUSTOM_PROPERTY_OPT.length()), attr.get());
              } else {
                List<Object> values = new ArrayList<Object>();
                for (NamingEnumeration<?> avne = attr.getAll(); avne.hasMore();) {
                  values.add(avne.next());
                }
                userPrincipal.putCustomProperty(option.getKey().substring(
                    CUSTOM_PROPERTY_OPT.length()), values);
              }
            }
          }
        }
View Full Code Here


   */
  @Override
  protected Principal createIdentity(String username) throws Exception {
    if (principalClassName == null && getIdentity() == null) {
      // we are creating the user principal.
      return new UserPrincipal(username);
    }
    return super.createIdentity(username);
  }
View Full Code Here

  public boolean commit() {
    if (!succeeded) {
      return false;
    }
    // assume the user we authenticated is the DemoPrincipal
    userPrincipal = new UserPrincipal(username);
    for (Map.Entry<String, ?> option : options.entrySet()) {
      if (option.getKey().startsWith(CUSTOM_PROPERTY_OPT + suffix)) {
        userPrincipal.putCustomProperty(option.getKey().substring(
            (CUSTOM_PROPERTY_OPT + suffix).length() + 1), option.getValue());
      }
View Full Code Here

TOP

Related Classes of org.jspresso.framework.security.UserPrincipal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.