List of usage examples for org.springframework.security.openid OpenIDAttribute getType
public String getType()
From source file:org.mitre.provenance.openid.OpenId4JavaProxyConsumer.java
public String beginConsumption(HttpServletRequest req, String identityUrl, String returnToUrl, String realm) throws OpenIDConsumerException { List<DiscoveryInformation> discoveries; try {/* w w w.j av a 2s. co m*/ discoveries = consumerManager.discover(identityUrl); } catch (DiscoveryException e) { throw new OpenIDConsumerException("Error during discovery", e); } DiscoveryInformation information = consumerManager.associate(discoveries); req.getSession().setAttribute(DISCOVERY_INFO_KEY, information); AuthRequest authReq; try { authReq = consumerManager.authenticate(information, returnToUrl, realm); logger.debug("Looking up attribute fetch list for identifier: " + identityUrl); List<OpenIDAttribute> attributesToFetch = attributesToFetchFactory.createAttributeList(identityUrl); if (!attributesToFetch.isEmpty()) { req.getSession().setAttribute(ATTRIBUTE_LIST_KEY, attributesToFetch); FetchRequest fetchRequest = FetchRequest.createFetchRequest(); for (OpenIDAttribute attr : attributesToFetch) { if (logger.isDebugEnabled()) { logger.debug("Adding attribute " + attr.getType() + " to fetch request"); } fetchRequest.addAttribute(attr.getName(), attr.getType(), attr.isRequired(), attr.getCount()); } authReq.addExtension(fetchRequest); } } catch (MessageException e) { throw new OpenIDConsumerException("Error processing ConsumerManager authentication", e); } catch (ConsumerException e) { throw new OpenIDConsumerException("Error processing ConsumerManager authentication", e); } return authReq.getDestinationUrl(true); }
From source file:org.mitre.provenance.openid.OpenId4JavaProxyConsumer.java
List<OpenIDAttribute> fetchAxAttributes(Message authSuccess, List<OpenIDAttribute> attributesToFetch) throws OpenIDConsumerException { if (attributesToFetch == null || !authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) { return Collections.emptyList(); }/*from www .j ava 2 s . c om*/ logger.debug("Extracting attributes retrieved by attribute exchange"); List<OpenIDAttribute> attributes = Collections.emptyList(); try { MessageExtension ext = authSuccess.getExtension(AxMessage.OPENID_NS_AX); if (ext instanceof FetchResponse) { FetchResponse fetchResp = (FetchResponse) ext; attributes = new ArrayList<OpenIDAttribute>(attributesToFetch.size()); for (OpenIDAttribute attr : attributesToFetch) { List<String> values = fetchResp.getAttributeValues(attr.getName()); if (!values.isEmpty()) { OpenIDAttribute fetched = new OpenIDAttribute(attr.getName(), attr.getType(), values); fetched.setRequired(attr.isRequired()); attributes.add(fetched); } } } } catch (MessageException e) { throw new OpenIDConsumerException("Attribute retrieval failed", e); } if (logger.isDebugEnabled()) { logger.debug("Retrieved attributes" + attributes); } return attributes; }
From source file:org.mitre.provenance.openid.OpenIDInterceptorFilter.java
/** * Handle turning an OpenID (2) token into a user. *//*from ww w .j a v a 2s. c o m*/ protected User handle(OpenIDAuthenticationToken oidToken) { String oid2UniqueId = oidToken.getName(); System.err.println("FILTER: OpenID2 Token ID " + oid2UniqueId + " cred " + oidToken.getCredentials() + " details " + oidToken.getDetails() + " principal " + oidToken.getPrincipal() + " message " + oidToken.getMessage()); User existingUser = null; try { PLUSActor a = Neo4JPLUSObjectFactory.getActor(oid2UniqueId); if (a instanceof User) existingUser = (User) a; } catch (PLUSException exc) { log.severe("Could not load actor by ID " + oid2UniqueId); exc.printStackTrace(); } if (existingUser != null) { // System.err.println("FILTER: OpenID2 existing user " + existingUser); return existingUser; } else { List<OpenIDAttribute> attributes = oidToken.getAttributes(); System.err.println("FILTER: OpenID2 new user with " + attributes.size() + " attributes."); String oid2DisplayName = null; String oid2FirstName = null; String oid2LastName = null; String email = null; for (OpenIDAttribute attr : attributes) { String attrName = attr.getName(); StringBuffer vals = new StringBuffer(""); for (String val : attr.getValues()) vals.append(val + "/"); System.err.println("OPEN ID ATTRIBUTE: " + attrName + " type " + attr.getType() + " vals " + vals); if (attrName.equals("name")) { //This is the OpenID 2.0 display name. //OpenID 2.0 Attribute Exchange (AX) is a little finicky, so this value //may not be populated or may be stored uner a different attribute name. oid2DisplayName = attr.getValues().get(0); } else if (attrName.equals("firstName")) { oid2FirstName = attr.getValues().get(0); } else if (attrName.equals("lastName")) { oid2LastName = attr.getValues().get(0); } else if (attrName.equals("email")) { email = attr.getValues().get(0); } } if (oid2DisplayName == null) { // Google sends first and last rather than "name" oid2DisplayName = oid2FirstName + oid2LastName; } OpenIDUser oid2User = new OpenIDUser(oid2UniqueId, (oid2DisplayName != null) ? oid2DisplayName : "Name Not Provided"); oid2User.setEmail(email); // TODO: Remove oid2User.addPrivilege(PrivilegeClass.ADMIN); oid2User.addPrivilege(PrivilegeClass.PUBLIC); try { if (client.actorExists(oid2User.getId()) == null) client.report(ProvenanceCollection.collect(oid2User)); } catch (PLUSException exc) { log.severe("Could not save new user entry " + oid2User); exc.printStackTrace(); } System.err.println("FILTER: set new OpenID2 user " + oid2User); return oid2User; } }
From source file:org.springframework.security.openid.OpenID4JavaConsumer.java
List<OpenIDAttribute> fetchAxAttributes(Message authSuccess, List<OpenIDAttribute> attributesToFetch) throws OpenIDConsumerException { if (attributesToFetch == null || !authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) { return Collections.emptyList(); }// w ww .ja v a 2s . c o m logger.debug("Extracting attributes retrieved by attribute exchange"); List<OpenIDAttribute> attributes = Collections.emptyList(); try { MessageExtension ext = authSuccess.getExtension(AxMessage.OPENID_NS_AX); if (ext instanceof FetchResponse) { FetchResponse fetchResp = (FetchResponse) ext; attributes = new ArrayList<>(attributesToFetch.size()); for (OpenIDAttribute attr : attributesToFetch) { List<String> values = fetchResp.getAttributeValues(attr.getName()); if (!values.isEmpty()) { OpenIDAttribute fetched = new OpenIDAttribute(attr.getName(), attr.getType(), values); fetched.setRequired(attr.isRequired()); attributes.add(fetched); } } } } catch (MessageException e) { throw new OpenIDConsumerException("Attribute retrieval failed", e); } if (logger.isDebugEnabled()) { logger.debug("Retrieved attributes" + attributes); } return attributes; }