• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java UnauthorizedUserException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException的典型用法代码示例。如果您正苦于以下问题:Java UnauthorizedUserException类的具体用法?Java UnauthorizedUserException怎么用?Java UnauthorizedUserException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UnauthorizedUserException类属于org.springframework.security.oauth2.common.exceptions包,在下文中一共展示了UnauthorizedUserException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: deleteStory

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "fallbackDeleteStory", ignoreExceptions = IllegalArgumentException.class)
public String deleteStory(String storyId, String userId) {
    Assert.hasLength(storyId, "deleteStory input was null or empty");

    Story story = storyRepository.findById(storyId);
    if(!userId.equals(story.getUserId()))
        throw new UnauthorizedUserException("Unauthorized user for this action");

    storyRepository.delete(storyId);
    return Constants.OK;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:13,代码来源:StoryServiceImpl.java


示例2: changePassword

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@ApiOperation(
  value = "Changing the current User’s password",
  notes = "The current user can change his password by providing a new one"
)
@RequestMapping(
  value = "changepwd",
  method = RequestMethod.PUT,
  consumes = MediaType.APPLICATION_JSON_VALUE
)
@ResponseStatus(HttpStatus.ACCEPTED)
public void changePassword(@RequestBody /*@Valid*/ JsonObject newPwd)
    throws UnauthorizedUserException, PasswordWeakException {
  log.debug("Changing password");
  JsonObject jsonObject = gson.fromJson(newPwd, JsonObject.class);
  userManagement.changePassword(
      jsonObject.get("old_pwd").getAsString(), jsonObject.get("new_pwd").getAsString());
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:18,代码来源:RestUsers.java


示例3: changePasswordOf

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@ApiOperation(
  value = "Changing a User’s password",
  notes = "If you want to change another User’s password, you have to be an admin"
)
@RequestMapping(
  value = "changepwd/{username}",
  method = RequestMethod.PUT,
  consumes = MediaType.APPLICATION_JSON_VALUE
)
@ResponseStatus(HttpStatus.ACCEPTED)
public void changePasswordOf(
    @PathVariable("username") String username, @RequestBody /*@Valid*/ JsonObject newPwd)
    throws UnauthorizedUserException, PasswordWeakException, NotFoundException,
        NotAllowedException {
  log.debug("Changing password of user " + username);
  if (isAdmin()) {
    JsonObject jsonObject = gson.fromJson(newPwd, JsonObject.class);
    userManagement.changePasswordOf(username, jsonObject.get("new_pwd").getAsString());
  } else {
    throw new NotAllowedException(
        "Forbidden to change password of other users. Only admins can do this.");
  }
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:24,代码来源:RestUsers.java


示例4: getVirtualNetworkFunctionDescriptor

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
/**
 * Returns the VirtualNetworkFunctionDescriptor with the ID idVnfd from the Network Service
 * Descriptor with ID idNsd.
 *
 * @param idNsd of NSD
 * @param idVnfd of VirtualNetworkFunctionDescriptor
 */
@Override
public VirtualNetworkFunctionDescriptor getVirtualNetworkFunctionDescriptor(
    String idNsd, String idVnfd, String projectId) throws NotFoundException {
  NetworkServiceDescriptor nsd = nsdRepository.findFirstByIdAndProjectId(idNsd, projectId);
  if (nsd == null)
    throw new NotFoundException("Did not find a Network Service Descriptor with ID " + idNsd);
  for (VirtualNetworkFunctionDescriptor vnfd : nsd.getVnfd()) {
    if (vnfd.getId().equals(idVnfd)) {
      if (!vnfd.getProjectId().equals(projectId))
        throw new UnauthorizedUserException(
            "VNFD not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
      return vnfd;
    }
  }
  throw new NotFoundException(
      "The NSD with ID " + idNsd + " does not contain a VNFD with ID " + idVnfd);
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:25,代码来源:NetworkServiceDescriptorManagement.java


示例5: doFilter

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest servletRequest;
    try {
        servletRequest = (HttpServletRequest) request;
    } catch (ClassCastException e) {
        return;
    }
    String ruquestUri = servletRequest.getRequestURI();
    servletRequest.getSession(true).setAttribute(REQUEST_URI_ATTRIBUTE_NAME, ruquestUri);
    logger.info("Access to protected resources.");
    if (!IvisOAuth2Utils.isTokenGood(servletRequest)) {
        throw new UnauthorizedUserException("Token isn't good.");
    } else if (Objects.nonNull(roles)
            && !IvisOAuth2Utils.getIvisLoggedInUser(servletRequest).hasRoles(roles.split(","))){
        throw new AccessDeniedException("Token is good, but roles aren't.");
    }
    logger.info("Access is permitted");

    chain.doFilter(request, response);
}
 
开发者ID:imCodePartnerAB,项目名称:iVIS,代码行数:22,代码来源:IvisAuthorizedFilter.java


示例6: deleteComment

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "fallbackDeleteComment", ignoreExceptions = IllegalArgumentException.class)
public String deleteComment(String commentId, String userId) {
    Assert.hasLength(commentId, "deleteComment input was null or empty");

    Comment comment = storyRepository.findCommentById(commentId);
    if(!comment.getUserId().equals(userId))
        throw new UnauthorizedUserException("Unauthorized user for this action");

    storyRepository.deleteCommentById(commentId);
    return Constants.OK;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:13,代码来源:StoryServiceImpl.java


示例7: checkUser

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
private boolean checkUser(String username, String groupId) throws UnauthorizedUserException {
    Group group = groupRepository.findOne(groupId);
    if(group==null )
        return false;
    if(!username.equals(group.getModerator()))
        throw new UnauthorizedUserException("Unauthorized user for this action.");
    return true;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:9,代码来源:AdministrativeServiceImpl.java


示例8: updateUser

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@LogTimeExecution
@RequestMapping(value = "/updateUser", method = RequestMethod.POST)
public GenericJson updateUser(Principal principal, @Valid @RequestBody UserRequest user){
    logger.debug("Entering updateUser (username = {})",principal.getName());
    if(!checkUsername(principal, user))
        throw new UnauthorizedUserException("Wrong Username");
    String result =  administrativeService.updateUser(user);
    logger.debug("Exiting updateUser (username ={}, result={})", principal.getName(), result);
    return new GenericJson(result);
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:11,代码来源:AdministrativeController.java


示例9: findMine

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
public List<Message> findMine() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication == null || !authentication.isAuthenticated()) {
        throw new UnauthorizedUserException("未登录的请求");
    }

    User user = (User) authentication.getPrincipal();
    return messageRepository.findByTargetUserIdAndHasReadFalseOrderByCreatedTimeDesc(user.getId());
}
 
开发者ID:microacup,项目名称:microbbs,代码行数:10,代码来源:MessageService.java


示例10: changePassword

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Override
public void changePassword(String oldPassword, String newPassword) {
  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  String currentUserName = authentication.getName();
  log.debug("Changing password of user: " + currentUserName);
  User user = userRepository.findFirstByUsername(currentUserName);
  if (!BCrypt.checkpw(oldPassword, user.getPassword())) {
    throw new UnauthorizedUserException("Old password is wrong.");
  }
  if (!(authentication instanceof AnonymousAuthenticationToken)) { // TODO is this line needed?
    user.setPassword(BCrypt.hashpw(newPassword, BCrypt.gensalt(12)));
    userRepository.save(user);
    log.debug("Password of user " + currentUserName + " has been changed successfully.");
  }
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:16,代码来源:CustomUserDetailsService.java


示例11: handleUnauthorized

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@ExceptionHandler({UnauthorizedUserException.class, NotAllowedException.class})
@ResponseStatus(value = HttpStatus.FORBIDDEN)
protected ResponseEntity<Object> handleUnauthorized(Exception e, WebRequest request) {
  if (log.isDebugEnabled()) {
    log.error("Exception was thrown -> Return message: " + e.getMessage(), e);
  } else {
    log.error("Exception was thrown -> Return message: " + e.getMessage());
  }
  ExceptionResource exc = new ExceptionResource("Unauthorized exception", e.getMessage());
  HttpHeaders headers = new HttpHeaders();
  headers.setContentType(MediaType.APPLICATION_JSON);

  return handleExceptionInternal(e, exc, headers, HttpStatus.FORBIDDEN, request);
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:15,代码来源:GlobalExceptionHandler.java


示例12: deleteVNFRecord

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
public void deleteVNFRecord(String idNsr, String idVnf, String projectId)
    throws NotFoundException {
  //TODO the logic of this request for the moment deletes only the VNFR from the DB, need to be removed from the
  // running NetworkServiceRecord
  VirtualNetworkFunctionRecord vnfr = vnfrRepository.findOne(idVnf);
  if (vnfr == null) {
    throw new NotFoundException("Not found VNFR with ID: " + idVnf);
  }
  if (!vnfr.getParent_ns_id().equals(idNsr)) {
    throw new NotFoundException("Not found VNFR " + idVnf + " in the given NSR " + idNsr);
  }
  if (!vnfr.getProjectId().equals(projectId)) {
    throw new UnauthorizedUserException("VNFR not contained in the chosen project.");
  }
  nsrRepository.deleteVNFRecord(idNsr, idVnf);
  NetworkServiceRecord nsr = query(idNsr, projectId);
  if (nsr != null) {
    for (VirtualNetworkFunctionRecord virtualNetworkFunctionRecord : nsr.getVnfr()) {
      if (nsr.getStatus().ordinal() > virtualNetworkFunctionRecord.getStatus().ordinal()) {
        nsr.setStatus(vnfr.getStatus());
      }
    }
    nsrRepository.saveCascade(nsr);
  } else {
    log.warn("Parent NS does not exist anymore...");
  }
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:28,代码来源:NetworkServiceRecordManagement.java


示例13: deleteVNFCInstance

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Override
public void deleteVNFCInstance(String id, String idVnf, String idVdu, String projectId)
    throws NotFoundException, WrongStatusException, InterruptedException, ExecutionException,
        VimException, PluginException, BadFormatException {
  log.info("Removing VNFCInstance from VNFR with id: " + idVnf + " in vdu: " + idVdu);
  NetworkServiceRecord networkServiceRecord = getNetworkServiceRecordInActiveState(id, projectId);
  VirtualNetworkFunctionRecord virtualNetworkFunctionRecord =
      getVirtualNetworkFunctionRecord(idVnf, networkServiceRecord);
  if (!virtualNetworkFunctionRecord.getProjectId().equals(projectId)) {
    throw new UnauthorizedUserException(
        "VNFR not under the project chosen, are you trying to hack us? Just kidding, it's a bug :)");
  }

  VirtualDeploymentUnit virtualDeploymentUnit = null;

  for (VirtualDeploymentUnit vdu : virtualNetworkFunctionRecord.getVdu()) {
    if (vdu.getId().equals(idVdu)
        && vdu.getProjectId() != null
        && vdu.getProjectId().equals(projectId)) {
      virtualDeploymentUnit = vdu;
    }
  }

  if (virtualDeploymentUnit == null) {
    throw new NotFoundException("No VirtualDeploymentUnit found");
  }

  if (virtualDeploymentUnit.getVnfc_instance().size() == 1) {
    throw new WrongStatusException(
        "The VirtualDeploymentUnit chosen has reached the minimum number of VNFCInstance");
  }

  VNFCInstance vnfcInstance = getVNFCInstance(virtualDeploymentUnit, null);

  networkServiceRecord.setStatus(Status.SCALING);
  networkServiceRecord = nsrRepository.saveCascade(networkServiceRecord);
  scaleIn(
      networkServiceRecord, virtualNetworkFunctionRecord, virtualDeploymentUnit, vnfcInstance);
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:40,代码来源:NetworkServiceRecordManagement.java


示例14: changePassword

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Override
public void changePassword(String oldPwd, String newPwd)
    throws UnauthorizedUserException, PasswordWeakException {
  log.debug("Got old password: " + oldPwd);
  if (checkStrength) {
    Utils.checkPasswordIntegrity(newPwd);
  }
  customUserDetailsService.changePassword(oldPwd, newPwd);
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:10,代码来源:UserManagement.java


示例15: resolveArgument

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Override
public Client resolveArgument(final MethodParameter parameter,
                              final ModelAndViewContainer mavContainer,
                              final NativeWebRequest request,
                              final WebDataBinderFactory binderFactory) throws Exception {
    final Optional<String> clientId = Optional.ofNullable(request.getUserPrincipal()).map(Principal::getName);
    if (clientId.filter(settings.getAdminClientId()::equals).isPresent()
            || settings.getAuthMode() == OFF) {
        return new FullAccessClient(clientId.orElse(FULL_ACCESS_CLIENT_ID));
    }

    return clientId.map(client -> new NakadiClient(client, getScopes()))
            .orElseThrow(() -> new UnauthorizedUserException("Client unauthorized"));
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:15,代码来源:ClientResolver.java


示例16: writeUnauthorizedClient

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Test
public void writeUnauthorizedClient() throws Exception {
	OAuth2Exception oauthException = new UnauthorizedUserException(DETAILS);
	String expected = createResponse(oauthException.getOAuth2ErrorCode());
	converter.write(oauthException, contentType, outputMessage);
	assertEquals(expected, getOutput());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:8,代码来源:JaxbOAuth2ExceptionMessageConverterTests.java


示例17: readUnauthorizedClient

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Test
public void readUnauthorizedClient() throws Exception {
	String accessToken = createResponse(OAuth2Exception.UNAUTHORIZED_CLIENT);
	when(inputMessage.getBody()).thenReturn(createInputStream(accessToken));
	@SuppressWarnings("unused")
	UnauthorizedUserException result = (UnauthorizedUserException) converter.read(OAuth2Exception.class,
			inputMessage);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:9,代码来源:JaxbOAuth2ExceptionMessageConverterTests.java


示例18: readValueUnauthorizedClient

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Test
public void readValueUnauthorizedClient() throws Exception {
	String accessToken = createResponse(OAuth2Exception.UNAUTHORIZED_CLIENT);
	UnauthorizedUserException result = (UnauthorizedUserException) mapper.readValue(accessToken,
			OAuth2Exception.class);
	assertEquals(DETAILS,result.getMessage());
	assertEquals(null,result.getAdditionalInformation());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:9,代码来源:OAuth2ExceptionDeserializerTests.java


示例19: shouldFailToDeleteGroupUnauthrizedUser

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Test(expected = UnauthorizedUserException.class)
public void shouldFailToDeleteGroupUnauthrizedUser() throws Exception{
    administrativeService.deleteGroup("testGroupName", "testUsername2");
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:5,代码来源:AdministrativeServiceTest.java


示例20: shouldFailToUpdateGroupUnauthrizedUser

import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; //导入依赖的package包/类
@Test(expected = UnauthorizedUserException.class)
public void shouldFailToUpdateGroupUnauthrizedUser() throws Exception{
    administrativeService.updateGroup("testGroupName",groupRequest,"testUsername2");
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:5,代码来源:AdministrativeServiceTest.java



注:本文中的org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java M2Model类代码示例发布时间:2022-05-22
下一篇:
Java FsVolumeImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap