@RequestMapping(value = "/{discussionId}", method = RequestMethod.PUT) @Interceptors({ ProjectMemberRequired.class, ProjectNotArchivedRequired.class }) @ResponseBody public Object updateDiscussion(@PathVariable("companyId") int companyId, @PathVariable("projectId") int projectId, @PathVariable("discussionId") int discussionId, @Valid @RequestBody DiscussionForm form, @RequestParam(value = "recover", defaultValue = "false", required = true) Boolean recover) throws NoPermissionException { if (recover) { return recoverDiscussion(discussionId); } logger.info("Updating discussion " + discussionId); logger.info("attachments " + form.getAttachments().size()); form.setProjectId(projectId); form.setCompanyId(companyId); discussionService.updateSelective(form); Topic topic = topicService.getTopicByTypeAndId(form.getType(), form.getId()); TopicDTO result = TopicTransform.topicToTopicDTO(topic); logger.info("add comment count..."); addCommentCount(result); logger.info("Finishing..."); return result; }
private Map<String, ?> recoverDiscussion(@PathVariable("discussionId") int discussionId) throws NoPermissionException { logger.info("recovering " + discussionId); Discussion discussion = discussionService.getById(discussionId); if (discussion.getId().equals(session.getCurrentUser().getId())) { throw new NoPermissionException(); } discussion.setDeleted(false); discussionService.updateSelective(discussion); // discussionService.discardDiscussion(discussionId); discussion = discussionService.getByIdWithDetail(discussionId); DiscussionDTO discussionDto = DiscussionTransform.discussionToDiscussionDTOWithDetail(discussion); Topic topic = topicService.getTopicByTypeAndId(discussion.getType(), discussion.getId()); TopicDTO topicDTO = TopicTransform.topicToTopicDTO(topic); addCommentCount(topicDTO); return ImmutableMap.of("discussion", discussionDto, "topic", topicDTO); }
/** * Checks if this context has been destroyed. isDestroyed is set to true when a context is * destroyed by calling destroySubcontext method. * * @throws NoPermissionException if this context has been destroyed */ private void checkIsDestroyed() throws NamingException { if (isDestroyed) { throw new NoPermissionException( LocalizedStrings.ContextImpl_CAN_NOT_INVOKE_OPERATIONS_ON_DESTROYED_CONTEXT .toLocalizedString()); } }
/** * {@inheritDoc} */ public Object addToEnvironment(String propName, Object propVal) throws NoPermissionException { if (propName.equals(SECURITY_MANAGER)) { installSecurityManager(); } return environment.put(propName, propVal); }
/** * Installs {@link RMISecurityManager} if it is not already installed. * * @throws NoPermissionException * If security manager other than {@link RMISecurityManager} is * installed and prohibits installing a new security manager. */ protected void installSecurityManager() throws NoPermissionException { if (!(System.getSecurityManager() instanceof RMISecurityManager)) { try { System.setSecurityManager(new RMISecurityManager()); } catch (SecurityException e) { // jndi.84=Cannot install RMISecurityManager throw (NoPermissionException) new NoPermissionException( Messages.getString("jndi.84")).initCause(e); //$NON-NLS-1$ } } }
/** * Installs {@link RMISecurityManager} if it is not already installed. * * @throws NoPermissionException * If security manager other than {@link RMISecurityManager} * is installed and prohibits installing a new security manager. */ protected void installSecurityManager() throws NoPermissionException { if (! (System.getSecurityManager() instanceof RMISecurityManager)) { try { System.setSecurityManager(new RMISecurityManager()); } catch (SecurityException e) { // jndi.84=Cannot install RMISecurityManager throw (NoPermissionException) new NoPermissionException( Messages.getString("jndi.84")).initCause(e); //$NON-NLS-1$ } } }
/** * Prepares a new {@link NamingException} wrapping the specified * {@link RemoteException} source exception. Source exception becomes a * {@linkplain NamingException#getCause() cause} of the generated exception. * * The particular subclass of {@link NamingException} returned depends on * the particular subclass of source {@link RemoteException}. * * If source exception is not of a specific class or is not a * {@link RemoteException} or is <code>null</code>, then plain * {@link NamingException} is returned. * * Note: {@link Throwable#fillInStackTrace()} should be called before * throwing the generated exception, to provide the proper (not including * this method) stack trace for the exception. * * Example of use: * * <code>try { * ... * } catch (RemoteException e) { * throw (NamingException) newNamingException(e).fillInStackTrace(); * }</code> * * @param e * Source {@link RemoteException}. * * @return Generated {@link NamingException} exception. */ @SuppressWarnings("deprecation") protected NamingException newNamingException(Throwable e) { NamingException ret = (e instanceof AccessException) ? new NoPermissionException() : (e instanceof ConnectException) ? new ServiceUnavailableException() : (e instanceof ConnectIOException) || (e instanceof ExportException) || (e instanceof MarshalException) || (e instanceof UnmarshalException) ? new CommunicationException() : (e instanceof ActivateFailedException) || (e instanceof NoSuchObjectException) || (e instanceof java.rmi.server.SkeletonMismatchException) || (e instanceof java.rmi.server.SkeletonNotFoundException) || (e instanceof StubNotFoundException) || (e instanceof UnknownHostException) ? new ConfigurationException() : (e instanceof ServerException) ? newNamingException(e .getCause()) : new NamingException(); if (ret.getCause() == null) { ret.initCause(e); } return ret; }
@PostMapping(value = "/register", headers = "Content-Type=application/x-www-form-urlencoded") @ResponseBody public Map<String, String> registerUser(@Valid @ModelAttribute RegisterRequest registerRequest, @Valid @ModelAttribute CaptchaRequest captchaRequest, HttpServletRequest request) throws Exception { if (authenticationSettings.getSignUp()) { if (!registerRequest.getPassword().equals(registerRequest.getConfirmPassword())) { throw new BindException(RegisterRequest.class, "password does not match confirm password"); } if (!captchaService.validateCaptcha(captchaRequest.getCaptcha())) { throw new CaptchaException("invalid captcha answer"); } User user = toUser(registerRequest); String activationUri = null; if (StringUtils.isEmpty(request.getHeader("X-Forwarded-Host"))) { activationUri = ServletUriComponentsBuilder.fromCurrentRequest() .replacePath(URI + "/activate") .build() .toUriString(); } else { String scheme = request.getHeader("X-Forwarded-Proto"); if (scheme == null) scheme = request.getScheme(); activationUri = scheme + "://" + request.getHeader("X-Forwarded-Host") + URI + "/activate"; } accountService.createUser(user, activationUri); String successMessage = authenticationSettings.getSignUpModeration() ? REGISTRATION_SUCCESS_MESSAGE_ADMIN : REGISTRATION_SUCCESS_MESSAGE_USER; captchaService.removeCaptcha(); return Collections.singletonMap("message", successMessage); } else { throw new NoPermissionException("Self registration is disabled"); } }
/** * Prepares a new {@link NamingException} wrapping the specified * {@link RemoteException} source exception. Source exception becomes a * {@linkplain NamingException#getCause() cause} of the generated exception. * * The particular subclass of {@link NamingException} returned depends * on the particular subclass of source {@link RemoteException}. * * If source exception is not of a specific class or is not * a {@link RemoteException} or is <code>null</code>, * then plain {@link NamingException} is returned. * * Note: {@link Throwable#fillInStackTrace()} should be called before * throwing the generated exception, to provide the proper * (not including this method) stack trace for the exception. * * Example of use: * * <code>try { * ... * } catch (RemoteException e) { * throw (NamingException) newNamingException(e).fillInStackTrace(); * }</code> * * @param e * Source {@link RemoteException}. * * @return Generated {@link NamingException} exception. */ @SuppressWarnings("deprecation") //$NON-NLS-1$ protected NamingException newNamingException(Throwable e) { NamingException ret = (e instanceof AccessException) ? new NoPermissionException() : (e instanceof ConnectException) ? new ServiceUnavailableException() : (e instanceof ConnectIOException) || (e instanceof ExportException) || (e instanceof MarshalException) || (e instanceof UnmarshalException) ? new CommunicationException() : (e instanceof ActivateFailedException) || (e instanceof NoSuchObjectException) || (e instanceof java.rmi.server.SkeletonMismatchException) || (e instanceof java.rmi.server.SkeletonNotFoundException) || (e instanceof StubNotFoundException) || (e instanceof UnknownHostException) ? new ConfigurationException() : (e instanceof ServerException) ? newNamingException(e.getCause()) : new NamingException(); if (ret.getCause() == null) { ret.initCause(e); } return ret; }
/** * Checks if this context has been destroyed. isDestroyed is set to true when * a context is destroyed by calling destroySubcontext method. * * @throws NoPermissionException if this context has been destroyed */ private void checkIsDestroyed() throws NamingException { if (isDestroyed) { throw new NoPermissionException(LocalizedStrings.ContextImpl_CAN_NOT_INVOKE_OPERATIONS_ON_DESTROYED_CONTEXT.toLocalizedString()); } }