/**
   * Reads user profile from ldap.
   *
   * @param context the current request context (contains the active user)
   * @param request HTTP request.
   * @return user the user whose profile was read
   * @throws IdentityException if a system error occurs preventing the action
   * @throws NamingException if an LDAP naming exception occurs
   * @throws SQLException if a database communication exception occurs
   * @throws CredentialsDeniedException
   * @throws UnsupportedEncodingException
   */
  protected User readUserProfile(RequestContext context, HttpServletRequest request)
      throws Exception {

    IdentityAdapter idAdapter = context.newIdentityAdapter();
    User user = new User();
    String[] parts = request.getRequestURI().toString().split("/");
    String sEncoding = request.getCharacterEncoding();
    if ((sEncoding == null) || (sEncoding.trim().length() == 0)) {
      sEncoding = "UTF-8";
    }

    if (parts.length > 0) {
      String userIdentifier = Val.chkStr(URLDecoder.decode(parts[5].trim(), "UTF-8"));
      if (userIdentifier.endsWith(userDIT)) {
        user.setDistinguishedName(userIdentifier);
        DistinguishedNameCredential dnCredential = new DistinguishedNameCredential();
        dnCredential.setDistinguishedName(userIdentifier);
        user.setCredentials(dnCredential);
      } else if (userIdentifier.length() > 0) {
        user.setCredentials(new UsernameCredential(userIdentifier));
      }
      ((LdapIdentityAdapter) idAdapter).populateUser(context, user);
      return user;
    } else {
      throw new Exception("error");
    }
  }
  /**
   * Constructs a administrator based upon the user associated with the current request context.
   *
   * @param context the current request context (contains the active user)
   * @throws NotAuthorizedException if the user does not have publishing rights
   */
  protected void checkRole(RequestContext context) throws NotAuthorizedException {

    // initialize
    User user = context.getUser();
    user.setKey(user.getKey());
    user.setLocalID(user.getLocalID());
    user.setDistinguishedName(user.getDistinguishedName());
    user.setName(user.getName());

    // establish credentials
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials();
    creds.setUsername(user.getName());
    user.setCredentials(creds);

    user.setAuthenticationStatus(user.getAuthenticationStatus());
    assertAdministratorRole(user);
  }