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:com.cb.controllers.WebSocketsController.java

/**
 * Method gets executed when there are requests to the
 * <code>/secured/basicWebsockets</code> url. This url is called after a
 * successful login.//from w  ww  .  j a  v a2  s  . c  o m
 *
 * @param model
 * @param principal
 * @param locale
 * @return
 */
@RequestMapping("/secured/basicWebsockets")
public String basicWebsocketsPage(Model model, Principal principal, Locale locale) {

    // Get a simple human readable date and time
    String formattedDate = Util.getSimpleDate(locale);

    // Get the logged in user's name
    String userName = principal.getName();

    // Set some sample messages to show on the landing 'basicWebsockets.jsp'
    // page.
    model.addAttribute("username", userName);
    model.addAttribute("time", formattedDate);

    LOG.info("Request from user:{} for /secured/basicWebsockets url processed at time:{}", userName,
            formattedDate);

    return "secured/basicWebsockets";
}

From source file:shiver.me.timbers.security.web.controller.UserHandlerMethodArgumentResolverTest.java

@Test
public void Can_resolver_a_user() throws Exception {

    final NativeWebRequest request = mock(NativeWebRequest.class);

    final Principal principal = mock(Principal.class);
    final String username = someString();

    final User expected = mock(User.class);

    // Given/*from  w  ww.  jav a2  s .c o m*/
    given(request.getUserPrincipal()).willReturn(principal);
    given(principal.getName()).willReturn(username);
    given(userRepository.findByUsername(username)).willReturn(expected);

    // When
    final User actual = resolver.resolveArgument(mock(MethodParameter.class), mock(ModelAndViewContainer.class),
            request, mock(WebDataBinderFactory.class));

    // Then
    assertThat(actual, equalTo(expected));
}

From source file:fi.okm.mpass.shibboleth.profile.impl.AbstractAuthnFlowRestResponseAction.java

/**
 * Checks if the given flow exists in the list of ignored flows.
 * @param flow The flow to be checked.//  ww  w.j ava  2s  .c  o m
 * @param flowId The (stripped) flow id to be checked.
 * @return true if it exists, false otherwise.
 */
protected boolean isIgnoredFlow(final AuthenticationFlowDescriptor flow, final String flowId) {
    final Collection<Principal> principals = flow.getSupportedPrincipals();
    if (principals == null || principals.isEmpty()) {
        log.trace("{} Empty set of supported principals for {}, will be ignored", getLogPrefix(), flowId);
        return true;
    }
    boolean mpassPrincipalFound = false;
    for (final Principal principal : principals) {
        if (principal.getName().startsWith(AuthenticationDiscoveryContext.PRINCIPAL_PREFIX)) {
            mpassPrincipalFound = true;
        }
    }
    if (!mpassPrincipalFound) {
        return true;
    }
    if (ignoredFlowIds == null || ignoredFlowIds.isEmpty()) {
        return false;
    }
    return ignoredFlowIds.contains(flowId);
}

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

@PreAuthorize("hasRole(USER)")
@RequestMapping(method = RequestMethod.POST, value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/unlike")
public @ResponseBody void unlikeVideo(@PathVariable("id") long id, Principal principal,
        HttpServletResponse response) {//from w ww .j a  va2 s  . co m
    Video v = videoRepo.findOne(id);
    if (v != null) {
        HashSet<String> likers = v.getLikers();
        if (likers.contains(principal.getName())) {
            likers.remove(principal.getName());
            videoRepo.save(v);
            response.setStatus(HttpServletResponse.SC_OK);
        } else
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    } else
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}

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

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/unlike", method = RequestMethod.POST)
public void unlikeVideo(@PathVariable long id, Principal principal, HttpServletResponse response) {
    Video v = _videoRepository.findOne(id);
    if (v == null) {
        response.setStatus(HttpStatus.SC_NOT_FOUND);
        return;/*from www. j  av  a  2s.c o  m*/
    }
    String username = principal.getName();
    v.unlike(username);
    _videoRepository.save(v);
}

From source file:net.d53.syman.web.controller.PatientController.java

@RequestMapping(value = "/api/patient", method = RequestMethod.GET)
public @ResponseBody Patient getOwnData(Principal p) {
    Patient patient = patientRepository.findByUsername(p.getName());
    return patient;
}

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

@Override
@RequestMapping(value = "/{systemId}", method = RequestMethod.PUT, consumes = { APPLICATION_JSON_VALUE })
@ResponseBody// w w  w .j av a  2 s  .c  o  m
@PreAuthorize(PROJECT_LEAD)
@ResponseStatus(HttpStatus.OK)
@ApiOperation("Update registered external system instance")
public OperationCompletionRS updateExternalSystem(@Validated @RequestBody UpdateExternalSystemRQ request,
        @PathVariable String projectName, @PathVariable String systemId, Principal principal) {
    return updateExternalSystemHandler.updateExternalSystem(request,
            EntityUtils.normalizeProjectName(projectName), systemId, principal.getName());
}

From source file:com.ushahidi.swiftriver.core.api.controller.FormsController.java

/**
 * Handler for modifying an existing form.
 * // ww w .  ja  v  a 2 s  .  c o  m
 * @param principal
 * @param id
 * @param modifyFormTo
 * @return
 */
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
@ResponseBody
public GetFormDTO modifyForm(Principal principal, @PathVariable Long id,
        @RequestBody ModifyFormDTO modifyFormTo) {

    return formService.modifyForm(id, modifyFormTo, principal.getName());
}

From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.server.GPSecureServerResource.java

@GET
@Path(value = GPServiceRSPathConfig.GET_SHORT_SERVER_PATH)
@Override// w  w  w  . j a v  a  2 s . c om
public ServerDTO getShortServer(@Auth Principal principal, @QueryParam(value = "serverUrl") String serverUrl)
        throws Exception {
    logger.debug("\n\n@@@@@@@@@@@@@@Executing secure getShortServer - " + "Principal : {}\n\n",
            principal.getName());
    return super.getShortServer(serverUrl);
}

From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.server.GPSecureServerResource.java

@GET
@Path(value = GPServiceRSPathConfig.GET_SERVER_DETAIL_BY_URL_PATH)
@Override/*from  w w w . j  a va  2 s  .c o  m*/
public GeoPlatformServer getServerDetailByUrl(@Auth Principal principal,
        @QueryParam(value = "serverUrl") String serverUrl) throws Exception {
    logger.debug("\n\n@@@@@@@@@@@@@@Executing secure getShortServer - " + "Principal : {}\n\n",
            principal.getName());
    return super.getServerDetailByUrl(serverUrl);
}