List of usage examples for org.springframework.security.core Authentication getPrincipal
Object getPrincipal();
From source file:shiver.me.timbers.spring.security.jwt.JwtPrincipalAuthenticationConverter.java
private String extractUsername(Authentication authentication) { final Object principal = authentication.getPrincipal(); if (principal instanceof UserDetails) { return ((UserDetails) principal).getUsername(); }/* w ww.j ava2 s. c om*/ return principal.toString(); }
From source file:org.energyos.espi.datacustodian.web.DefaultControllerTest.java
@Test public void whenRoleUser_redirectsToRetailCustomerHome() { DefaultController controller = new DefaultController(); RetailCustomer customer = new RetailCustomer(); customer.setId(99L);//from w ww . ja v a2 s . com HttpServletRequest request = mock(HttpServletRequest.class); when(request.isUserInRole(RetailCustomer.ROLE_USER)).thenReturn(true); when(request.isUserInRole(RetailCustomer.ROLE_CUSTODIAN)).thenReturn(false); Authentication principal = mock(Authentication.class); when(principal.getPrincipal()).thenReturn(customer); assertEquals("redirect:/RetailCustomer/" + customer.getId() + "/home", controller.defaultAfterLogin(request, principal)); }
From source file:org.vaadin.spring.samples.mvp.ui.presenter.BannerPresenter.java
@EventBusListenerMethod(filter = StartupFilter.class) public void onStartup(Action action) { if (security.isAuthenticated()) { Authentication auth = security.getAuthentication(); User user = (User) auth.getPrincipal(); getView().setUser(user.getUsername()); }/*w ww. j a v a 2s . co m*/ }
From source file:org.jblogcms.core.security.controller.CurrentUser.java
@ModelAttribute("currentUser") public AccountDetails getCurrentUser(Authentication authentication) { return (authentication == null) ? null : (AccountDetails) authentication.getPrincipal(); }
From source file:com.example.securelogin.app.common.security.CacheClearLogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { if (authentication.getPrincipal() instanceof LoggedInUser) { LoggedInUser details = (LoggedInUser) authentication.getPrincipal(); accountSharedService.clearPasswordValidationCache(details.getUsername()); }/*from w ww.j ava2 s. c o m*/ super.onLogoutSuccess(request, response, authentication); }
From source file:es.osoco.grails.plugins.otp.access.OneTimePasswordVoter.java
private boolean isOtpAuthenticated(Authentication authentication) { return authentication.getPrincipal() instanceof GrailsOtpUser; }
From source file:de.fau.amos4.web.CurrentClientControllerAdvice.java
/** * Makes the current user available in all views with the name "currentClient". * * @param authentication// w ww .ja va2 s . c o m * @return */ @ModelAttribute("currentClient") public CurrentClient getCurrentUser(Authentication authentication) { return (authentication == null) ? null : (CurrentClient) authentication.getPrincipal(); }
From source file:com.trenako.security.permissions.TrenakoPermissionEvaluator.java
private Account user(Authentication authentication) { Object user = authentication.getPrincipal(); if (user instanceof Account) { return (Account) user; }//from w w w.jav a 2 s . c o m if (user instanceof AccountDetails) { return ((AccountDetails) user).getAccount(); } return null; }
From source file:org.jasig.portlet.survey.security.PortalPreAuthenticatedUserDetailsService.java
@Override public UserDetails loadUserDetails(Authentication authentication) throws UsernameNotFoundException { UserDetails userDetails = (UserDetails) authentication.getPrincipal(); return userDetails; }
From source file:org.openmhealth.shim.AccessParameterClientTokenServices.java
@Override public void removeAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication) { String username = authentication.getPrincipal().toString(); String shimKey = authentication.getDetails().toString(); List<AccessParameters> accessParameters = accessParametersRepo.findAllByUsernameAndShimKey(username, shimKey);/*w w w .j a va 2s. c o m*/ for (AccessParameters accessParameter : accessParameters) { accessParametersRepo.delete(accessParameter); } }