Package org.exoplatform.services.jcr.core

Examples of org.exoplatform.services.jcr.core.CredentialsImpl


    * org.exoplatform.services.jcr.access.AuthenticationPolicy#authenticate(javax.jcr.Credentials)
    */
   public final ConversationState authenticate(Credentials credentials) throws LoginException
   {

      CredentialsImpl thisCredentials;
      if (credentials instanceof CredentialsImpl)
      {
         thisCredentials = (CredentialsImpl)credentials;
      }
      else if (credentials instanceof SimpleCredentials)
      {
         String name = ((SimpleCredentials)credentials).getUserID();
         char[] pswd = ((SimpleCredentials)credentials).getPassword();
         thisCredentials = new CredentialsImpl(name, pswd);
      }
      else
         throw new LoginException(
            "Credentials for the authentication should be CredentialsImpl or SimpleCredentials type");

      // SYSTEM
      if (thisCredentials.getUserID().equals(SystemIdentity.SYSTEM))
      {
         Identity sid = new Identity(SystemIdentity.SYSTEM, new HashSet<MembershipEntry>());
         return new ConversationState(sid);
      }

      // prepare to new login
      // uses BasicCallbackHandler
      CallbackHandler handler = new BasicCallbackHandler(thisCredentials.getUserID(), thisCredentials.getPassword());

      // and try to login
      try
      {

         LoginContext loginContext = new LoginContext(config.getSecurityDomain(), handler);
         loginContext.login();

      }
      catch (javax.security.auth.login.LoginException e)
      {
         throw new LoginException("Login failed for " + thisCredentials.getUserID() + " " + e);
      }

      if (log.isDebugEnabled())
         log.debug("Logged " + thisCredentials.getUserID());

      // supposed to be set
      Identity identity = identityRegistry.getIdentity(thisCredentials.getUserID());
      if (identity == null)
      {
         throw new LoginException("Identity not found, check Loginmodule, userId " + thisCredentials.getUserID());
      }
      ConversationState state = new ConversationState(identity);
      String[] aNames = thisCredentials.getAttributeNames();
      for (String name : aNames)
      {
         state.setAttribute(name, thisCredentials.getAttribute(name));
      }

      ConversationState.setCurrent(state);
      return state;

View Full Code Here


   public BaseReplicationTestCase(RepositoryService repositoryService, String reposytoryName, String workspaceName,
      String userName, String password)
   {
      try
      {
         credentials = new CredentialsImpl(userName, password.toCharArray());

         repository = repositoryService.getRepository(reposytoryName);

         session = repository.login(credentials, workspaceName);
View Full Code Here

   public BaseReplicationTestCase(RepositoryService repositoryService, String reposytoryName, String workspaceName,
      String userName, String password)
   {
      try
      {
         credentials = new CredentialsImpl(userName, password.toCharArray());

         repository = repositoryService.getRepository(reposytoryName);

         session = repository.login(credentials, workspaceName);
View Full Code Here

    * from the {@link SessionRequestInfo}, otherwise we will use the credentials
    * defined in the configuration of the {@link ManagedSessionFactory}.
    */
   private Credentials getCredentials(final Subject subject, SessionRequestInfo sri) throws ResourceException
   {
      CredentialsImpl credentials = null;
      if (subject != null)
      {
         credentials = SecurityHelper.doPrivilegedAction(new PrivilegedAction<CredentialsImpl>()
         {
            public CredentialsImpl run()
            {
               Iterator<Object> i = subject.getPrivateCredentials().iterator();
               while (i.hasNext())
               {
                  Object o = i.next();
                  if (o instanceof PasswordCredential)
                  {
                     PasswordCredential cred = (PasswordCredential)o;
                     if (cred.getManagedConnectionFactory().equals(ManagedSessionFactory.this))
                     {
                        return new CredentialsImpl(cred.getUserName(), cred.getPassword());
                     }
                  }
               }
               return null;
            }
         });
      }
      if (credentials == null && sri.getUserName() != null)
      {
         credentials =
            new CredentialsImpl(sri.getUserName(), sri.getPassword() == null ? null : sri.getPassword()
               .toCharArray());
      }
      if (LOG.isDebugEnabled())
      {
         LOG.debug("getCredentials: login = " + (credentials == null ? "undefined" : credentials.getUserID()));
      }
      return credentials;
   }
View Full Code Here

      container = StandaloneContainer.getInstance();

      if (System.getProperty("java.security.auth.login.config") == null)
         System.setProperty("java.security.auth.login.config", loginConf);

      credentials = new CredentialsImpl("admin", "admin".toCharArray());

      repositoryService = (RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);

      repository = (RepositoryImpl)repositoryService.getRepository("db1");
      repository2 = (RepositoryImpl)repositoryService.getRepository("db2");
View Full Code Here

      if (System.getProperty("java.security.auth.login.config") == null)
         System.setProperty("java.security.auth.login.config", Thread.currentThread().getContextClassLoader()
            .getResource("login.conf").toString());

      credentials = new CredentialsImpl("root", "exo".toCharArray());

      repositoryService = (RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);

      repository = (RepositoryImpl)repositoryService.getDefaultRepository();
View Full Code Here

      handler.handleRequest(creq, cres);

      assertEquals(200, cres.getStatus());

      Session session =
         repositoryService.getRepository(rName).login(new CredentialsImpl("root", "exo".toCharArray()), wsName);
      assertNotNull(session);
      assertNotNull(session.getRootNode());
      session.logout();
   }
View Full Code Here

      handler.handleRequest(creq, cres);

      assertEquals(200, cres.getStatus());

      Session session =
         repositoryService.getRepository(rName).login(new CredentialsImpl("root", "exo".toCharArray()), wsName);
      assertNotNull(session);
      assertNotNull(session.getRootNode());
      session.logout();
   }
View Full Code Here

      handler.handleRequest(creq, cres);

      assertEquals(200, cres.getStatus());

      Session session =
         repositoryService.getRepository(rName).login(new CredentialsImpl("root", "exo".toCharArray()), wsName);
      assertNotNull(session);
      assertNotNull(session.getRootNode());

      session.logout();
   }
View Full Code Here

   public void testRemoveWorkspace() throws Exception
   {
      String wsName = "ws_over_rest_2";
      String rName = "repo_over_rest";
      Session session =
         repositoryService.getRepository(rName).login(new CredentialsImpl("root", "exo".toCharArray()), wsName);
      assertNotNull(session);
      assertNotNull(session.getRootNode());

      MultivaluedMap<String, String> headers = new MultivaluedMapImpl();

      ContainerRequestUserRole creq =
         new ContainerRequestUserRole("POST", new URI(REST_REPOSITORY_SERVICE_PATH
            + RestRepositoryService.Constants.OperationType.REMOVE_WORKSPACE + "/" + rName + "/" + wsName + "/false/"),
            new URI(""), null, new InputHeadersMap(headers));

      ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
      ContainerResponse cres = new ContainerResponse(responseWriter);
      handler.handleRequest(creq, cres);

      assertEquals(409, cres.getStatus());

      //remove with prepare close sessions
      creq =
         new ContainerRequestUserRole("POST", new URI(REST_REPOSITORY_SERVICE_PATH
            + RestRepositoryService.Constants.OperationType.REMOVE_WORKSPACE + "/" + rName + "/" + wsName + "/true/"),
            new URI(""), null, new InputHeadersMap(headers));

      responseWriter = new ByteArrayContainerResponseWriter();
      cres = new ContainerResponse(responseWriter);
      handler.handleRequest(creq, cres);

      assertEquals(200, cres.getStatus());

      try
      {
         repositoryService.getRepository(rName).login(new CredentialsImpl("root", "exo".toCharArray()), wsName);
         fail("The workspace /" + rName + "/" + wsName + "should be removed. ");
      }
      catch (NoSuchWorkspaceException e)
      {
         //ok.
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.core.CredentialsImpl

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.