Package com.streamreduce.core.model

Examples of com.streamreduce.core.model.User


                .url("http://nodeable.com")
                .description("Nodeable Test Account")
                .name("Nodeable Testing")
                .build();

        User testUser = new User.Builder()
                .account(testAccount)
                .accountLocked(false)
                .accountOriginator(true)
                .fullname("Nodeable Test User")
                .username("test_user_" + new Date().getTime() + "@nodeable.com")
View Full Code Here


        return new UserAuthenticationToken(token);
    }

    @Override
    protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception {
        User user = userService.getUserByAuthenticationToken(((NodeableAuthenticationToken) token).getToken());
        user.setLastActivity(new Date());
        userService.updateUser(user);
        return super.onLoginSuccess(token, subject, request, response);
    }
View Full Code Here

//        }
//    }

    @Override
    public void sendCommentAddedEmail(Account account, SobaMessage sobaMessage, MessageComment comment) {
        User owner = null;
        if (sobaMessage.getOwnerId() != null) {
            try {
                owner = userService.getUserById(sobaMessage.getOwnerId());
            }
            catch (UserNotFoundException e) {
                logger.error("User not found for ID {}. Cannot send email.", sobaMessage.getOwnerId());
                return;
            }
        }

        String from = (String) emailProperties.get("email.noreply.from");
        String subject = (String) emailProperties.get("email.comment.added.subject");
        String urlPrefix = (String) emailProperties.get("email.urlprefix");

        // try to use a sensible default if the details or title are null
        String title = "User Comment";
        if (sobaMessage.getDetails() != null) {
            AbstractMessageDetails details = (AbstractMessageDetails) sobaMessage.getDetails();
            if (details.getTitle() != null) {
                title = details.getTitle();
            }
        }

        VelocityContext context = new VelocityContext();
        context.put("messageId", sobaMessage.getId());
        context.put("commenter", comment.getFullName());
        context.put("messageType", getFriendlyMessageTypeLabel(sobaMessage.getType()));
        context.put("urlPrefix", urlPrefix);
        context.put("title", title);
        context.put("comment", comment.getComment());

        List<User> enabledUsers = userService.allEnabledUsersForAccount(account);
        for (User user : enabledUsers) {
            // don't send if the commenter is the owner or if the user has elected to not receive notifications
            if (owner == null || !user.getId().equals(owner.getId()) || !receivesCommentNotifications(user)) {
                sendEmail(user.getUsername(), from, subject, "comment_added", context);
            }
        }
    }
View Full Code Here

    public void sendConnectionBrokenEmail(Connection connection) {
        String from = (String) emailProperties.get("email.noreply.from");
        String subject = (String) emailProperties.get("email.connection.error.subject");
        String urlPrefix = (String) emailProperties.get("email.urlprefix");

        User accountAdmin = userService.getAccountAdmin(connection.getAccount());

        VelocityContext context = new VelocityContext();
        context.put("urlPrefix", urlPrefix);
        context.put("connectionName", connection.getAlias());
        context.put("connectionId", connection.getId());

        sendEmail(accountAdmin.getUsername(), from, subject, "connection_error", context);
    }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public <T extends ObjectWithId> Event createEvent(EventId eventId, T target, Map<String, Object> extraMetadata) {
        Account account = null;
        User user = null;

        try {
            user = securityService.getCurrentUser();
            account = user.getAccount();
        } catch (AuthenticationException ae) {
            // We will not persist any READ_* events when a user is not logged in
            if (eventId == EventId.READ) {
                logger.debug("Anonymous read events are not persisted (" + target + "): " + eventId);
                return null;
            }
        } catch (UnavailableSecurityManagerException e) {
            logger.warn("Unable to derive user from SecurityService.  A User will be derived from the target (" +
                              target + ") if possible.  If not, no event will be persisted", e);
        } catch (Exception nfi) {
            logger.warn("Unknown exception type in EventService", nfi);
        }

        if (extraMetadata == null) {
            extraMetadata = new HashMap<>();
        }

        // TODO: Figure out a way to make these automatically-generated metadata keys constants somewhere

        // Extend the context with T information
        if (target != null) {
            // Fill out ObjectWithId information
            extraMetadata.put("targetId", target.getId());
            extraMetadata.put("targetVersion", target.getVersion());
            // Fill out type (camel casing of the object type)
            extraMetadata.put("targetType", target.getClass().getSimpleName());

            // Fill out the SobaObject information
            if (target instanceof SobaObject) {
                SobaObject tSobaObject = (SobaObject) target;

                // Attempt to gather the user/account from the target of the event when there is no user logged in.
                // We can only do this for subclasses of SobaObject because the other two objects that create events
                // (Account/User) can only provide one piece of the puzzle.
                if (user == null) {
                    user = tSobaObject.getUser();
                    account = tSobaObject.getAccount();
                }

                extraMetadata.put("targetVisibility", tSobaObject.getVisibility());
                extraMetadata.put("targetAlias", tSobaObject.getAlias());
                extraMetadata.put("targetHashtags", tSobaObject.getHashtags());
            }

            // Fill in specific object information
            if (target instanceof Account) {
                Account tAccount = (Account) target;
                extraMetadata.put("targetFuid", tAccount.getFuid());
                extraMetadata.put("targetName", tAccount.getName());

            } else if (target instanceof InventoryItem) {
                InventoryItem inventoryItem = (InventoryItem)target;
                Connection connection = inventoryItem.getConnection();
                ConnectionProvider tConnectionProvider = connectionProviderFactory.connectionProviderFromId(
                        connection.getProviderId());

                extraMetadata.put("targetExternalId", inventoryItem.getExternalId());
                extraMetadata.put("targetExternalType", inventoryItem.getType());

                extraMetadata.put("targetConnectionId", connection.getId());
                extraMetadata.put("targetConnectionAlias", connection.getAlias());
                extraMetadata.put("targetConnectionHashtags", connection.getHashtags());
                extraMetadata.put("targetConnectionVersion", connection.getVersion());

                extraMetadata.put("targetProviderId", tConnectionProvider.getId());
                extraMetadata.put("targetProviderDisplayName", tConnectionProvider.getDisplayName());
                extraMetadata.put("targetProviderType", tConnectionProvider.getType());

                // Fill in the extra metadata stored in the nodeMetadata
                extraMetadata.putAll(getMetadataFromInventoryItem(inventoryItem));
            } else if (target instanceof Connection) {
                Connection tConnection = (Connection) target;
                ConnectionProvider tConnectionProvider = connectionProviderFactory.connectionProviderFromId(
                        tConnection.getProviderId());

                extraMetadata.put("targetProviderId", tConnectionProvider.getId());
                extraMetadata.put("targetProviderDisplayName", tConnectionProvider.getDisplayName());
                extraMetadata.put("targetProviderType", tConnectionProvider.getType());

            } else if (target instanceof User) {
                User tUser = (User) target;

                extraMetadata.put("targetFuid", tUser.getFuid());
                extraMetadata.put("targetFullname", tUser.getFullname());
                extraMetadata.put("targetUsername", tUser.getUsername());

            } else if (target instanceof SobaMessage) {
                // This is actually already handled in MessageServiceImpl.  This was just put here to help keep track
                // of the different types of objects we're supporting in case we want to do more later.
            }
View Full Code Here

    // for a certain account
    @SuppressWarnings({"rawtypes", "unchecked"})
    @Override
    public SobaMessage sendNodeableAccountMessage(Event event, Account account, Set<String> hashtags) {

        User sender = userService.getSystemUser();
        // this enables us to save in a target account rather than use the senders account
        sender.setAccount(account);
        return sendAccountMessage(
                event,
                sender, // sent from nodebelly
                null, // no connectionId right now
                new Date().getTime(),
View Full Code Here

        SobaMessage sobaMessage = null;

        try {
            // if this is the sender, should we override the ownerId? how?
            User nodebelly = userService.getSuperUser();

            // if this is null, it's a global metric so only persist the message to the Nodeable account
            if (event.getAccountId() != null) {
                Account account = userService.getAccount(event.getAccountId());

                // send an email if these are your first insights
                // SOBA-1600
                if (!account.getConfigValue(Account.ConfigKey.RECIEVED_INSIGHTS)) {
                    userService.handleInitialInsightForAccount(account);
                }

                // trickery to send from Nodebelly to a certain account
                // DO NOT PERSIST THIS!!!!!
                // also note how this is set last so the account references above are still valid to the "real" account
                nodebelly.setAccount(account);
            }

            Map<String, Object> meta = event.getMetadata();
            String objectType = (String) meta.get("targetType");
            String providerTypeId = (String) meta.get("targetProviderId");
View Full Code Here

        Collection c = principals.fromRealm(name);
        if (c.size() < 1) {
            return null;
        }
        ObjectId userId = (ObjectId) c.iterator().next();
        User user = userDAO.get(userId);
        if (user != null) {
            SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
            for (Role role : user.getRoles()) {
                logger.debug("Add Role of " + role.getName() + " to user " + user.getUsername());
                info.addRole(role.getName());
                info.addStringPermissions(role.getPermissions());
            }
            return info;
        } else {
View Full Code Here

        NodeableAuthenticationToken token = (UserAuthenticationToken) authcToken;

        logger.debug("Attempting to get authentication info for" + ((UserAuthenticationToken) authcToken).getToken());

        User theUser = securityService.getUserFromAuthenticationToken(token.getToken());

        if (theUser == null) {
            throw new AuthenticationException(ErrorMessages.INVALID_CREDENTIAL);
        }

        logger.debug("UserId is set to " + theUser.getUser().getId());

        // token is expired
//        if (userToken.getExpirationDate() < System.currentTimeMillis()) {
//            throw new AuthenticationException(ErrorMessages.EXPIRED_CREDENTIAL);
//        }
        // all is well so far...

        return new SimpleAuthenticationInfo(theUser.getId(), "", getName());
    }
View Full Code Here

    @POST
    @Path("{messageId}/email")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response email(@PathParam("messageId") ObjectId messageId, JSONObject json) {

        User user = applicationManager.getSecurityService().getCurrentUser();

        SobaMessage message;
        try {
            message = applicationManager.getMessageService().getMessage(user.getAccount(), messageId);
        }
        catch (MessageNotFoundException mnfe) {
            logger.error("Unable to find message with ID {}", messageId);
            return Response.status(404).build();
        }
View Full Code Here

TOP

Related Classes of com.streamreduce.core.model.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.