List of usage examples for org.springframework.security.core Authentication getDetails
Object getDetails();
From source file:com.rockagen.gnext.service.spring.aspect.OpLogAspect.java
/** * Get ip address//from w w w . ja v a 2s . c o m * @return ip */ private String getIp() { String ip = "0.0.0.0"; Authentication auth = getAuthentication(); if (auth != null) { return ((ExWebAuthenticationDetails) auth.getDetails()).getRemoteAddress(); } return ip; }
From source file:org.carewebframework.security.spring.AbstractAuthenticationProvider.java
/** * Authentication Provider. Produces a trusted <code>UsernamePasswordAuthenticationToken</code> * if//w w w . j a va 2 s . c o m * * @param authentication The authentication context. * @return authentication Authentication object if authentication succeeded. Null if not. */ @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { CWFAuthenticationDetails details = (CWFAuthenticationDetails) authentication.getDetails(); String username = (String) authentication.getPrincipal(); String password = (String) authentication.getCredentials(); String domain = null; if (log.isDebugEnabled()) { log.debug("User: " + username); log.debug("Details, RA: " + details == null ? "null" : details.getRemoteAddress()); } if (username != null) { String pcs[] = username.split("\\\\", 2); domain = pcs[0]; username = pcs.length > 1 ? pcs[1] : null; } ISecurityDomain securityDomain = domain == null ? null : SecurityUtil.getSecurityService().getSecurityDomain(domain); if (username == null || password == null || securityDomain == null) { throw new BadCredentialsException("Missing security credentials."); } IUser user = authenticate(username, password, securityDomain, details); details.setDetail("user", user); List<GrantedAuthority> userAuthorities = new ArrayList<GrantedAuthority>(); List<String> list = getAuthorities(user); Set<String> authorities = list == null ? new HashSet<String>() : new HashSet<String>(list); for (String grantedAuthority : grantedAuthorities) { if (grantedAuthority.startsWith("-")) { authorities.remove(grantedAuthority.substring(1)); } else { authorities.add(grantedAuthority); } } for (String authority : authorities) { if (!authority.isEmpty()) { userAuthorities.add(new SimpleGrantedAuthority(authority)); } } User principal = new User(username, password, true, true, true, true, userAuthorities); authentication = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), principal.getAuthorities()); ((UsernamePasswordAuthenticationToken) authentication).setDetails(details); return authentication; }
From source file:io.curly.commons.github.GitHubAuthenticationMethodHandler.java
@SuppressWarnings("unchecked") private User from(OAuth2Authentication auth) { Authentication userAuthentication = auth.getUserAuthentication(); if (userAuthentication != null) { try {//from ww w. j a va 2s .c o m LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>) userAuthentication.getDetails(); return User.builder().id(String.valueOf(map.get("id"))) .avatarUrl(String.valueOf(map.get("avatar_url"))).email(String.valueOf(map.get("email"))) .name(String.valueOf(map.get("name"))).type(String.valueOf(map.get("type"))) .username(String.valueOf(map.get("login"))).build(); } catch (ClassCastException e) { log.error("Cannot build User due to a ClassCastException {}", e); } } log.debug("Returning no user due to previous errors or no UserAuthentication detected"); return null; }
From source file:curly.commons.github.GitHubAuthenticationMethodHandler.java
@SuppressWarnings("unchecked") private OctoUser from(OAuth2Authentication auth) { Authentication userAuthentication = auth.getUserAuthentication(); if (userAuthentication != null) { try {//w w w . ja va 2 s .co m LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>) userAuthentication.getDetails(); return new OctoUser(String.valueOf(map.get("email")), Boolean.valueOf(String.valueOf(map.get("hireable"))), Long.valueOf(String.valueOf(map.get("id"))), Integer.valueOf(String.valueOf(map.get("followers"))), Integer.valueOf(String.valueOf(map.get("following"))), Integer.valueOf(String.valueOf(map.get("public_repos"))), String.valueOf(map.get("avatar_url")), String.valueOf(map.get("blog")), String.valueOf(map.get("company")), null, String.valueOf(map.get("html_url")), null, String.valueOf(map.get("login")), String.valueOf(map.get("name")), String.valueOf(map.get("type")), String.valueOf(map.get("url"))); } catch (ClassCastException e) { log.error("Cannot build OctoUser due to a ClassCastException {}", e); } } log.debug("Returning no user due to previous errors or no UserAuthentication detected"); return null; }
From source file:com.springsource.greenhouse.account.UsernamePasswordAuthenticationProvider.java
private Authentication authenticatedToken(Account account, Authentication original) { List<GrantedAuthority> authorities = null; UsernamePasswordAuthenticationToken authenticated = new UsernamePasswordAuthenticationToken(account, null, authorities);//from w w w. j ava 2 s. c o m authenticated.setDetails(original.getDetails()); return authenticated; }
From source file:org.jasig.portlet.blackboardvcportlet.security.ConferenceUserPreAuthenticatedGrantedAuthoritiesUserDetailsService.java
@Override protected UserDetails createuserDetails(Authentication token, Collection<? extends GrantedAuthority> authorities) { final PortletAuthenticationDetails authenticationDetails = (PortletAuthenticationDetails) token .getDetails();//from ww w .jav a2s . co m final ConferenceUser conferenceUser = this.setupConferenceUser(authenticationDetails); return new ConferenceSecurityUser(token.getName(), conferenceUser, authorities); }
From source file:org.openmrs.contrib.metadatarepository.service.UserSecurityAdvice.java
private User getCurrentUser(Authentication auth) { User currentUser;/*ww w . j a va2 s.co m*/ if (auth.getPrincipal() instanceof UserDetails) { currentUser = (User) auth.getPrincipal(); } else if (auth.getDetails() instanceof UserDetails) { currentUser = (User) auth.getDetails(); } else { throw new AccessDeniedException("User not properly authenticated."); } return currentUser; }
From source file:com.gfactor.web.wicket.context.ProviderManager.java
/** * Copies the authentication details from a source Authentication object to a destination one, provided the * latter does not already have one set. * * @param source source authentication//from www.ja v a 2s. c o m * @param dest the destination authentication object */ private void copyDetails(Authentication source, Authentication dest) { if ((dest instanceof AbstractAuthenticationToken) && (dest.getDetails() == null)) { AbstractAuthenticationToken token = (AbstractAuthenticationToken) dest; token.setDetails(source.getDetails()); } }
From source file:org.xaloon.wicket.security.spring.SpringSecurityFacade.java
@SuppressWarnings("unchecked") @Override/* www .ja v a2 s . c o m*/ public <T extends User> T getCurrentUser() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication.getDetails() == null) { return null; } if (authentication.getDetails() instanceof User) { return (T) authentication.getDetails(); } return null; }
From source file:at.ac.univie.isc.asio.security.HttpMethodRestrictionFilterTest.java
@Test public void should_keep_anonymous_type() throws Exception { final AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key", "principal", Collections.<GrantedAuthority>singletonList(Permission.INVOKE_UPDATE)); token.setDetails("details"); setAuthentication(token);//ww w. j a v a2 s . c o m request.setMethod(HttpMethod.GET.name()); subject.doFilter(request, response, chain); final Authentication filtered = getAuthentication(); assertThat(filtered, instanceOf(AnonymousAuthenticationToken.class)); assertThat(filtered.getPrincipal(), equalTo(token.getPrincipal())); assertThat(filtered.getDetails(), equalTo(token.getDetails())); }