use of won.owner.model.User in project webofneeds by researchstudio-sat.
the class BridgeForLinkedDataController method currentUserHasIdentity.
/**
* Check if the current user has the claimed identity represented by web-id of
* the need. I.e. if the identity is that of the need that belongs to the user -
* return true, otherwise - false.
*
* @param requesterWebId
* @return
*/
private boolean currentUserHasIdentity(final String requesterWebId) {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
User user = (User) wonUserDetailService.loadUserByUsername(username);
Set<URI> needUris = getUserNeedUris(user);
if (needUris.contains(URI.create(requesterWebId))) {
return true;
}
return false;
}
use of won.owner.model.User in project webofneeds by researchstudio-sat.
the class RestNeedController method getAllDrafts.
@ResponseBody
@RequestMapping(value = "/drafts", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
public // TODO: move transactionality annotation into the service layer
List<CreateDraftPojo> getAllDrafts() {
User user = getCurrentUser();
List<CreateDraftPojo> createDraftPojos = new ArrayList<>();
Set<URI> draftURIs = user.getDraftURIs();
Iterator<URI> draftURIIterator = draftURIs.iterator();
while (draftURIIterator.hasNext()) {
URI draftURI = draftURIIterator.next();
Draft draft = draftRepository.findByDraftURI(draftURI).get(0);
CreateDraftPojo createDraftPojo = new CreateDraftPojo(draftURI.toString(), draft.getContent());
createDraftPojos.add(createDraftPojo);
}
return createDraftPojos;
}
use of won.owner.model.User in project webofneeds by researchstudio-sat.
the class RestNeedController method createDraft.
/**
* saves draft of a draft
* @param createDraftObject an object containing information of the need draft
* @return a JSON object of the draft with its temprory id.
*/
@ResponseBody
@RequestMapping(value = "/drafts", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
// TODO: move transactionality annotation into the service layer
@Transactional(propagation = Propagation.SUPPORTS)
public CreateDraftPojo createDraft(@RequestBody CreateDraftPojo createDraftObject) throws ParseException {
User user = getCurrentUser();
URI draftURI = URI.create(createDraftObject.getDraftURI());
user.getDraftURIs().add(draftURI);
wonUserDetailService.save(user);
Draft draft = null;
draft = draftRepository.findOneByDraftURI(draftURI);
if (draft == null) {
draft = new Draft(draftURI, createDraftObject.getDraft());
}
draft.setContent(createDraftObject.getDraft());
draftRepository.save(draft);
return createDraftObject;
}
use of won.owner.model.User in project webofneeds by researchstudio-sat.
the class RestUserController method registerUser.
/**
* Registers the specified user with password and an opional role.
* Assumes values have already been checked for syntactic validity.
* @param email
* @param password
* @param role
* @throws UserAlreadyExistsException
*/
private void registerUser(String email, String password, String role) throws UserAlreadyExistsException {
User user = userRepository.findByUsername(email);
if (user != null) {
throw new UserAlreadyExistsException();
}
try {
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
user = new User(email, passwordEncoder.encode(password), role);
user.setEmail(email);
KeystorePasswordHolder keystorePassword = new KeystorePasswordHolder();
// generate a password for the keystore and save it in the database, encrypted with a symmetric key
// derived from the user's password
keystorePassword.setPassword(KeystorePasswordUtils.generatePassword(KeystorePasswordUtils.KEYSTORE_PASSWORD_BYTES), password);
// keystorePassword = keystorePasswordRepository.save(keystorePassword);
// generate the keystore for the user
KeystoreHolder keystoreHolder = new KeystoreHolder();
try {
// create the keystore if it doesnt exist yet
keystoreHolder.getKeystore(keystorePassword.getPassword(password));
} catch (Exception e) {
throw new IllegalStateException("could not create keystore for user " + email);
}
// keystoreHolder = keystoreHolderRepository.save(keystoreHolder);
user.setKeystorePasswordHolder(keystorePassword);
user.setKeystoreHolder(keystoreHolder);
userRepository.save(user);
} catch (DataIntegrityViolationException e) {
// username is already in database
throw new UserAlreadyExistsException();
}
}
use of won.owner.model.User in project webofneeds by researchstudio-sat.
the class WonWebSocketHandler method afterConnectionEstablished.
@Override
public void afterConnectionEstablished(final WebSocketSession session) throws Exception {
super.afterConnectionEstablished(session);
// remember which user or (if not logged in) which atomUri the session is bound
// to
User user = getUserForSession(session);
if (user != null) {
logger.debug("connection established, binding session to user {}", user.getId());
this.webSocketSessionService.addMapping(user, session);
} else {
logger.debug("connection established, but no user found in session to bind to");
}
}
Aggregations