Search in sources :

Example 21 with User

use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.

the class BoschIoTSuiteOAuthProviderAuthCodeTest method authenticateSuccessTest.

@Test
public void authenticateSuccessTest() {
    when(userAccountService.getUser(any())).thenReturn(new User());
    Authentication authentication = sut.authenticate(null, TOKEN);
    assertTrue(authentication.isAuthenticated());
}
Also used : User(org.eclipse.vorto.repository.domain.User) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) Test(org.junit.Test)

Example 22 with User

use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.

the class AccountControllerTest method updateAccount.

@Test
public void updateAccount() throws Exception {
    this.repositoryServer.perform(put("/rest/accounts/" + USER_MODEL_CREATOR_NAME).content(testMail).with(userSysadmin)).andExpect(status().isOk());
    User user = userRepository.findByUsername(USER_MODEL_CREATOR_NAME);
    assertNotNull(user);
    assertEquals(testMail, user.getEmailAddress());
    this.repositoryServer.perform(put("/rest/accounts/doesnotexist").content(testMail).with(userSysadmin)).andExpect(status().isNotFound());
}
Also used : User(org.eclipse.vorto.repository.domain.User) Test(org.junit.Test)

Example 23 with User

use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.

the class BoschIDOAuthProvider method createAuthentication.

/**
 * Authenticates the user from the CIAM issued token by checking if the user is registered in the
 * Repository
 */
@Override
public OAuth2Authentication createAuthentication(HttpServletRequest httpRequest, JwtToken accessToken) {
    Map<String, Object> tokenPayload = accessToken.getPayloadMap();
    Optional<String> email = Optional.ofNullable((String) tokenPayload.get(JWT_EMAIL));
    Optional<String> name = Optional.ofNullable((String) tokenPayload.get(JWT_NAME)).map(str -> str.split("@")[0]);
    String userId = getUserId(tokenPayload).orElseThrow(() -> new InvalidTokenException("Cannot generate a userId from your provided token. Maybe 'sub' or 'client_id' is not present in JWT token?"));
    User user = userAccountService.getUser(userId);
    if (user == null) {
        throw new InvalidTokenException("User from token is not a registered user in the repository!");
    }
    return createAuthentication(this.ciamClientId, userId, name.orElse(userId), email.orElse(null), userNamespaceRoleService.getRolesOnAllNamespaces(user));
}
Also used : InvalidTokenException(org.springframework.security.oauth2.common.exceptions.InvalidTokenException) User(org.eclipse.vorto.repository.domain.User)

Example 24 with User

use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.

the class DefaultCommentService method notifyAllCommentAuthors.

private void notifyAllCommentAuthors(Comment comment, ModelInfo model) {
    Set<String> recipients = new HashSet<>();
    recipients.add(model.getAuthor());
    List<Comment> existingComments = this.commentRepository.findByModelId(comment.getModelId());
    for (Comment c : existingComments) {
        recipients.add(c.getAuthor());
    }
    recipients.stream().filter(recipient -> !User.USER_ANONYMOUS.equalsIgnoreCase(recipient)).forEach(recipient -> {
        User user = accountService.getUser(recipient);
        if (user != null) {
            notificationService.sendNotification(new CommentReplyMessage(user, model, comment.getContent()));
        }
    });
}
Also used : DoesNotExistException(org.eclipse.vorto.repository.services.exceptions.DoesNotExistException) Date(java.util.Date) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) ICommentService(org.eclipse.vorto.repository.comment.ICommentService) User(org.eclipse.vorto.repository.domain.User) ModelId(org.eclipse.vorto.model.ModelId) IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) NamespaceService(org.eclipse.vorto.repository.services.NamespaceService) HashSet(java.util.HashSet) CommentReplyMessage(org.eclipse.vorto.repository.notification.message.CommentReplyMessage) List(java.util.List) PathNotFoundException(javax.jcr.PathNotFoundException) ModelRepositoryFactory(org.eclipse.vorto.repository.core.impl.ModelRepositoryFactory) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) INotificationService(org.eclipse.vorto.repository.notification.INotificationService) DefaultUserAccountService(org.eclipse.vorto.repository.account.impl.DefaultUserAccountService) Comment(org.eclipse.vorto.repository.domain.Comment) IModelRepositoryFactory(org.eclipse.vorto.repository.core.IModelRepositoryFactory) Comment(org.eclipse.vorto.repository.domain.Comment) User(org.eclipse.vorto.repository.domain.User) CommentReplyMessage(org.eclipse.vorto.repository.notification.message.CommentReplyMessage) HashSet(java.util.HashSet)

Example 25 with User

use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.

the class UserAccountListener method refreshUserContext.

public void refreshUserContext(String userId) {
    if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (userId != null && !auth.getName().equals(userId)) {
            return;
        }
        User user = userAccountService.getUser(auth.getName());
        SpringUserUtils.refreshSpringSecurityUser(user, userNamespaceRoleService);
    }
}
Also used : User(org.eclipse.vorto.repository.domain.User) Authentication(org.springframework.security.core.Authentication)

Aggregations

User (org.eclipse.vorto.repository.domain.User)36 ResponseEntity (org.springframework.http.ResponseEntity)13 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 IUserContext (org.eclipse.vorto.repository.core.IUserContext)8 DoesNotExistException (org.eclipse.vorto.repository.services.exceptions.DoesNotExistException)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 OperationForbiddenException (org.eclipse.vorto.repository.services.exceptions.OperationForbiddenException)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 Optional (java.util.Optional)6 InvalidUserException (org.eclipse.vorto.repository.services.exceptions.InvalidUserException)6 ApiParam (io.swagger.annotations.ApiParam)5 Collection (java.util.Collection)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 DefaultUserAccountService (org.eclipse.vorto.repository.account.impl.DefaultUserAccountService)5 Namespace (org.eclipse.vorto.repository.domain.Namespace)5 NamespaceService (org.eclipse.vorto.repository.services.NamespaceService)5 UserNamespaceRoleService (org.eclipse.vorto.repository.services.UserNamespaceRoleService)5 Test (org.junit.Test)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5