Example usage for java.security Principal getName

List of usage examples for java.security Principal getName

Introduction

In this page you can find the example usage for java.security Principal getName.

Prototype

public String getName();

Source Link

Document

Returns the name of this principal.

Usage

From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.acl.GPSecureACLResource.java

@GET
@Path(value = GPServiceRSPathConfig.GET_ALL_ROLES_PATH)
@Override// w  w  w  . ja  v  a2 s. c om
public WSGetRoleResponse getAllRoles(@Auth Principal principal,
        @PathParam(value = "organization") String organization) throws Exception {
    logger.debug("\n\n@@@@@@@@@@@@@@@@@Executing secure getAllRoles - " + "Principal : {}\n\n",
            principal.getName());
    return super.getAllRoles(organization);
}

From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.acl.GPSecureACLResource.java

@PUT
@Path(value = GPServiceRSPathConfig.UPDATE_ROLE_PERMISSION_PATH)
@Override/*from  w  w w . j  a  va2 s. c o  m*/
public Boolean updateRolePermission(@Auth Principal principal, WSPutRolePermissionRequest putRolePermissionReq)
        throws Exception {
    logger.debug("\n\n@@@@@@@@@@@@@@@Executing secure updateRolePermission" + " - Principal : {}\n\n",
            principal.getName());
    return super.updateRolePermission(putRolePermissionReq);
}

From source file:org.mitre.oauth2.web.TokenAPI.java

@RequestMapping(value = "/access", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public String getAllAccessTokens(ModelMap m, Principal p) {

    Set<OAuth2AccessTokenEntity> allTokens = tokenService.getAllAccessTokensForUser(p.getName());
    m.put(JsonEntityView.ENTITY, allTokens);
    return TokenApiView.VIEWNAME;
}

From source file:alfio.controller.api.AdminApiController.java

@RequestMapping(value = "/events/{eventName}/pending-payments")
public List<Pair<TicketReservation, OrderSummary>> getPendingPayments(
        @PathVariable("eventName") String eventName, Principal principal) {
    return eventManager.getPendingPayments(eventName, principal.getName());
}

From source file:io.fabric8.maven.impl.MavenSecureHttpContext.java

public Subject doAuthenticate(final String username, final String password) {
    try {//from   w w w  . j a  v  a 2 s .c om
        Subject subject = new Subject();
        LoginContext loginContext = new LoginContext(realm, subject, new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (int i = 0; i < callbacks.length; i++) {
                    if (callbacks[i] instanceof NameCallback) {
                        ((NameCallback) callbacks[i]).setName(username);
                    } else if (callbacks[i] instanceof PasswordCallback) {
                        ((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
                    } else {
                        throw new UnsupportedCallbackException(callbacks[i]);
                    }
                }
            }
        });
        loginContext.login();
        if (role != null && role.length() > 0) {
            String clazz = "org.apache.karaf.jaas.boot.principal.RolePrincipal";
            String name = role;
            int idx = role.indexOf(':');
            if (idx > 0) {
                clazz = role.substring(0, idx);
                name = role.substring(idx + 1);
            }
            boolean found = false;
            for (Principal p : subject.getPrincipals()) {
                if (p.getClass().getName().equals(clazz) && p.getName().equals(name)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new FailedLoginException("User does not have the required role " + role);
            }
        }
        return subject;
    } catch (AccountException e) {
        LOGGER.warn("Account failure", e);
        return null;
    } catch (LoginException e) {
        LOGGER.debug("Login failed", e);
        return null;
    } catch (GeneralSecurityException e) {
        LOGGER.error("General Security Exception", e);
        return null;
    }
}

From source file:org.magnum.mobilecloud.video.MainController_HW_2.java

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/like", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Void> likeVideo(@PathVariable("id") long id, Principal p) {

    if (videos.findOne(id) == null) {
        return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
    }/*from  ww w.j a v a 2s  .  co  m*/

    String username = p.getName();
    Video v = videos.findOne(id);
    Set<String> likesUsernames = v.getLikesUsernames();

    // Checks if the user has already liked the video.
    if (likesUsernames.contains(username)) {
        //videos.save(v);
        return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
    }

    likesUsernames.add(username);
    v.setLikesUsernames(likesUsernames);
    v.setLikes(likesUsernames.size());
    //v.setLikes(1);
    videos.save(v);
    return new ResponseEntity<Void>(HttpStatus.OK);
}

From source file:org.mitre.oauth2.web.TokenAPI.java

@RequestMapping(value = "/refresh", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public String getAllRefreshTokens(ModelMap m, Principal p) {

    Set<OAuth2RefreshTokenEntity> allTokens = tokenService.getAllRefreshTokensForUser(p.getName());
    m.put(JsonEntityView.ENTITY, allTokens);
    return TokenApiView.VIEWNAME;

}

From source file:com.jd.survey.web.security.DepartmentController.java

@Secured({ "ROLE_ADMIN" })
@RequestMapping(params = "create", produces = "text/html")
public String createGet(Model uiModel, Principal principal) {
    try {/*from  w w  w  . j  a v  a  2 s.co  m*/
        User user = userService.user_findByLogin(principal.getName());
        populateEditForm(uiModel, new Department(), user);
        return "security/departments/create";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:com.epam.ta.reportportal.ws.controller.impl.TestItemController.java

@Override
@ResponseBody/* w ww.j  a  v  a  2s  . com*/
@ResponseStatus(OK)
@DeleteMapping
public List<OperationCompletionRS> deleteTestItems(@PathVariable String projectName,
        @RequestParam(value = "ids") String[] ids, Principal principal) {
    return deleteTestItemHandler.deleteTestItem(ids, normalizeProjectName(projectName), principal.getName());
}

From source file:org.magnum.mobilecloud.video.MainController_HW_2.java

@RequestMapping(value = "/video/{id}/unlike", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Void> unlikeVideo(@PathVariable("id") long id, Principal p) {

    if (videos.findOne(id) == null) {
        return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
    }/*from  w w  w  .  j  a v  a  2s  .c o  m*/

    String username = p.getName();
    Video v = videos.findOne(id);
    Set<String> likesUsernames = (Set<String>) v.getLikesUsernames();

    // Checks if the user has already liked the video.
    if (likesUsernames.contains(username)) {
        likesUsernames.remove(username);
        v.setLikesUsernames(likesUsernames);
        v.setLikes(likesUsernames.size());
        videos.save(v);

        return new ResponseEntity<Void>(HttpStatus.OK);
    }
    //videos.save(v);
    return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
}