Search in sources :

Example 6 with UserId

use of edu.stanford.bmir.protege.web.shared.user.UserId in project webprotege by protegeproject.

the class UserIdSuggestOracle method requestSuggestions.

@Override
public void requestSuggestions(final Request request, final Callback callback) {
    dispatchServiceManager.execute(new GetUserIdCompletionsAction(request.getQuery()), new DispatchServiceCallback<GetPossibleItemCompletionsResult<UserId>>() {

        @Override
        public void handleSuccess(GetPossibleItemCompletionsResult<UserId> result) {
            Collection<Suggestion> suggestions = new ArrayList<>();
            for (final UserId userId : result.getPossibleItemCompletions()) {
                suggestions.add(new Suggestion() {

                    @Override
                    public String getDisplayString() {
                        String userName = userId.getUserName();
                        String query = request.getQuery();
                        int queryIndex = userName.toLowerCase().indexOf(query.toLowerCase());
                        if (queryIndex != -1) {
                            return userName.substring(0, queryIndex) + "<span style='font-weight: bold;'>" + userName.substring(queryIndex, queryIndex + query.length()) + "</span>" + userName.substring(queryIndex + query.length());
                        } else {
                            return userName;
                        }
                    }

                    @Override
                    public String getReplacementString() {
                        return userId.getUserName();
                    }
                });
            }
            callback.onSuggestionsReady(request, new Response(suggestions));
        }
    });
}
Also used : GetPossibleItemCompletionsResult(edu.stanford.bmir.protege.web.shared.itemlist.GetPossibleItemCompletionsResult) GetUserIdCompletionsAction(edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) Collection(java.util.Collection)

Example 7 with UserId

use of edu.stanford.bmir.protege.web.shared.user.UserId in project webprotege by protegeproject.

the class ResetPasswordActionHandler method execute.

@Nonnull
@Override
public ResetPasswordResult execute(@Nonnull ResetPasswordAction action, @Nonnull ExecutionContext executionContext) {
    final String emailAddress = action.getResetPasswordData().getEmailAddress();
    try {
        Optional<UserId> userId = userDetailsManager.getUserByUserIdOrEmail(emailAddress);
        if (!userId.isPresent()) {
            return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
        }
        Optional<UserDetails> userDetails = userDetailsManager.getUserDetails(userId.get());
        if (!userDetails.isPresent()) {
            return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
        }
        if (!userDetails.get().getEmailAddress().isPresent()) {
            return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
        }
        if (!userDetails.get().getEmailAddress().get().equalsIgnoreCase(emailAddress)) {
            return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
        }
        String pwd = IdUtil.getBase62UUID();
        Salt salt = saltProvider.get();
        SaltedPasswordDigest saltedPasswordDigest = passwordDigestAlgorithm.getDigestOfSaltedPassword(pwd, salt);
        authenticationManager.setDigestedPassword(userId.get(), saltedPasswordDigest, salt);
        mailer.sendEmail(userId.get(), emailAddress, pwd, ex -> {
            throw new RuntimeException(ex);
        });
        logger.info("The password for {} has been reset.  " + "An email has been sent to {} that contains the new password.", userId.get().getUserName(), emailAddress);
        return new ResetPasswordResult(SUCCESS);
    } catch (Exception e) {
        logger.error("Could not reset the user password " + "associated with the email " + "address {}.  The following " + "error occurred: {}.", emailAddress, e.getMessage(), e);
        return new ResetPasswordResult(INTERNAL_ERROR);
    }
}
Also used : Salt(edu.stanford.bmir.protege.web.shared.auth.Salt) UserDetails(edu.stanford.bmir.protege.web.shared.user.UserDetails) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) SaltedPasswordDigest(edu.stanford.bmir.protege.web.shared.auth.SaltedPasswordDigest) ResetPasswordResult(edu.stanford.bmir.protege.web.shared.chgpwd.ResetPasswordResult) Nonnull(javax.annotation.Nonnull)

Example 8 with UserId

use of edu.stanford.bmir.protege.web.shared.user.UserId in project webprotege by protegeproject.

the class GetChapSessionActionHandler method execute.

@Nonnull
@Override
public GetChapSessionResult execute(@Nonnull GetChapSessionAction action, @Nonnull ExecutionContext executionContext) {
    UserId userId = action.getUserId();
    if (userId.isGuest()) {
        logger.info("Attempt at authenticating guest user");
        return new GetChapSessionResult(Optional.empty());
    }
    Optional<Salt> salt = authenticationManager.getSalt(userId);
    if (!salt.isPresent()) {
        logger.info("Attempt to authenticate non-existing user: {}", userId);
        return new GetChapSessionResult(Optional.empty());
    }
    ChapSession challengeMessage = chapSessionManager.getSession(salt.get());
    return new GetChapSessionResult(Optional.of(challengeMessage));
}
Also used : Salt(edu.stanford.bmir.protege.web.shared.auth.Salt) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ChapSession(edu.stanford.bmir.protege.web.shared.auth.ChapSession) GetChapSessionResult(edu.stanford.bmir.protege.web.shared.auth.GetChapSessionResult) Nonnull(javax.annotation.Nonnull)

Example 9 with UserId

use of edu.stanford.bmir.protege.web.shared.user.UserId in project webprotege by protegeproject.

the class PerspectiveLinkManagerImpl method addLinkedPerspective.

public void addLinkedPerspective(final PerspectiveId perspectiveId, final Callback callback) {
    final UserId userId = loggedInUserProvider.getCurrentUserId();
    dispatchServiceManager.execute(new GetPerspectivesAction(projectId, userId), new DispatchServiceCallback<GetPerspectivesResult>() {

        @Override
        public void handleSuccess(GetPerspectivesResult result) {
            List<PerspectiveId> ids = new ArrayList<>(result.getPerspectives());
            ids.add(perspectiveId);
            final ImmutableList<PerspectiveId> perspectiveIds = ImmutableList.copyOf(ids);
            dispatchServiceManager.execute(new SetPerspectivesAction(projectId, userId, perspectiveIds), new DispatchServiceCallback<SetPerspectivesResult>() {

                @Override
                public void handleSuccess(SetPerspectivesResult setPerspectivesResult) {
                    callback.handlePerspectives(perspectiveIds);
                }
            });
        }
    });
}
Also used : DispatchServiceCallback(edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceCallback) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList)

Example 10 with UserId

use of edu.stanford.bmir.protege.web.shared.user.UserId in project webprotege by protegeproject.

the class PerspectiveLinkManagerImpl method getLinkedPerspectives.

public void getLinkedPerspectives(final Callback callback) {
    final UserId userId = loggedInUserProvider.getCurrentUserId();
    dispatchServiceManager.execute(new GetPerspectivesAction(projectId, userId), new DispatchServiceCallback<GetPerspectivesResult>() {

        @Override
        public void handleSuccess(GetPerspectivesResult result) {
            callback.handlePerspectives(result.getPerspectives());
        }
    });
}
Also used : UserId(edu.stanford.bmir.protege.web.shared.user.UserId)

Aggregations

UserId (edu.stanford.bmir.protege.web.shared.user.UserId)64 Nonnull (javax.annotation.Nonnull)20 Test (org.junit.Test)14 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)13 Inject (javax.inject.Inject)6 OWLEntity (org.semanticweb.owlapi.model.OWLEntity)6 List (java.util.List)5 ImmutableList (com.google.common.collect.ImmutableList)4 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)4 WebProtegeSession (edu.stanford.bmir.protege.web.server.session.WebProtegeSession)4 WebProtegeSessionImpl (edu.stanford.bmir.protege.web.server.session.WebProtegeSessionImpl)4 OWLEntityData (edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)4 EventTag (edu.stanford.bmir.protege.web.shared.event.EventTag)4 ArrayList (java.util.ArrayList)4 DispatchServiceCallback (edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceCallback)3 Subject.forUser (edu.stanford.bmir.protege.web.server.access.Subject.forUser)3 Optional (java.util.Optional)3 Stopwatch (com.google.common.base.Stopwatch)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ProjectResource (edu.stanford.bmir.protege.web.server.access.ProjectResource)2