Examples of StoredUser


Examples of org.jboss.resteasy.keystone.model.StoredUser

   @Consumes("application/json")
   @Produces("application/json")
   @Path("{id}")
   public void update(@PathParam("id") String id, StoredUser user) throws Exception
   {
      StoredUser stored = getStoredUser(id);
      if (stored == null) throw new NotFoundException();
      if (user.getName() != null) stored.setName(user.getName());
      if (user.getEnabled() != null) stored.setEnabled(user.getEnabled());
      if (user.getEmail() != null) stored.setEmail((user.getEmail()));
      if (user.getCredentials() != null && user.getCredentials().containsKey("password"))
      {
         String password = user.getCredentials().remove("password");
         MessageDigest digest = MessageDigest.getInstance("MD5");
         String hashPassword = Base64.encodeBytes(digest.digest(password.getBytes("UTF-8")));
         stored.getCredentials().put("password", hashPassword);
      }
      cache.put("/users/" + id, stored, -1, TimeUnit.MILLISECONDS);
   }
View Full Code Here

Examples of org.jboss.resteasy.keystone.model.StoredUser

   @GET
   @Path("{id}")
   @Produces("application/json")
   public User get(@PathParam("id") String id)
   {
      StoredUser user = getStoredUser(id);
      if (user == null) throw new NotFoundException();

      return user.toUser();
   }
View Full Code Here

Examples of org.jboss.resteasy.keystone.model.StoredUser

         String username = auth.getPasswordCredentials().getUsername();
         if (username == null) throw new WebApplicationException(401);
         userId = projects.getUserIdByName(projectId, username);
      }
      if (userId == null) throw new WebApplicationException(401);
      StoredUser user = users.getStoredUser(userId);
      if (user == null) throw new WebApplicationException(401);
      String password = auth.getPasswordCredentials().getPassword();
      MessageDigest digest = MessageDigest.getInstance("MD5");
      String hashPassword = Base64.encodeBytes(digest.digest(password.getBytes("UTF-8")));
      String savedPassword = user.getCredentials().get("password-hash");
      if (!hashPassword.equals(savedPassword)) throw new WebApplicationException(401);

      Roles roles = projects.getUserRoles(projectId, userId);
      if (roles == null || roles.getRoles().size() < 1) throw new WebApplicationException(403);

      String tokenId = UUID.randomUUID().toString();
      long expMillis = expirationUnit.toMillis(expiration);
      Calendar expires = Calendar.getInstance();
      expires.setTime(new Date(System.currentTimeMillis() + expMillis));
      Access.Token token = new Access.Token(tokenId, expires, project);
      Access.User userInfo = new Access.User(user.getId(), user.getName(), user.getUsername(), roles.getRoles());
      Access access = new Access(token, null, userInfo, null);
      cache.put("/tokens/" + tokenId, access, expiration, expirationUnit);
      return access;
   }
View Full Code Here

Examples of org.jboss.resteasy.keystone.model.StoredUser

         String username = auth.getPasswordCredentials().getUsername();
         if (username == null) throw new WebApplicationException(401);
         userId = projects.getUserIdByName(projectId, username);
      }
      if (userId == null) throw new WebApplicationException(401);
      StoredUser user = users.getStoredUser(userId);
      if (user == null) throw new WebApplicationException(401);
      String password = auth.getPasswordCredentials().getPassword();
      MessageDigest digest = MessageDigest.getInstance("MD5");
      String hashPassword = Base64.encodeBytes(digest.digest(password.getBytes("UTF-8")));
      String savedPassword = user.getCredentials().get("password-hash");
      if (!hashPassword.equals(savedPassword)) throw new WebApplicationException(401);

      Roles roles = projects.getUserRoles(projectId, userId);
      if (roles == null || roles.getRoles().size() < 1) throw new WebApplicationException(403);

      String tokenId = UUID.randomUUID().toString();
      long expMillis = expirationUnit.toMillis(expiration);
      Calendar expires = Calendar.getInstance();
      expires.setTime(new Date(System.currentTimeMillis() + expMillis));

      UrlToken tiny = new UrlToken();
      //tiny.setId(tokenId);
      tiny.setUserId(user.getId());
      tiny.setExpires(expires);
      tiny.setProjectId(projectId);
      for (Role role : roles)
      {
         tiny.getRoles().add(role.getName());
View Full Code Here

Examples of org.jboss.resteasy.keystone.model.StoredUser

      privateKey = keyPair.getPrivate();
      certificate = KeyTools.generateTestCertificate(keyPair);
      app.getTokenService().setCertificate(certificate);
      app.getTokenService().setPrivateKey(privateKey);

      StoredUser admin = new StoredUser();
      admin.setName("Bill");
      admin.setUsername("wburke");
      HashMap<String, String> creds = new HashMap<String, String>();
      creds.put("password", "geheim");
      admin.setCredentials(creds);
      app.getUsers().create(admin);

      Project project = new Project();
      project.setName("Skeleton Key");
      project.setEnabled(true);
      app.getProjects().createProject(project);

      Role adminRole = new Role();
      adminRole.setName("admin");
      app.getRoles().create(adminRole);

      app.getProjects().addUserRole(project.getId(), admin.getId(), adminRole.getId());

      // Test export/import
      System.out.println(new Loader().export(app.getCache()));

      try
View Full Code Here

Examples of org.jboss.resteasy.keystone.model.StoredUser

      RegisterBuiltin.register(providerFactory);
      ResteasyClient client = new ResteasyClientBuilder().providerFactory(providerFactory).build();
      WebTarget target = client.target(generateBaseUrl());
      SkeletonKeyAdminClient admin = new SkeletonKeyClientBuilder().username("wburke").password("geheim").idp(target).admin();

      StoredUser newUser = new StoredUser();
      newUser.setName("John Smith");
      newUser.setUsername("jsmith");
      newUser.setEnabled(true);
      Map creds = new HashMap();
      creds.put("password", "foobar");
      newUser.setCredentials(creds);
      Response response = admin.users().create(newUser);
      User user = response.readEntity(User.class);
      response = admin.roles().create("user");
      Role role = response.readEntity(Role.class);
      Projects projects = admin.projects().query("Skeleton Key");
View Full Code Here

Examples of org.jboss.resteasy.keystone.model.StoredUser

      RegisterBuiltin.register(providerFactory);
      ResteasyClient client = new ResteasyClientBuilder().providerFactory(providerFactory).build();
      WebTarget target = client.target(generateBaseUrl());
      SkeletonKeyAdminClient admin = new SkeletonKeyClientBuilder().username("wburke").password("geheim").idp(target).admin();

      StoredUser newUser = new StoredUser();
      newUser.setName("John Smith");
      newUser.setUsername("jsmith");
      newUser.setEnabled(true);
      Map creds = new HashMap();
      creds.put("password", "foobar");
      newUser.setCredentials(creds);
      Response response = admin.users().create(newUser);
      User user = response.readEntity(User.class);
      response = admin.roles().create("user");
      Role role = response.readEntity(Role.class);
      Projects projects = admin.projects().query("Skeleton Key");
View Full Code Here

Examples of org.jboss.resteasy.keystone.model.StoredUser

   {
      app = new SkeletonKeyApplication(confgurable);

      try
      {
         StoredUser admin = new StoredUser();
         admin.setName("Bill");
         admin.setId("1");
         admin.setUsername("admin");
         HashMap<String, String> creds = new HashMap<String, String>();
         creds.put("password", "geheim");
         admin.setCredentials(creds);
         app.getUsers().create(admin);

         Project project = new Project();
         project.setName("Skeleton Key");
         project.setEnabled(true);
         app.getProjects().createProject(project);

         Role adminRole = new Role();
         adminRole.setName("admin");
         app.getRoles().create(adminRole);

         app.getProjects().addUserRole(project.getId(), admin.getId(), adminRole.getId());

         project = new Project();
         project.setId("42");
         project.setName("Skeleton App");
         project.setEnabled(true);
         app.getProjects().createProject(project);

         Role userRole = new Role();
         userRole.setName("user");
         app.getRoles().create(userRole);

         StoredUser user = new StoredUser();
         user.setName("Some User");
         user.setUsername("someuser");
         creds = new HashMap<String, String>();
         creds.put("password", "geheim");
         user.setCredentials(creds);
         app.getUsers().create(user);


         app.getProjects().addUserRole(project.getId(), user.getId(), userRole.getId());

         StoredUser superuser = new StoredUser();
         superuser.setName("Super User");
         superuser.setUsername("superuser");
         creds = new HashMap<String, String>();
         creds.put("password", "geheim");
         superuser.setCredentials(creds);
         app.getUsers().create(superuser);


         app.getProjects().addUserRole(project.getId(), superuser.getId(), adminRole.getId());
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
View Full Code Here

Examples of org.jboss.resteasy.keystone.model.StoredUser

   private static SkeletonKeyApplication app;

   public static void init() throws Exception
   {

      StoredUser admin = new StoredUser();
      admin.setName("Bill");
      admin.setUsername("wburke");
      HashMap<String, String> creds = new HashMap<String, String>();
      creds.put("password", "geheim");
      admin.setCredentials(creds);
      app.getUsers().create(admin);

      Project project = new Project();
      project.setName("Skeleton Key");
      project.setEnabled(true);
      app.getProjects().createProject(project);

      Role adminRole = new Role();
      adminRole.setName("admin");
      app.getRoles().create(adminRole);

      app.getProjects().addUserRole(project.getId(), admin.getId(), adminRole.getId());

      // Test export/import
      System.out.println(new Loader().export(app.getCache()));

      try
View Full Code Here

Examples of org.jboss.resteasy.keystone.model.StoredUser

      startDeployment();
      ResteasyClient client = new ResteasyClientBuilder().build();
      WebTarget target = client.target(generateBaseUrl());
      SkeletonKeyAdminClient admin = new SkeletonKeyClientBuilder().username("wburke").password("geheim").idp(target).admin();

      StoredUser newUser = new StoredUser();
      newUser.setName("John Smith");
      newUser.setUsername("jsmith");
      newUser.setEnabled(true);
      Map creds = new HashMap();
      creds.put("password", "foobar");
      newUser.setCredentials(creds);
      Response response = admin.users().create(newUser);
      User user = response.readEntity(User.class);
      response = admin.roles().create("user");
      Role role = response.readEntity(Role.class);
      Projects projects = admin.projects().query("Skeleton Key");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.