List of usage examples for org.springframework.security.core Authentication getDetails
Object getDetails();
From source file:org.zalando.stups.oauth2.spring.client.AccessTokenUtilsTest.java
@Test public void testGetToken() throws Exception { final Authentication userAuthentication = mock(Authentication.class); when(userAuthentication.getDetails()).thenReturn(singletonMap(ACCESS_TOKEN, "1234567890")); SecurityContextHolder.getContext()/*from w w w .j a v a 2 s . com*/ .setAuthentication(new OAuth2Authentication(mock(OAuth2Request.class), userAuthentication)); assertThat(getAccessTokenFromSecurityContext().get()).contains("1234567890"); }
From source file:org.zalando.stups.oauth2.spring.client.SecurityContextTokenProviderTest.java
@Before public void setUp() throws Exception { tokenProvider = new SecurityContextTokenProvider(); final Authentication userAuthentication = mock(Authentication.class); when(userAuthentication.getDetails()).thenReturn(singletonMap(ACCESS_TOKEN, "1234567890")); SecurityContextHolder.getContext().setAuthentication( // new OAuth2Authentication(mock(OAuth2Request.class), userAuthentication)); }
From source file:com.rockagen.gnext.service.spring.security.extension.BasicRequestAwareAuthenticationSuccessHandler.java
/** * Handler locked.//from w ww . j a va 2 s. c om * * @param userId * the user id */ protected void handlerLocked(Authentication authentication) { String latestIp = ((BasicWebAuthenticationDetails) authentication.getDetails()).getRemoteAddress(); String username = ((UserDetails) authentication.getPrincipal()).getUsername(); AuthUser user = authUserServ.load(username); // error count clean user.setErrorCount(0); user.setStateTime(new Date()); user.setLatestIp(latestIp); authUserServ.add(user); }
From source file:com.amediamanager.controller.AllControllers.java
@ModelAttribute("user") public User populateUser() { SecurityContext context = SecurityContextHolder.getContext(); if (context == null) { return null; }// w w w . j a v a 2 s . c o m Authentication auth = context.getAuthentication(); if (auth == null) { return null; } Object user = auth.getDetails(); return (user != null && user instanceof User) ? (User) user : null; }
From source file:org.apache.cxf.fediz.service.idp.beans.CacheTokenForWauthAction.java
public void submit(RequestContext context) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Assert.isInstanceOf(STSUserDetails.class, auth.getDetails()); final STSUserDetails stsUserDetails = (STSUserDetails) auth.getDetails(); SecurityToken securityToken = stsUserDetails.getSecurityToken(); Idp idpConfig = (Idp) WebUtils.getAttributeFromFlowScope(context, IDP_CONFIG); WebUtils.putAttributeInExternalContext(context, idpConfig.getRealm(), securityToken); LOG.info("Token [IDP_TOKEN=" + securityToken.getId() + "] for realm [" + idpConfig.getRealm() + "] successfully cached."); }
From source file:org.ngrinder.security.NGrinderAuthenticationPreAuthProvider.java
/** * Authenticate the given PreAuthenticatedAuthenticationToken. * // ww w . j a va 2s .c o m * If the principal contained in the authentication object is null, the request will be ignored to allow other * providers to authenticate it. * * @param authentication * authentication * @return authorized {@link Authentication} */ @SuppressWarnings("unchecked") @Override public Authentication authenticate(Authentication authentication) { Object details = authentication.getDetails(); Authentication authenticate = super.authenticate(authentication); SecuredUser securedUser = (SecuredUser) authenticate.getPrincipal(); if (details instanceof HashMap) { securedUser.getUser().setTimeZone(((HashMap<String, String>) details).get("user_timezone")); securedUser.getUser().setUserLanguage(((HashMap<String, String>) details).get("user_language")); } else if (details instanceof LanguageAndTimezone) { LanguageAndTimezone languageAndTimeZone = ((LanguageAndTimezone) details); securedUser.getUser().setTimeZone(languageAndTimeZone.getTimezone()); securedUser.getUser().setUserLanguage(languageAndTimeZone.getLanguage()); } // If It's the first time to login // means.. If the user info provider is not defaultLoginPlugin.. if (securedUser.getUser().getId() == null) { addNewUserIntoLocal(securedUser); } return authenticate; }
From source file:net.paulgray.bbrest.security.CourseFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain fc) throws IOException, ServletException { Logger.getLogger(CourseFilter.class.getName()).log(Level.INFO, "Calling Course Filter..."); String url = ((HttpServletRequest) request).getRequestURL().toString(); String course = getCourseIdFromUrl(url); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); User user = (User) authentication.getDetails(); Id userId = BlackboardUtilities.getIdFromPk(user.getId(), blackboard.data.user.User.class); Id courseId = BlackboardUtilities.getIdFromPk(course, blackboard.data.course.Course.class); if (!SecurityUtil.userHasEntitlement(userId, courseId, new Entitlement("course.VIEW"))) { throw new AccessDeniedException( "Context user: '" + user.getUsername() + "' does not have access to view course: " + courseId); }//from w w w . j a va 2 s . c om }
From source file:fr.esiea.windmeal.service.security.SecurityService.java
public User getUserConnected() throws DaoException, NotPermitException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); User userAuthenticate = userDao.getOne(authentication.getDetails().toString()); if (null == userAuthenticate) throw new NotPermitException(); return userAuthenticate; }
From source file:org.carewebframework.security.spring.AuthenticationScope.java
@Override protected ScopeContainer getContainer() { Authentication auth = AbstractSecurityService.getAuthentication(); CWFAuthenticationDetails details = auth == null ? null : (CWFAuthenticationDetails) auth.getDetails(); ScopeContainer container = null;/* ww w . j a v a2s.c o m*/ if (details != null) { container = (ScopeContainer) details.getDetail(KEY_SCOPE); if (container == null) { container = new ScopeContainer(); details.setDetail(KEY_SCOPE, container); } } return container; }
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 ww. j a va2 s . c o m*/ for (AccessParameters accessParameter : accessParameters) { accessParametersRepo.delete(accessParameter); } }