List of usage examples for org.springframework.security.authentication BadCredentialsException BadCredentialsException
public BadCredentialsException(String msg)
BadCredentialsException
with the specified message. From source file:com.ebay.pulsar.analytics.resources.PermissionControlResource.java
@DELETE @Path("datasources") @Consumes(MediaType.APPLICATION_JSON)//from ww w . j a v a2 s. c o m @Produces(MediaType.APPLICATION_JSON) public Response batchDeleteDatasource(@Context HttpServletRequest request, @QueryParam("batch") String datasourceNames) { logger.info("Delete DataSources API called from IP: " + request.getRemoteAddr()); try { if (isAnonymous()) { throw new BadCredentialsException("Bad credentials"); } if (datasourceNames == null) { throw new IllegalArgumentException("No DataSources to Delete!"); } int id = datasourceService.deleteDataSources(Lists.newArrayList(datasourceNames.split(","))); if (id >= 0) { return Response.ok(ImmutableMap.of("deleted", id)).build(); } else { return Response.status(Status.BAD_REQUEST).build(); } } catch (Exception ex) { logger.warn("Response Error: " + ex.getMessage()); return handleException(ex); } }
From source file:com.ebay.pulsar.analytics.resources.PermissionControlResource.java
@PUT @Path("datasources") @Consumes(MediaType.APPLICATION_JSON)/* w w w . j a va 2 s . c o m*/ @Produces(MediaType.APPLICATION_JSON) public Response updateDatasource(@Context HttpServletRequest request, DBDataSource datasource) { logger.info("Update DataSource API called from IP: " + request.getRemoteAddr()); try { if (isAnonymous()) { throw new BadCredentialsException("Bad credentials"); } if (!this.validateDataSourceType(datasource.getType())) throw new IllegalArgumentException("Invalid DataSource Type [" + datasource.getType() + "]"); if (!this.validateDataSourceEndPoint(datasource.getEndpoint())) { throw new IllegalArgumentException( "Invalid DataSource Endpoint [" + datasource.getEndpoint() + "]"); } if (datasource.getName() == null) { throw new IllegalArgumentException("DataSource Name is Empty!"); } if (!isValidDisplayName(datasource.getDisplayName())) { throw new IllegalArgumentException("DataSource DisplayName is Invalid!"); } datasource.setName(datasource.getName().toLowerCase()); long id = datasourceService.updateDataSource(datasource); if (id > 0) { return Response.ok(ImmutableMap.of("updated", id)).build(); } else { return Response.status(Status.BAD_REQUEST).build(); } } catch (Exception ex) { logger.warn("Response Error: " + ex.getMessage()); return handleException(ex); } }
From source file:com.ebay.pulsar.analytics.resources.PermissionControlResource.java
@GET @Path("datasources") @Produces(MediaType.APPLICATION_JSON)// w ww. ja va 2 s.com public Response getAllDataSourceByUser(@Context HttpServletRequest request, @QueryParam("right") String right) { logger.info("List DataSources API called from IP: " + request.getRemoteAddr()); try { if (isAnonymous()) { throw new BadCredentialsException("Bad credentials"); } Set<DBDataSource> datasources = null; if ("view".equalsIgnoreCase(right)) { datasources = datasourceService.getAllUserViewedDatasource(); return Response.ok("get all datasources succeed!").entity(datasources).build(); } if (right == null || "manage".equalsIgnoreCase(right)) { datasources = datasourceService.getAllUserManagedDatasource(); return Response.ok("get all datasources succeed!").entity(datasources).build(); } throw new IllegalArgumentException("Invalid Query Parameter!"); } catch (Exception ex) { logger.warn("Response Error: " + ex.getMessage()); return handleException(ex); } }
From source file:com.ebay.pulsar.analytics.resources.PermissionControlResource.java
@GET @Path("datasources/{datasourceName}/groups") @Produces(MediaType.APPLICATION_JSON)/* www . jav a2 s. c o m*/ public Response getAllGroupsByDataSource(@Context HttpServletRequest request, @PathParam("datasourceName") String datasourceName, @QueryParam("right") String right) { logger.info("List DataSources API called from IP: " + request.getRemoteAddr()); try { if (isAnonymous()) { throw new BadCredentialsException("Bad credentials"); } List<DBGroup> groups = groupService.getAllUserManagedGroups(); if ("view".equalsIgnoreCase(right)) { return Response.ok("get all datasources succeed!") .entity(groupService.getAllGroupsForDataSource(datasourceName, groups, String.format(PermissionConst.VIEW_RIGHT_TEMPLATE, datasourceName))) .build(); } if (right == null || "manage".equalsIgnoreCase(right)) { return Response.ok("get all datasources succeed!") .entity(groupService.getAllGroupsForDataSource(datasourceName, groups, String.format(PermissionConst.MANAGE_RIGHT_TEMPLATE, datasourceName))) .build(); } throw new IllegalArgumentException("Invalid Query Parameter!"); } catch (Exception ex) { logger.warn("Response Error: " + ex.getMessage()); return handleException(ex); } }
From source file:com.ebay.pulsar.analytics.resources.PulsarQueryResource.java
private Response processSqlRequest(BaseSQLRequest req, String dataSourceName, boolean trace) { Response response = null;//from w w w . j av a 2s. c o m try { if (req.getSql() != null && !req.getSql().trim().toLowerCase().startsWith("select")) { Set<String> dataSourceList = getSourceInfo(req.getSql().trim().toLowerCase()); GenericEntity<Set<String>> entity = new GenericEntity<Set<String>>(dataSourceList) { }; return Response.ok(entity).build(); } long start = System.nanoTime(); if (Strings.isNullOrEmpty(dataSourceName)) { String tableName = SimpleTableNameParser.getTableName(req.getSql()); if (tableName != null) { int idx = tableName.indexOf('.'); if (idx > 0) { dataSourceName = tableName.substring(0, idx); } } } if (Strings.isNullOrEmpty(dataSourceName)) { dataSourceName = DataSourceConfigurationLoader.PULSAR_DATASOURCE; } else { dataSourceName = dataSourceName.toLowerCase(); } if (!dataSourceName.equals(DataSourceConfigurationLoader.PULSAR_DATASOURCE) && isAnonymous()) { throw new BadCredentialsException("Bad credentials"); } DataSourceConfiguration configuration = DataSourceMetaRepo.getInstance().getActiveDbConfMap() .get(dataSourceName); DataSourceTypeEnum dataSourceType = null; if (configuration != null) { dataSourceType = configuration.getDataSourceType(); } else { throw new InvalidQueryParameterException( ExceptionErrorCode.INVALID_DATASOURCE.getErrorMessage() + dataSourceName); } SQLQueryProcessor sqlRequestProcessor = DataSourceTypeRegistry.getDataSourceFactory(dataSourceType) .queryProcessor(); TraceAbleResponse resp = sqlRequestProcessor.executeQuery(req, dataSourceName); if (trace) { resp.setRequestProcessTime(System.nanoTime() - start); response = Response.ok(resp).build(); } else { response = Response.ok(resp.getQueryResult()).build(); } } catch (Exception ex) { ObjectMapper mapper = new ObjectMapper(); try { if (req != null && mapper != null) { String str = mapper.writeValueAsString(req); if (str != null) { logger.debug(str); } } } catch (JsonGenerationException e) { logger.warn("JsonGenerationException: " + e); } catch (JsonMappingException e) { logger.warn("JsonMappingException: " + e); } catch (IOException e) { logger.warn("IOException: " + e); } logger.warn("SQL Query Error: " + ex.getMessage()); return handleException(ex); } return response; }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java
/** * Decodes the header into a username and password. * * @throws BadCredentialsException if the Basic header is not present or is not valid Base64 *//* www .j a v a 2 s . com*/ private String[] extractAndDecodeHeader(String header) throws IOException { byte[] base64Token = header.substring(6).getBytes("UTF-8"); byte[] decoded; try { decoded = org.springframework.security.crypto.codec.Base64.decode(base64Token); } catch (IllegalArgumentException e) { throw new BadCredentialsException("Failed to decode basic authentication token"); } String token = new String(decoded, "UTF-8"); int delim = token.indexOf(":"); if (delim == -1) { throw new BadCredentialsException("Invalid basic authentication token"); } return new String[] { token.substring(0, delim), token.substring(delim + 1) }; }
From source file:com.ebay.pulsar.analytics.resources.PermissionControlResource.java
@POST @Path("dashboards") @Consumes(MediaType.APPLICATION_JSON)/* www . j a v a 2 s . c om*/ @Produces(MediaType.APPLICATION_JSON) public Response addDashboard(@Context HttpServletRequest request, Dashboard d) { logger.info("Add Dashboard API called from IP: " + request.getRemoteAddr()); try { DBDashboard dashboard = d.toDBDashboard(); if (isAnonymous()) { throw new BadCredentialsException("Bad credentials"); } if (!this.validateDashboardConfig(dashboard.getConfig())) { throw new IllegalArgumentException("Invalid Dashboard config"); } if (!isValidDisplayName(dashboard.getDisplayName())) { throw new IllegalArgumentException("Dashboard DisplayName is Invalid!"); } dashboard.setName(slg.slugify(dashboard.getDisplayName())); dashboard.setOwner(getUserName()); long id = dashboardService.addDashboard(dashboard); if (id > 0) { return Response.ok(this.converDBDashboard2Map(dashboard)).build(); } else { return Response.status(Status.BAD_REQUEST).build(); } } catch (Exception ex) { logger.warn("Response Error: " + ex.getMessage()); return handleException(ex); } }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java
@RequestMapping(value = "/autologin", method = RequestMethod.POST) @ResponseBody//from ww w .ja v a2 s . c o m public AutologinResponse generateAutologinCode(@RequestBody AutologinRequest request, @RequestHeader(value = "Authorization", required = false) String auth) throws Exception { if (auth == null || (!auth.startsWith("Basic"))) { throw new BadCredentialsException("No basic authorization client information in request"); } String username = request.getUsername(); if (username == null) { throw new BadCredentialsException("No username in request"); } Authentication remoteAuthentication = null; if (remoteAuthenticationManager != null) { String password = request.getPassword(); if (!StringUtils.hasText(password)) { throw new BadCredentialsException("No password in request"); } remoteAuthentication = remoteAuthenticationManager .authenticate(new AuthzAuthenticationRequest(username, password, null)); } String base64Credentials = auth.substring("Basic".length()).trim(); String credentials = new String(new Base64().decode(base64Credentials.getBytes()), Charset.forName("UTF-8")); // credentials = username:password final String[] values = credentials.split(":", 2); if (values == null || values.length == 0) { throw new BadCredentialsException("Invalid authorization header."); } String clientId = values[0]; logger.debug("Autologin authentication request for user:" + username + "; client:" + clientId); SocialClientUserDetails user = new SocialClientUserDetails(username, UaaAuthority.USER_AUTHORITIES); Map<String, String> details = new HashMap<>(); details.put("client_id", clientId); user.setDetails(details); if (remoteAuthentication != null && remoteAuthentication.getPrincipal() instanceof UaaPrincipal) { UaaPrincipal p = (UaaPrincipal) remoteAuthentication.getPrincipal(); if (p != null) { details.put("origin", p.getOrigin()); details.put("user_id", p.getId()); } } ResponseEntity<ExpiringCode> response = doGenerateCode(user); return new AutologinResponse(response.getBody().getCode()); }
From source file:com.ebay.pulsar.analytics.resources.PermissionControlResource.java
@DELETE @Path("dashboards/{dashboardName}") @Consumes(MediaType.APPLICATION_JSON)// ww w .ja v a 2s . co m @Produces(MediaType.APPLICATION_JSON) public Response deleteDashboard(@Context HttpServletRequest request, @PathParam("dashboardName") String dashboardName) { logger.info("Delete Dashboard API called from IP: " + request.getRemoteAddr()); try { if (isAnonymous()) { throw new BadCredentialsException("Bad credentials"); } if (dashboardName == null) { throw new IllegalArgumentException("No Dashboard to Delete!"); } int id = dashboardService.deleteDashboard(dashboardName); if (id >= 0) { return Response.ok(ImmutableMap.of("deleted", id)).build(); } else { return Response.status(Status.BAD_REQUEST).build(); } } catch (Exception ex) { logger.warn("Response Error: " + ex.getMessage()); return handleException(ex); } }