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
@POST @Path("datasources") @Consumes(MediaType.APPLICATION_JSON)/*from w w w .j ava 2s .c om*/ @Produces(MediaType.APPLICATION_JSON) public Response addDatasource(@Context HttpServletRequest request, DBDataSource datasource) { logger.info("Add 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 (!isValidDisplayName(datasource.getDisplayName())) { throw new IllegalArgumentException("DataSource DisplayName is Invalid!"); } if (datasource.getType() == null) { throw new IllegalArgumentException("DataSource Type is Empty!"); } datasource.setName(slg.slugify(datasource.getDisplayName())); datasource.setOwner(getUserName()); long id = datasourceService.addDataSource(datasource); if (id > 0) { return Response.ok(datasource).build(); } else { return Response.status(Status.BAD_REQUEST).build(); } } catch (Exception ex) { logger.warn("Response Error: " + ex.getMessage()); return handleException(ex); } }
From source file:fr.gael.dhus.server.http.valve.AccessValve.java
private String[] extractAndDecodeHeader(String header) throws IOException { if (header == null || header.isEmpty()) { return null; }// w w w . j a v a2s. co m byte[] base64Token = header.substring(6).getBytes("UTF-8"); byte[] decoded; try { decoded = 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:net.rrm.ehour.user.service.UserServiceImpl.java
@Override @Transactional/*from www .j av a2s. c o m*/ public void changePassword(String username, String currentPassword, String newUnencryptedPassword) throws BadCredentialsException { User user = userDAO.findByUsername(username); Validate.notNull(user, String.format("Can't find user with username %s", username)); String encryptedCurrentPassword = encryptPassword(currentPassword, user.getSalt()); if (!user.getPassword().equals(encryptedCurrentPassword)) { throw new BadCredentialsException("Invalid current password"); } changePassword(user, newUnencryptedPassword); }
From source file:edu.zipcloud.cloudstreetmarket.core.services.CommunityServiceImpl.java
@Override public User identifyUser(User user) { Preconditions.checkArgument(user.getPassword() != null, "The provided password cannot be null!"); Preconditions.checkArgument(StringUtils.isNotEmpty(user.getPassword()), "The provided password cannot be empty!"); User retreivedUser = userRepository.findOne(user.getUsername()); if (!passwordEncoder.matches(user.getPassword(), retreivedUser.getPassword())) { throw new BadCredentialsException("No match has been found with the provided credentials!"); }//from w ww .j a v a 2 s . c om return retreivedUser; }
From source file:com.telefonica.euro_iaas.sdc.puppetwrapper.auth.OpenStackAuthenticationProvider.java
@Override protected final UserDetails retrieveUser(final String username, final UsernamePasswordAuthenticationToken authentication) { PaasManagerUser user = null;//www.j a v a 2 s. co m String tenantId = null; if (null != authentication.getCredentials()) { tenantId = authentication.getCredentials().toString(); if (SYSTEM_FIWARE.equals(cloudSystem)) { try { user = authenticationFiware(username, tenantId); } catch (AuthenticationConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (SYSTEM_FASTTRACK.equals(cloudSystem)) { user = authenticationFastTrack(username, tenantId); } } else { String str = "Missing tenantId header"; log.info(str); throw new BadCredentialsException(str); } return user; }
From source file:com.ebay.pulsar.analytics.resources.PermissionControlResource.java
@DELETE @Path("datasources/{datasourceName}") @Consumes(MediaType.APPLICATION_JSON)// ww w . j a va 2 s . c o m @Produces(MediaType.APPLICATION_JSON) public Response deleteDatasource(@Context HttpServletRequest request, @PathParam("datasourceName") String datasourceName) { logger.info("Delete DataSources API called from IP: " + request.getRemoteAddr()); try { if (isAnonymous()) { throw new BadCredentialsException("Bad credentials"); } if (datasourceName == null) { throw new IllegalArgumentException("No DataSource Name to Delete!"); } int id = datasourceService.deleteDataSource(datasourceName); 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:fragment.web.AuthenticationControllerTest.java
@Test public void testLoginFailedAuth() throws Exception { MockHttpServletRequest request = getRequestTemplate(HttpMethod.GET, "/login"); request.setParameter("login_failed", ""); MockHttpSession mockSession = new MockHttpSession(); mockSession.setAttribute(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY, "someuser"); mockSession.setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, new BadCredentialsException("Bad creds")); String actualResult = controller.login(request, map, mockSession); if (config.getAuthenticationService().compareToIgnoreCase("cas") == 0) { Assert.assertEquals("redirect:" + config.getCasLoginUrl() + "?service=" + URLEncoder.encode(config.getCasServiceUrl(), "UTF-8"), actualResult); } else {/*w w w. j av a2 s. c om*/ Assert.assertEquals("auth.login", actualResult); } String message = (String) map.get("error"); Assert.assertNotNull(message); Assert.assertThat(message, JUnitMatchers.containsString("Username or password incorrect.")); }
From source file:iplatform.admin.ui.server.auth.ad.ActiveDirectoryLdapAuthenticationProvider.java
private BadCredentialsException badCredentials() { /*return new BadCredentialsException(messages.getMessage( "LdapAuthenticationProvider.badCredentials", "Bad credentials")); *///from ww w .j a v a 2 s .c o m return new BadCredentialsException(messages.getMessage("LdapAuthenticationProvider.badCredentials", "?? ? ? ")); }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java
@RequestMapping(value = "/oauth/authorize", params = "response_type") public ModelAndView startAuthorization(HttpServletRequest request, @RequestParam Map<String, String> parameters, Map<String, Object> model, @RequestHeader HttpHeaders headers, Principal principal) throws Exception { String path = extractPath(request); MultiValueMap<String, String> map = new LinkedMaskingMultiValueMap<String, String>(); map.setAll(parameters);/*w ww . ja v a 2 s . c o m*/ String redirectUri = parameters.get("redirect-uri"); if (redirectUri != null && !redirectUri.matches("(http:|https:)?//.*")) { redirectUri = "http://" + redirectUri; map.set("redirect-uri", redirectUri); } if (principal != null) { map.set("source", "login"); map.setAll(getLoginCredentials(principal)); map.remove("credentials"); // legacy cf might break otherwise map.remove("password"); // request for token will not use password } else { throw new BadCredentialsException("No principal found in authorize endpoint"); } HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.putAll(getRequestHeaders(headers)); requestHeaders.remove(AUTHORIZATION.toLowerCase()); requestHeaders.remove(USER_AGENT); requestHeaders.remove(ACCEPT.toLowerCase()); requestHeaders.remove(CONTENT_TYPE.toLowerCase()); requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); requestHeaders.remove(COOKIE); requestHeaders.remove(COOKIE.toLowerCase()); @SuppressWarnings("rawtypes") ResponseEntity<Map> response; response = authorizationTemplate.exchange(getUaaBaseUrl() + "/" + path, HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(map, requestHeaders), Map.class); saveCookie(response.getHeaders(), model); @SuppressWarnings("unchecked") Map<String, Object> body = response.getBody(); if (body != null) { // User approval is required logger.debug("Response: " + body); model.putAll(body); model.put("links", getLinksInfo()); if (!body.containsKey("options")) { String errorMsg = "No options returned from UAA for user approval"; if (body.containsKey("error")) { throw OAuth2Exception.create((String) body.get("error"), (String) (body.containsKey("error_description") ? body.get("error_description") : errorMsg)); } else { throw new OAuth2Exception(errorMsg); } } logger.info("Approval required in /oauth/authorize for: " + principal.getName()); return new ModelAndView("access_confirmation", model); } String location = response.getHeaders().getFirst("Location"); if (location != null) { logger.info("Redirect in /oauth/authorize for: " + principal.getName()); // Don't expose model attributes (cookie) in redirect return new ModelAndView(new RedirectView(location, false, true, false)); } throw new IllegalStateException("Neither a redirect nor a user approval"); }