Example usage for org.springframework.security.core Authentication getPrincipal

List of usage examples for org.springframework.security.core Authentication getPrincipal

Introduction

In this page you can find the example usage for org.springframework.security.core Authentication getPrincipal.

Prototype

Object getPrincipal();

Source Link

Document

The identity of the principal being authenticated.

Usage

From source file:com.porvak.bracket.socialize.signin.AccountExposingHandlerInterceptor.java

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth != null && auth.getPrincipal() instanceof Account) {
        request.setAttribute("account", auth.getPrincipal());
    }/*from   ww  w  .j av a 2s  .c  om*/
    return true;
}

From source file:org.openlmis.fulfillment.security.CustomUserAuthenticationConverterTest.java

private void checkAuthentication(UUID userId, Authentication authentication) {
    assertEquals(userId, authentication.getPrincipal());
    assertEquals("N/A", authentication.getCredentials());
    assertTrue(authentication.isAuthenticated());
}

From source file:org.zalando.example.zauth.controller.WebController.java

@RequestMapping(value = { "/", "/index" })
public String index(final Model model) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    auth.getPrincipal();

    String currentLogin = zAuth.getCurrentLogin();
    model.addAttribute("currentLogin", currentLogin);

    User user = zAuth.userOperations().getUserById(currentLogin);
    model.addAttribute("user", user);
    return "index";
}

From source file:opensnap.security.CustomAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    String username = ((Principal) authentication.getPrincipal()).getName();
    this.template.convertAndSend(Topic.USER_AUTHENTICATED, this.userService.getByUsername(username));
}

From source file:org.jtalks.common.security.web.SuccessfulAuthenticationHandler.java

/**
 * Handle user's successfull authentication.
 * Updates last login time for authenticated user.
 *
 * @param request        http request//from w ww. j  a v  a2s . co  m
 * @param response       http response
 * @param authentication user's authentication
 * @throws javax.servlet.ServletException .
 * @throws java.io.IOException            .
 */
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    User user = (User) authentication.getPrincipal();
    lastLoginTimeService.updateLastLoginTime(user);
    logger.info("User logged in: " + user.getUsername());
    super.onAuthenticationSuccess(request, response, authentication);
}

From source file:org.jtalks.common.web.util.SuccessfulAuthenticationHandler.java

/**
 * Handle user's successfull authentication.
 * Updates last login time for authenticated user.
 *
 * @param request        http request//from  w  w  w . j a  v a  2s. c o m
 * @param response       http response
 * @param authentication user's authentication
 * @throws javax.servlet.ServletException .
 * @throws java.io.IOException            .
 */
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    User user = (User) authentication.getPrincipal();
    userService.updateLastLoginTime(user);
    logger.info("User logged in: " + user.getUsername());
    super.onAuthenticationSuccess(request, response, authentication);
}

From source file:ua.com.codefire.dao.ContactDAOImpl.java

@Override
public String CurrentUser() {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    Object obj = auth.getPrincipal();

    String UserName = ((UserDetails) obj).getUsername();

    return UserName;
}

From source file:com.indusborn.ui.signin.AccountExposingHandlerInterceptor.java

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth != null && auth.getPrincipal() instanceof UserVO) {
        request.setAttribute("userVO", auth.getPrincipal());
    }/* w  w w  . ja  v a2  s .  c  om*/
    return true;
}

From source file:com.mustafaderyol.inventory.beans.LoginControlClass.java

public void authorizedUserControl() {

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    if (!authentication.getPrincipal().toString().equals("anonymousUser")) {

        NavigationHandler nh = FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
        nh.handleNavigation(FacesContext.getCurrentInstance(), null, "/dashboard.xhtml?faces-redirect=true");

    }//from w  w  w. j a  v  a2 s.co m
}

From source file:org.energyos.espi.datacustodian.web.customer.UsagePointControllerTests.java

@Test
@Ignore("TODO: come back to it b/f we're finished")
public void feed_returnsAtomFeedOfUsagePointsForCurrentUser() throws Exception {
    Authentication auth = mock(Authentication.class);
    when(auth.getPrincipal()).thenReturn(mock(RetailCustomer.class));
    MockHttpServletResponse response = new MockHttpServletResponse();

    HashMap<String, String> params = new HashMap<>();
    // controller.feed(response, auth, params);

    verify(exportService).exportUsagePoints(anyLong(), anyLong(), any(OutputStream.class),
            eq(new ExportFilter(params)));
}