예제 #1
0
  /** Generates a valid Atom id. */
  public String generateAtomId(String input) {
    if (input == null) {
      return ID_DUMMY;
    }

    return ID_PREFIX + Base64.encodeBytes(IOUtils.toUTF8Bytes(input));
  }
  private String getSecurityToken() {
    try {
      Class<?> wsSubjectClass =
          ClassLoaderUtil.loadClass("com.ibm.websphere.security.auth.WSSubject");
      Class<?> wsCredentialClass =
          ClassLoaderUtil.loadClass("com.ibm.websphere.security.cred.WSCredential");

      // Get current security subject
      Method m = wsSubjectClass.getMethod("getRunAsSubject", new Class[0]);
      Subject securitySubject = (Subject) m.invoke(null, new Object[0]);
      if (securitySubject != null) {
        // Get all security credentials from the security subject
        Set<?> securityCredentials = securitySubject.getPublicCredentials(wsCredentialClass);

        // Get the first credential
        Object securityCredential = securityCredentials.iterator().next();
        String user =
            invokeSecurityCredentialMethod(
                wsCredentialClass, securityCredential, "getSecurityName");

        if (user.equalsIgnoreCase("UNAUTHENTICATED")) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("User = UNAUTHENTICATED");
          }
          return null;
        }

        byte[] token =
            invokeSecurityCredentialMethod(
                wsCredentialClass, securityCredential, "getCredentialToken");
        if (token == null) {
          return null;
        }

        return Base64.encodeBytes(token);
      }
    } catch (Exception e) {
      throw new CmisRuntimeException("Could not build SOAP header: " + e.getMessage(), e);
    }

    return null;
  }