List of usage examples for org.springframework.security.core Authentication getDetails
Object getDetails();
From source file:org.openmhealth.shim.AccessParameterClientTokenServices.java
@Override public OAuth2AccessToken getAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication) { String username = authentication.getPrincipal().toString(); String shimKey = authentication.getDetails().toString(); AccessParameters accessParameters = accessParametersRepo.findByUsernameAndShimKey(username, shimKey, new Sort(Sort.Direction.DESC, "dateCreated")); if (accessParameters == null || accessParameters.getSerializedToken() == null) { return null; //No token was found! }/* ww w . ja v a 2 s . c o m*/ return SerializationUtils.deserialize(accessParameters.getSerializedToken()); }
From source file:org.appverse.web.framework.backend.api.helpers.security.PreAuthUserDetailsService.java
@SuppressWarnings("unchecked") @Override//from w ww . ja v a2 s. co m public UserDetails loadUserDetails(Authentication token) throws UsernameNotFoundException { String username = (String) token.getPrincipal(); List<String> externalAuthorities = null; if (token.getDetails() instanceof String) { externalAuthorities = new ArrayList<String>(); externalAuthorities.add((String) token.getDetails()); } else { externalAuthorities = (List<String>) token.getDetails(); } List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (String externalAuthority : externalAuthorities) { GrantedAuthority authority = new SimpleGrantedAuthority(externalAuthority); authorities.add(authority); } User user = new User(username, "", true, true, true, true, authorities); return user; }
From source file:com.jaspersoft.jasperserver.ps.OAuth.OAuthMTExternalDataSynchronizerImpl.java
protected void loadExternalUserDetailsToProcessorData(final Authentication auth) { final ProcessorData processorData = ProcessorData.getInstance(); final List<Map<String, Object>> loadedDetails = null; Object authDetails = auth.getDetails(); // if (authDetails instanceof OAuthMTUserDetails) { String tenantId = ((User) authDetails).getTenantId(); logger.debug("is externally defined: " + ((User) authDetails).isExternallyDefined()); //set the external auth user detail information in the thread safe processorData variable for use by the user processors/synching process processorData.addData(EXTERNAL_AUTH_DETAILS, ((UserDetails) authDetails)); processorData.addData(EXTERNAL_AUTHORITIES, ((UserDetails) authDetails).getAuthorities()); processorData.addData(EXTERNAL_JRS_USER_TENANT_ID, tenantId == null || tenantId.trim().length() == 0 ? null : tenantId); // }/*from ww w . jav a 2 s . c o m*/ }
From source file:com.jaspersoft.jasperserver.ps.SAMLMTExternalDataSynchronizerImpl.java
protected void loadExternalUserDetailsToProcessorData(final Authentication auth) { final ProcessorData processorData = ProcessorData.getInstance(); final List<Map<String, Object>> loadedDetails = null; Object authDetails = auth.getDetails(); // if (authDetails instanceof SAMLMTUserDetails) { String tenantId = ((User) authDetails).getTenantId(); logger.debug("is externally defined: " + ((User) authDetails).isExternallyDefined()); //set the external auth user detail information in the thread safe processorData variable for use by the user processors/synching process processorData.addData(EXTERNAL_AUTH_DETAILS, ((UserDetails) authDetails)); processorData.addData(EXTERNAL_AUTHORITIES, ((UserDetails) authDetails).getAuthorities()); processorData.addData(EXTERNAL_JRS_USER_TENANT_ID, tenantId == null || tenantId.trim().length() == 0 ? null : tenantId); //}/*from w w w . jav a 2 s. co m*/ }
From source file:org.openmhealth.shim.AccessParameterClientTokenServices.java
@Override public void saveAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication, OAuth2AccessToken accessToken) { String username = authentication.getPrincipal().toString(); String shimKey = authentication.getDetails().toString(); AccessParameters accessParameters = accessParametersRepo.findByUsernameAndShimKey(username, shimKey, new Sort(Sort.Direction.DESC, "dateCreated")); if (accessParameters == null) { accessParameters = new AccessParameters(); accessParameters.setUsername(username); accessParameters.setShimKey(shimKey); }/*from w ww . j a v a2 s.co m*/ accessParameters.setSerializedToken(SerializationUtils.serialize(accessToken)); accessParametersRepo.save(accessParameters); }
From source file:ru.org.linux.auth.LoginController.java
@RequestMapping(value = "/login_process", method = RequestMethod.POST) public ModelAndView loginProcess(@RequestParam("nick") final String username, @RequestParam("passwd") final String password, HttpServletRequest request, HttpServletResponse response) throws Exception { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password); try {/* www.j a va 2 s .co m*/ UserDetailsImpl details = (UserDetailsImpl) userDetailsService.loadUserByUsername(username); token.setDetails(details); Authentication auth = authenticationManager.authenticate(token); UserDetailsImpl userDetails = (UserDetailsImpl) auth.getDetails(); if (!userDetails.getUser().isActivated()) { throw new AccessViolationException("User not activated"); } SecurityContextHolder.getContext().setAuthentication(auth); rememberMeServices.loginSuccess(request, response, auth); AuthUtil.updateLastLogin(auth, userDao); } catch (Exception e) { return new ModelAndView(new RedirectView("/login.jsp?error=true")); } return new ModelAndView(new RedirectView("/")); }
From source file:org.brekka.pegasus.core.services.impl.EventServiceImpl.java
protected void populate(final RemoteUserEvent remoteUserEvent) { remoteUserEvent.setInitiated(new Date()); SecurityContext context = SecurityContextHolder.getContext(); Authentication authentication = context.getAuthentication(); Object details = authentication.getDetails(); if (details instanceof WebAuthenticationDetails) { WebAuthenticationDetails wad = (WebAuthenticationDetails) details; remoteUserEvent.setOnBehalfOfAddress(wad.getOnBehalfOfAddress()); remoteUserEvent.setRemoteAddress(wad.getRemoteAddress()); remoteUserEvent.setUserAgent(wad.getUserAgent()); } else {/*from w w w. j a va 2 s .c om*/ throw new IllegalStateException( String.format("No web authentication details found in authentication %s, principal: %s", authentication.getClass().getName(), authentication.getPrincipal())); } MemberContext current = memberService.getCurrent(); if (current != null) { remoteUserEvent.setMember(current.getMember()); } }
From source file:ru.org.linux.auth.LoginController.java
@RequestMapping(value = "/ajax_login_process", method = RequestMethod.POST) @ResponseBody/*from w w w. j a v a2 s . c o m*/ public LoginStatus loginAjax(@RequestParam("nick") final String username, @RequestParam("passwd") final String password, HttpServletRequest request, HttpServletResponse response) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password); try { UserDetailsImpl details = (UserDetailsImpl) userDetailsService.loadUserByUsername(username); token.setDetails(details); Authentication auth = authenticationManager.authenticate(token); UserDetailsImpl userDetails = (UserDetailsImpl) auth.getDetails(); if (!userDetails.getUser().isActivated()) { return new LoginStatus(false, "User not activated"); } SecurityContextHolder.getContext().setAuthentication(auth); rememberMeServices.loginSuccess(request, response, auth); AuthUtil.updateLastLogin(auth, userDao); return new LoginStatus(auth.isAuthenticated(), auth.getName()); } catch (LockedException e) { return new LoginStatus(false, "User locked"); } catch (UsernameNotFoundException e) { return new LoginStatus(false, "Bad credentials"); } catch (BadCredentialsException e) { return new LoginStatus(false, e.getMessage()); } }
From source file:edu.wisc.portlet.hrs.security.HrsPreAuthenticatedGrantedAuthoritiesUserDetailsService.java
@Override protected UserDetails createuserDetails(Authentication token, Collection<? extends GrantedAuthority> authorities) { final PrimaryAttributePortletAuthenticationDetails details = (PrimaryAttributePortletAuthenticationDetails) token .getDetails();/*from w ww . j a v a2 s . c o m*/ final String emplId = details.getPrimaryAttribute(); final Set<String> hrsRoles = this.hrsRolesDao.getHrsRoles(emplId); final Collection<GrantedAuthority> additionalGrantedAuthorities = new ArrayList<GrantedAuthority>( hrsRoles.size() + authorities.size()); additionalGrantedAuthorities.addAll(authorities); for (final String hrsRole : hrsRoles) { additionalGrantedAuthorities.add(new SimpleGrantedAuthority(hrsRole)); } return super.createuserDetails(token, additionalGrantedAuthorities); }
From source file:org.openmrs.cwf.security.base.OpenmrsSecurityFilter.java
/** * This method is called for every request. The main point of this is to make sure the user's * current userContext is set.// www .ja v a2 s.c o m * * @see org.springframework.web.filter.OncePerRequestFilter#doFilterInternal(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, javax.servlet.FilterChain) */ @Override protected void doFilterInternal(HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterChain chain) throws ServletException, IOException { Context.clearUserContext(); Authentication auth = AbstractSecurityService.getAuthentication(); CWFAuthenticationDetails details = auth == null ? null : (CWFAuthenticationDetails) auth.getDetails(); // User context is created if it doesn't already exist and added to the authentication detail // object. UserContext userContext = details == null ? null : (UserContext) details.getDetail("userContext"); // if there isn't a userContext on the session yet, create one // and set it onto the session if (userContext == null) { userContext = BaseSecurityService.ensureUserContext(); if (log.isDebugEnabled()) { log.debug("Just set user context " + userContext + " as attribute on authorization detail."); } } else { // Add the user context to the current thread Context.setUserContext(userContext); } Thread.currentThread().setContextClassLoader(OpenmrsClassLoader.getInstance()); log.debug("before chain.Filter"); // continue the filter chain (going on to spring, authorization, etc) try { chain.doFilter(httpRequest, httpResponse); } finally { Context.clearUserContext(); } log.debug("after chain.doFilter"); }