Exemplo n.º 1
0
  /** @see FlowService#executeJob(String, String, String, long, long, String) */
  @Override
  public Job executeJob(
      Credentials credentials,
      String token,
      String name,
      String description,
      long flowInstanceId,
      long userId,
      String userEmail) {
    FlowDao flowDao = daoFactory.getFlowDao();
    JobDao jobDao = daoFactory.getJobDao();

    Flow flowInstance = flowDao.findById(flowInstanceId, false);

    Job job = new Job();
    job.setToken(token);
    job.setName(name);
    job.setDescription(description);
    job.setFlow(flowInstance);
    job.setOwnerId(userId);
    job.setOwnerEmail(userEmail);
    SimpleCredentials simpleCreds = (SimpleCredentials) credentials;
    String serializedCreds = simpleCreds.getUserID() + ":" + new String(simpleCreds.getPassword());
    job.setCredentials(serializedCreds);
    jobDao.makePersistent(job);

    jobScheduler.scheduleJob(job);
    job.setJobStatus(JobStatus.SCHEDULED);
    job.setScheduleTimestamp(new Date());
    jobDao.makePersistent(job);

    jobStatusMonitor.start(job, notificationCreator);

    return job;
  }
  public void testGetPassword2() throws NoSuchAlgorithmException, UnsupportedEncodingException {
    CryptedSimpleCredentials prev = cCreds.get(0);
    // build crypted credentials from the uid and the crypted pw contained
    // in simple credentials -> simple-c-password must be treated plain-text
    SimpleCredentials sc = new SimpleCredentials(userID, prev.getPassword().toCharArray());
    CryptedSimpleCredentials diff = new CryptedSimpleCredentials(sc);

    assertFalse(prev.getPassword().equals(diff.getPassword()));
    assertFalse(String.valueOf(sc.getPassword()).equals(diff.getPassword()));
  }
Exemplo n.º 3
0
 public void logout() {
   for (Session session : sessions.values()) {
     session.logout();
   }
   if (credentials instanceof SimpleCredentials) {
     SimpleCredentials simpleCredentials = (SimpleCredentials) credentials;
     JahiaLoginModule.removeToken(
         simpleCredentials.getUserID(), new String(simpleCredentials.getPassword()));
   }
   isLive = false;
   activeSessions.decrementAndGet();
 }
  /**
   * {@inheritDoc}
   *
   * <p>Creates a {@code UsernamePasswordAuthenticationToken} from the given {@code principal} and
   * {@code credentials} and passes to Spring Security {@code AuthenticationManager}.
   */
  @Override
  protected Authentication getAuthentication(
      final Principal principal, final Credentials credentials) throws RepositoryException {

    // only handles SimpleCredential instances; DefaultLoginModule behaves the same way (albeit
    // indirectly)
    if (!(credentials instanceof SimpleCredentials)) {
      logger.debug("credentials not instance of SimpleCredentials; returning null"); // $NON-NLS-1$
      return null;
    }

    SimpleCredentials simpleCredentials = (SimpleCredentials) credentials;

    UsernamePasswordAuthenticationToken token =
        new UsernamePasswordAuthenticationToken(
            simpleCredentials.getUserID(), String.valueOf(simpleCredentials.getPassword()));

    boolean authenticated = false;

    try {
      org.springframework.security.Authentication authentication =
          SecurityContextHolder.getContext().getAuthentication();
      if (authentication != null
          && authentication.getName().equals(simpleCredentials.getUserID())) {
        // see if there's already an active Authentication for this user.
        authenticated = true;
      } else {
        // delegate to Spring Security
        getAuthenticationManager().authenticate(token);
        authenticated = true;
      }
    } catch (AuthenticationException e) {
      logger.debug("authentication exception", e); // $NON-NLS-1$
    }

    final boolean authenticateResult = authenticated;

    return new Authentication() {
      public boolean canHandle(Credentials credentials) {
        // this is decided earlier in getAuthentication
        return true;
      }

      public boolean authenticate(Credentials credentials) throws RepositoryException {
        return authenticateResult;
      }
    };
  }
  @Override
  public boolean login() throws LoginException {
    Credentials credentials = getCredentials();
    if (!(credentials instanceof SimpleCredentials)) {
      return super.login();
    }

    Principal principal = getPrincipal(credentials);
    if (principal == null) {
      SimpleCredentials cred = (SimpleCredentials) credentials;
      if (!createLogin(getUserID(credentials), String.valueOf(cred.getPassword()))) {
        return false;
      }
    }

    return super.login();
  }
Exemplo n.º 6
0
  public Session getProviderSession(JCRStoreProvider provider) throws RepositoryException {
    if (sessions.get(provider) == null) {
      Session s = null;

      if (credentials instanceof SimpleCredentials) {
        SimpleCredentials simpleCredentials = (SimpleCredentials) credentials;
        JahiaLoginModule.Token t =
            JahiaLoginModule.getToken(
                simpleCredentials.getUserID(), new String(simpleCredentials.getPassword()));

        s = provider.getSession(credentials, workspace.getName());

        credentials =
            JahiaLoginModule.getCredentials(
                simpleCredentials.getUserID(), t != null ? t.deniedPath : null);
      } else {
        s = provider.getSession(credentials, workspace.getName());
      }

      sessions.put(provider, s);
      for (String token : tokens) {
        s.addLockToken(token);
      }

      NamespaceRegistry namespaceRegistryWrapper = getWorkspace().getNamespaceRegistry();
      NamespaceRegistry providerNamespaceRegistry = s.getWorkspace().getNamespaceRegistry();

      if (providerNamespaceRegistry != null) {
        for (String prefix : namespaceRegistryWrapper.getPrefixes()) {
          try {
            providerNamespaceRegistry.getURI(prefix);
          } catch (NamespaceException ne) {
            providerNamespaceRegistry.registerNamespace(
                prefix, namespaceRegistryWrapper.getURI(prefix));
          }
        }
      }

      for (String prefix : prefixToNs.keySet()) {
        s.setNamespacePrefix(prefix, prefixToNs.get(prefix));
      }
    }
    return sessions.get(provider);
  }
  @Override
  protected String getUserID(Credentials credentials) {
    if (!(credentials instanceof SimpleCredentials)) {
      return super.getUserID(credentials);
    }

    SimpleCredentials cred = (SimpleCredentials) credentials;
    String id = cred.getUserID();
    if (id == null) {
      return super.getUserID(credentials);
    }

    String key = id + String.valueOf(cred.getPassword());
    String userId = ids.get(key);
    if (userId != null) {
      return userId;
    }

    boolean realId = false;
    Object realIdAttr = cred.getAttribute(JackrabbitConstants.REAL_USER_ID_USED);
    if (realIdAttr instanceof String) {
      realId = Boolean.valueOf((String) realIdAttr);
    }

    if (!realId) {
      try {
        LoginTable loginTable = LoginDBHandler.getUserLoginByUserName(id);
        userId = loginTable == null ? null : String.valueOf(loginTable.getUserId());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (userId == null) {
      userId = super.getUserID(credentials);
    }

    if (userId != null) {
      ids.put(key, userId);
    }

    return userId;
  }