List of usage examples for org.springframework.security.openid OpenIDAttribute getName
public String getName()
From source file:info.gewton.openid.servlet.OpenIDLoginServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { SecurityContext sc = (SecurityContext) request.getSession().getAttribute("SPRING_SECURITY_CONTEXT"); OpenIDAuthenticationToken auth = (OpenIDAuthenticationToken) sc.getAuthentication(); List<OpenIDAttribute> attributes = auth.getAttributes(); for (OpenIDAttribute a : attributes) { if (a.getName().equals("namePerson")) { request.getSession().setAttribute("namePerson", a.getValues().get(0)); break; }// w w w . j a v a 2s . co m } response.sendRedirect(request.getContextPath() + "/index.jsp"); }
From source file:ar.edu.fesf.security.OpenIDAttributes2UserDetailsImpl.java
/** * {@inheritDoc}/* w w w . j a va 2 s .c om*/ */ @Override public UserDetails extract(final OpenIDAuthenticationToken token) { String email = ""; String firstName = ""; String lastName = ""; String language = ""; List<OpenIDAttribute> attributes = token.getAttributes(); for (OpenIDAttribute openIDAttribute : attributes) { if (openIDAttribute.getName().equals("firstName")) { firstName = StringUtils.join(openIDAttribute.getValues(), ""); } if (openIDAttribute.getName().equals("email")) { email = StringUtils.join(openIDAttribute.getValues(), ""); } if (openIDAttribute.getName().equals("lastName")) { lastName = StringUtils.join(openIDAttribute.getValues(), ""); } if (openIDAttribute.getName().equals("language")) { language = StringUtils.join(openIDAttribute.getValues(), ""); } } return new UserDetailsImpl(token.getIdentityUrl(), firstName, lastName, email, language); }
From source file:org.bisen.blog.service.OpenIDUserDetailsService.java
@Override public UserDetails loadUserDetails(OpenIDAuthenticationToken token) throws UsernameNotFoundException { List<OpenIDAttribute> attributes = token.getAttributes(); String email = null;//from w ww.ja v a2 s . c o m for (OpenIDAttribute attribute : attributes) { if (attribute.getName().equals("email")) { email = attribute.getValues().get(0); } } if (email == null) { throw new UsernameNotFoundException("User not registered"); } else { BlogUser user = blogService.findUser(email); if (user == null) { throw new UsernameNotFoundException("User not registered"); } else { return new BlogUserDetails(email); } } }
From source file:it.av.youeat.web.security.OpenIDAttributes2UserDetailsImpl.java
/** * {@inheritDoc}//from www. j a v a 2 s. c om */ @Override public Eater extract(OpenIDAuthenticationToken token) { Eater user = new Eater(); List<OpenIDAttribute> attributes = token.getAttributes(); for (OpenIDAttribute openIDAttribute : attributes) { if (openIDAttribute.getName().equals("firstName")) { user.setFirstname(StringUtils.join(openIDAttribute.getValues(), "")); } if (openIDAttribute.getName().equals("email")) { user.setEmail(StringUtils.join(openIDAttribute.getValues(), "")); } if (openIDAttribute.getName().equals("lastName")) { user.setLastname(StringUtils.join(openIDAttribute.getValues(), "")); } if (openIDAttribute.getName().equals("language")) { String langage = StringUtils.join(openIDAttribute.getValues(), ""); user.setLanguage(languageService.getSupportedLanguage(new Locale(langage))); } if (openIDAttribute.getName().equals("country")) { String country = StringUtils.join(openIDAttribute.getValues(), ""); user.setCountry(countryService.getByIso2(country)); } } if (user.getCountry() == null) { user.setCountry(countryService.getByIso2(user.getLanguage().getCountry())); //user.setLanguage(languageService.getSupportedLanguage(new Locale(user.getLocale()))); } user.setEmail(user.getEmail()); user.setSocialType(SocialType.GOOGLE); user.setSocialUID(token.getIdentityUrl()); return user; }
From source file:mx.edu.um.mateo.general.service.UserDetailsServiceImpl.java
@Override public UserDetails loadUserDetails(OpenIDAuthenticationToken token) throws UsernameNotFoundException { log.debug("loadUserDetails: {}", token); String username = token.getIdentityUrl(); String email = ""; Usuario usuario = usuarioDao.obtienePorOpenId(username); log.debug("Usuario encontrado : {}", usuario); if (usuario == null) { log.debug("Buscando atributo email"); List<OpenIDAttribute> attrs = token.getAttributes(); for (OpenIDAttribute attr : attrs) { log.debug("Attr: {}", attr.getName()); if (attr.getName().equals("email")) { email = attr.getValues().get(0); }/*w ww .j a va2 s . c o m*/ } log.debug("Buscando por email {}", email); usuario = usuarioDao.obtienePorCorreo(email); if (usuario == null) { throw new UsernameNotFoundException("No se encontro al usuario " + username); } usuario.setOpenId(username); usuarioDao.actualiza(usuario); } log.debug("Regresando usuario: {}", usuario); return (UserDetails) usuario; }
From source file:org.cloudfoundry.identity.uaa.openid2.OpenIdUserDetailsService.java
/** * Implementation of {@code AuthenticationUserDetailsService} which allows full access to the submitted * {@code Authentication} object. Used by the OpenIDAuthenticationProvider. *///ww w .j a v a 2 s .c om public UserDetails loadUserDetails(OpenIDAuthenticationToken token) { // String id = token.getIdentityUrl(); String email = null; String firstName = null; String lastName = null; String fullName = null; List<OpenIDAttribute> attributes = token.getAttributes(); for (OpenIDAttribute attribute : attributes) { if (attribute.getName().equals("email")) { email = attribute.getValues().get(0); } if (attribute.getName().equals("firstname")) { firstName = attribute.getValues().get(0); } if (attribute.getName().equals("lastname")) { lastName = attribute.getValues().get(0); } if (attribute.getName().equals("fullname")) { fullName = attribute.getValues().get(0); } } if (firstName == null && StringUtils.hasText(fullName)) { String[] names = fullName.split(" "); firstName = names[0]; } if (lastName == null && StringUtils.hasText(fullName)) { String[] names = fullName.split(" "); lastName = names.length > 1 ? names[1] : "User"; } if (firstName == null && StringUtils.hasText(email)) { String[] names = email.split("@"); firstName = names[0]; } if (lastName == null && StringUtils.hasText(email)) { String[] names = email.split("@"); lastName = names.length > 1 ? names[1] : "User"; } UaaUser user = new UaaUser(email, generator.generate(), email, firstName, lastName); return new UaaUserDetails(user); }
From source file:net.firejack.platform.web.security.spring.openid.OpenIDAuthenticationManager.java
private Map<SupportedOpenIDAttribute, String> findAttributeValues(List<OpenIDAttribute> attributes) { Map<SupportedOpenIDAttribute, String> values = new HashMap<SupportedOpenIDAttribute, String>(); for (OpenIDAttribute attribute : attributes) { String name = attribute.getName(); SupportedOpenIDAttribute supportedOpenIDAttribute = SupportedOpenIDAttribute .lookForSupportedAttribute(name); if (supportedOpenIDAttribute != null && attribute.getValues() != null && !attribute.getValues().isEmpty()) { String value = attribute.getValues().get(0); if (value != null) { values.put(supportedOpenIDAttribute, value); }// w ww. j a v a 2 s . c o m } } return values; }
From source file:com.erudika.para.security.SimpleUserService.java
/** * Loads a user from the data store or creates a new user from an OpenID profile * @param token the OpenID authentication token holding the user profile * @return a user object or null if user is not found *//*from w ww. j a v a2s. c om*/ public UserDetails loadUserDetails(OpenIDAuthenticationToken token) { if (token == null) { return null; } User user = new User(); user.setIdentifier(token.getIdentityUrl()); user = loadUser(user); if (user == null) { // create new OpenID user String email = "email@domain.com"; String firstName = null, lastName = null, fullName = null; List<OpenIDAttribute> attributes = token.getAttributes(); for (OpenIDAttribute attribute : attributes) { if (attribute.getName().equals("email")) { email = attribute.getValues().get(0); } if (attribute.getName().equals("firstname")) { firstName = attribute.getValues().get(0); } if (attribute.getName().equals("lastname")) { lastName = attribute.getValues().get(0); } if (attribute.getName().equals("fullname")) { fullName = attribute.getValues().get(0); } } if (fullName == null) { if (firstName == null) { firstName = "No"; } if (lastName == null) { lastName = "Name"; } fullName = firstName.concat(" ").concat(lastName); } user = new User(); user.setActive(true); user.setEmail(email); user.setName(fullName); user.setPassword(new UUID().toString()); user.setIdentifier(token.getIdentityUrl()); String id = user.create(); if (id == null) { throw new BadCredentialsException("Authentication failed: cannot create new user."); } } return user; }
From source file:com.wisemapping.security.UserDetailsService.java
@NotNull private User buildUserFromToken(@NotNull OpenIDAuthenticationToken token) { final User result = new User(); String lastName = null;//from w ww . ja v a2 s .c o m String firstName = null; String email = null; String fullName = null; final List<OpenIDAttribute> attributes = token.getAttributes(); for (OpenIDAttribute attribute : attributes) { if (attribute.getName().equals("email")) { email = attribute.getValues().get(0); } if (attribute.getName().equals("firstname")) { firstName = attribute.getValues().get(0); } if (attribute.getName().equals("lastname")) { lastName = attribute.getValues().get(0); } if (attribute.getName().equals("fullname")) { fullName = attribute.getValues().get(0); } } if (lastName == null || firstName == null) { result.setFirstname(fullName); result.setLastname(""); } else { result.setLastname(lastName); result.setFirstname(firstName); } result.setEmail(email); result.setPassword(""); final Calendar now = Calendar.getInstance(); result.setActivationDate(now); return result; }
From source file:net.firejack.platform.web.security.spring.openid.OpenIDAuthenticationManager.java
private String findAttributeValueByName(SupportedOpenIDAttribute searchOpenIDAttribute, List<OpenIDAttribute> attributes) { String value = null;//from www.j a v a 2s . co m for (OpenIDAttribute attribute : attributes) { if (searchOpenIDAttribute.getAttributeName().equals(attribute.getName())) { if (attribute.getValues() != null && !attribute.getValues().isEmpty()) { value = attribute.getValues().get(0); } break; } } return value; }