Example usage for org.springframework.security.authentication BadCredentialsException BadCredentialsException

List of usage examples for org.springframework.security.authentication BadCredentialsException BadCredentialsException

Introduction

In this page you can find the example usage for org.springframework.security.authentication BadCredentialsException BadCredentialsException.

Prototype

public BadCredentialsException(String msg) 

Source Link

Document

Constructs a BadCredentialsException with the specified message.

Usage

From source file:ru.efo.security.ADUserDetailsService.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    final String username = authentication.getName();
    final String password = authentication.getCredentials().toString();
    logger.log(Level.FINE, "Performing logon into '" + ldapUrl + "' with credentials '" + username + "'/'"
            + password.replaceAll(".", "*") + "'");

    DirContext context = null;/*from w  w  w  .j av  a 2s  .c  o m*/
    try {
        context = getDirContext(username + userSuffix, password);
        logger.log(Level.FINE, "User '" + username + "' has been successfully logged on");
        final ADUserDetails details = loadUserByUsername(context, username, password);
        return new UsernamePasswordAuthenticationToken(details, password, details.getAuthorities());
    } catch (NamingException ex) {
        logger.log(Level.SEVERE, "Could not login into '" + ldapUrl + "'", ex);
        throw new BadCredentialsException(ex.getMessage());
    } finally {
        if (context != null) {
            try {
                context.close();
            } catch (NamingException ex) {
                logger.log(Level.WARNING, "Could not close DirContext", ex);
            }
        }
    }
}

From source file:com.ebay.pulsar.analytics.resources.PermissionControlResource.java

@DELETE
@Path("dashboards")
@Consumes(MediaType.APPLICATION_JSON)/*  w  ww  .  j a  va  2 s.c  o m*/
@Produces(MediaType.APPLICATION_JSON)
public Response deleteDashboards(@Context HttpServletRequest request,
        @QueryParam("batch") String dashboardNames) {
    logger.info("Delete Dashboard API called from IP: " + request.getRemoteAddr());
    try {
        if (isAnonymous()) {
            throw new BadCredentialsException("Bad credentials");
        }
        if (dashboardNames == null) {
            throw new IllegalArgumentException("No Dashboards to Delete!");
        }
        int id = dashboardService.deleteDashboards(Lists.newArrayList(dashboardNames.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("dashboards")
@Consumes(MediaType.APPLICATION_JSON)//  w w  w .ja  va2s . com
@Produces(MediaType.APPLICATION_JSON)
public Response saveDashboard(@Context HttpServletRequest request, Dashboard d) {
    logger.info("Update Dashboard API called from IP: " + request.getRemoteAddr());
    try {
        DBDashboard dashboard = d.toDBDashboard();
        if (isAnonymous()) {
            throw new BadCredentialsException("Bad credentials");
        }
        if (dashboard.getName() == null) {
            throw new IllegalArgumentException("Dashboard Name is Empty!");
        }
        if (!this.validateDashboardConfig(dashboard.getConfig())) {
            throw new IllegalArgumentException("Invalid Dashboard config");
        }
        if (!isValidDisplayName(dashboard.getDisplayName())) {
            throw new IllegalArgumentException("Dashboard DisplayName is Invalid!");
        }
        dashboard.setName(dashboard.getName().toLowerCase());
        long id = dashboardService.updateDashboard(dashboard.getName(), dashboard.getDisplayName(),
                dashboard.getConfig());
        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("dashboards/{dashboardName}")
@Produces(MediaType.APPLICATION_JSON)/*from w ww  .  j a  v  a  2  s .  c o m*/
public Response getDashboard(@Context HttpServletRequest request,
        @PathParam("dashboardName") String dashboardName) {
    logger.info("List dashboards API called from IP: " + request.getRemoteAddr());
    try {
        if (isAnonymous()) {
            throw new BadCredentialsException("Bad credentials");
        }
        if (dashboardName == null) {
            throw new IllegalArgumentException("Dashboard Name is Empty!");
        }
        return Response.ok("get dashboard succeed!")
                .entity(this.converDBDashboard2Map(dashboardService.getDashboardByName(dashboardName))).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("dashboards")
@Produces(MediaType.APPLICATION_JSON)/*from   w  w w .ja va  2s . c  om*/
public Response getAllDashboardByUser(@Context HttpServletRequest request, @QueryParam("right") String right) {
    logger.info("List dashboards API called from IP: " + request.getRemoteAddr());
    try {
        if (isAnonymous()) {
            throw new BadCredentialsException("Bad credentials");
        }
        List<DBDashboard> databoards = null;
        if ("view".equalsIgnoreCase(right)) {
            databoards = dashboardService.getUserViewedDashboard();
            return Response.ok("get all viewed dashboards succeed!").entity(this.converList2Map(databoards))
                    .build();
        }
        if (right == null || "manage".equalsIgnoreCase(right)) {
            databoards = dashboardService.getAllUserManagedDashboard();

            return Response.ok("get all managed dashboards succeed!").entity(this.converList2Map(databoards))
                    .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

@POST
@Path("groups")
@Consumes(MediaType.APPLICATION_JSON)/*  w  ww  .j av a 2  s .  c  o m*/
@Produces(MediaType.APPLICATION_JSON)
public Response addGroup(@Context HttpServletRequest request, DBGroup group) {
    logger.info("Add Group API called from IP: " + request.getRemoteAddr());
    try {
        if (isAnonymous()) {
            throw new BadCredentialsException("Bad credentials");
        }
        if (!isValidDisplayName(group.getDisplayName())) {
            throw new IllegalArgumentException("Group DisplayName is Invalid!");
        }
        group.setName(slg.slugify(group.getDisplayName()));
        group.setOwner(getUserName());

        long id = groupService.addGroup(group);
        if (id > 0) {
            return Response.ok(group).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("groups")
@Consumes(MediaType.APPLICATION_JSON)/*w ww . ja v a 2 s . c o m*/
@Produces(MediaType.APPLICATION_JSON)
public Response saveDashboard(@Context HttpServletRequest request, DBGroup group) {
    logger.info("Update group API called from IP: " + request.getRemoteAddr());
    try {
        if (isAnonymous()) {
            throw new BadCredentialsException("Bad credentials");
        }
        if (group.getName() == null) {
            throw new IllegalArgumentException("Group Name is Empty!");
        }
        if (!isValidDisplayName(group.getDisplayName())) {
            throw new IllegalArgumentException("Group DisplayName is Invalid!");
        }
        long id = groupService.updateGroup(group.getName(), group.getDisplayName());
        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

@DELETE
@Path("groups/{groupName}")
@Consumes(MediaType.APPLICATION_JSON)//from w  w  w .  j  a va 2 s  .  c om
@Produces(MediaType.APPLICATION_JSON)
public Response deleteGroup(@Context HttpServletRequest request, @PathParam("groupName") String groupName) {
    logger.info("Delete Group API called from IP: " + request.getRemoteAddr());
    try {
        if (isAnonymous()) {
            throw new BadCredentialsException("Bad credentials");
        }
        if (groupName == null) {
            throw new IllegalArgumentException("No Group to Delete!");
        }
        int id = groupService.deleteGroup(groupName);

        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

@DELETE
@Path("groups")
@Consumes(MediaType.APPLICATION_JSON)/*  ww w  .  j a  va 2s .c om*/
@Produces(MediaType.APPLICATION_JSON)
public Response deleteGroups(@Context HttpServletRequest request, @QueryParam("batch") String groupNames) {
    logger.info("Delete Group API called from IP: " + request.getRemoteAddr());
    try {
        if (isAnonymous()) {
            throw new BadCredentialsException("Bad credentials");
        }
        if (groupNames == null) {
            throw new IllegalArgumentException("No Groups to Delete!");
        }
        int id = groupService.deleteGroups(Lists.newArrayList(groupNames.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

@GET
@Path("groups")
@Produces(MediaType.APPLICATION_JSON)//from   w ww  .  j a  v a2 s .  c  o m
public Response getAllGroupsByUser(@Context HttpServletRequest request, @QueryParam("right") String right) {
    logger.info("List Groups API called from IP: " + request.getRemoteAddr());
    try {
        if (isAnonymous()) {
            throw new BadCredentialsException("Bad credentials");
        }
        List<DBGroup> groups = null;
        if ("view".equalsIgnoreCase(right)) {
            groups = groupService.getAllUserViewedGroups();
            return Response.ok("get all groups succeed!").entity(groups).build();
        }
        if (right == null || "manage".equalsIgnoreCase(right)) {
            groups = groupService.getAllUserManagedGroups();
            return Response.ok("get all groups succeed!").entity(groups).build();
        }
        throw new IllegalArgumentException("Invalid QueryParm!");

    } catch (Exception ex) {
        logger.warn("Response Error: " + ex.getMessage());
        return handleException(ex);
    }

}