Package models.entities

Examples of models.entities.User


        return F.Promise.pure(null);
    }

    @Override
    public Subject getSubject(final Http.Context context) {
        User user = null;
        String[] authTokenHeaderValues = context.request().headers().get(SecurityController.AUTH_TOKEN_HEADER);
        if ((authTokenHeaderValues != null) && (authTokenHeaderValues.length == 1) && (authTokenHeaderValues[0] != null)) {
            Logger.debug("got token "+ authTokenHeaderValues[0]);
            user = DaoManager.getUserDao().findByAuthToken(authTokenHeaderValues[0]);
            Logger.debug("found by token user " + user.getIdentifier());
            Logger.debug("user roles size" + user.getRoles().size() + " first role is " + user.getRoles().get(0).getName());
            if (user != null) {
                context.args.put("user", user);
            }
        }
        return user;
View Full Code Here


    public void getUserTest() {
        running(fakeApplication(), new Runnable() {
            public void run() {
                DemoData.loadDemoData();

                User user = DemoData.user1;

                Result result = callAction(routes.ref.UserController.getUser(user.getId()));
                Logger.debug("response: " + contentAsString(result));
                JsonNode resultJson = Json.parse(contentAsString(result));
                assertThat(status(result)).isEqualTo(OK);
                assertThat(resultJson.get("login").asText()).isEqualTo(user.getLogin());
            }
        });
    }
View Full Code Here

                JPA.withTransaction(new F.Callback0() {
                    @Override
                    public void invoke() throws Throwable {
                        try {
                            User savedUser = DaoManager.getUserDao().getBatch(0, 1).get(0);
                            assertNotNull(savedUser.getId());
                            assertThat(savedUser.getLogin()).isEqualTo("login1");
                        } catch (DataAccessException e) {
                            e.printStackTrace();
                        }
                    }
                });
View Full Code Here

                assertThat(status(result)).isEqualTo(OK);

                JPA.withTransaction(new F.Callback0() {
                    @Override
                    public void invoke() throws Throwable {
                        User savedUser = DaoManager.getUserDao().getBatch(0,2).get(0);
                        assertNotNull(savedUser.getId());
                        assertThat(savedUser.getLogin()).isEqualTo("login1");
                    }
                });
            }
        });
    }
View Full Code Here

    @Transactional
    @Restrict({@Group("manager"), @Group("admin"), @Group("supervisor")})
    public static Result getUser(Integer id) {
        try {
            User user = DaoManager.getUserDao().findById(id);
            if (user == null) {
                return notFound("Can't find user with id " + id);
            }
            UserDto userDto = UserDto.createFrom(user);
            return ok(toJson(userDto));
View Full Code Here

    @Transactional
    public static Result addNew() {
        try {
            Logger.debug("add req body: " + request().body().asJson().toString());
            UserDto userDto = new ObjectMapper().readValue(request().body().asJson().toString(), UserDto.class);
            User newUser = new User();
            userDto.mapBack(newUser);
            ConstraintViolation[] violations = Utilities.validateEntity(newUser);
            if (violations.length > 0) {
                return badRequest(Utilities.violationsToJson(violations));
            }
View Full Code Here

    }

    @Transactional
    public static Result update(int userId) {
        try {
            User user = DaoManager.getUserDao().findById(userId);
            if (user == null) {
                return notFound(Utilities.getJsonErrorNode("Can't find user with id " + userId));
            }
            Logger.debug("update req body: " + request().body().asJson().toString());
            UserDto userDto = new ObjectMapper().readValue(request().body().asJson().toString(), UserDto.class);
View Full Code Here

    }

    @Transactional
    public static Result remove(int userId) {
        try {
            User user = DaoManager.getUserDao().findById(userId);
            if (user == null) {
                return notFound(Utilities.getJsonErrorNode("Can't find user with id " + userId));
            }
            DaoManager.getUserDao().remove(user);
        } catch (DataAccessException e) {
View Full Code Here

            return badRequest(loginForm.errorsAsJson());
        }

        Login login = loginForm.get();

        User user = DaoManager.getUserDao().findByLoginAndPassword(login.login, login.password);

        if (user == null) {
            return unauthorized();
        } else {
            Logger.debug("User login " + user.getLogin() + " and pass " + user.getPassword());
            user.setAuthToken(Utilities.createToken());
            try {
                DaoManager.getUserDao().persist(user);
            } catch (DataAccessException e) {
                Logger.error("failed to persist user after token creation", e);
                return internalServerError();
            }
            ObjectNode authTokenJson = Json.newObject();
            authTokenJson.put(AUTH_TOKEN, user.getAuthToken());
            response().setCookie(AUTH_TOKEN, user.getAuthToken());
            return ok(authTokenJson);
        }
    }
View Full Code Here

        TypedQuery<User> query = JPA.em()
                .createQuery("SELECT u FROM User u WHERE u.login = :login AND u.shaPassword = :shaPassword", User.class);
        query.setParameter("login", login);
        query.setParameter("shaPassword", Utilities.getSha512(password));
        try {
            User user = query.getSingleResult();
            Logger.debug("FIND User login " + user.getLogin() + " and pass " + user.getPassword());
            return user;
        } catch (Exception e) {
            Logger.error("find user by Login And Password failed for login " + login + " and password " + password, e);
            return null;
        }
View Full Code Here

TOP

Related Classes of models.entities.User

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.