List of usage examples for org.springframework.security.oauth.provider BaseConsumerDetails setConsumerName
public void setConsumerName(String consumerName)
From source file:ltistarter.oauth.MyConsumerDetailsService.java
@Override public ConsumerDetails loadConsumerByConsumerKey(String consumerKey) throws OAuthException { BaseConsumerDetails cd; // NOTE: really lookup the key and secret, for the sample here we just hardcoded if ("key".equals(consumerKey)) { // allow this oauth request cd = new BaseConsumerDetails(); cd.setConsumerKey(consumerKey);//from w ww .ja v a 2s.com cd.setSignatureSecret(new SharedConsumerSecretImpl("secret")); cd.setConsumerName("Sample"); cd.setRequiredToObtainAuthenticatedToken(false); // no token required (0-legged) cd.getAuthorities().add(new SimpleGrantedAuthority("ROLE_OAUTH")); // add the ROLE_OAUTH (can add others as well) log.info("OAuth check SUCCESS, consumer key: " + consumerKey); } else { // deny - failed to match throw new OAuthException("For this example, key must be 'key'"); } return cd; }
From source file:ltistarter.lti.LTIConsumerDetailsService.java
@Override public ConsumerDetails loadConsumerByConsumerKey(String consumerKey) throws OAuthException { consumerKey = StringUtils.trimToNull(consumerKey); assert StringUtils.isNotEmpty(consumerKey) : "consumerKey must be set and not null"; BaseConsumerDetails cd; LtiKeyEntity ltiKey = ltiKeyRepository.findByKeyKey(consumerKey); if (ltiKey == null) { // no matching key found throw new OAuthException("No matching lti key record was found for " + consumerKey); } else {/*from www .j a va2s . c om*/ cd = new BaseConsumerDetails(); cd.setConsumerKey(consumerKey); cd.setSignatureSecret(new SharedConsumerSecretImpl(ltiKey.getSecret())); cd.setConsumerName(String.valueOf(ltiKey.getKeyId())); cd.setRequiredToObtainAuthenticatedToken(false); // no token required (0-legged) cd.getAuthorities().add(new SimpleGrantedAuthority("ROLE_OAUTH")); // add the ROLE_OAUTH (can add others as well) cd.getAuthorities().add(new SimpleGrantedAuthority("ROLE_LTI")); log.info("LTI check SUCCESS, consumer key: " + consumerKey); } return cd; }
From source file:org.eurekastreams.server.service.security.oauth.ConsumerDetailsServiceImpl.java
/** * {@inheritDoc}/*from w w w.j a v a2s. c om*/ */ @Override public ConsumerDetails loadConsumerByConsumerKey(final String inConsumerKey) throws OAuthException { try { ServiceActionContext currentContext = new ServiceActionContext(inConsumerKey, null); OAuthConsumer consumer = (OAuthConsumer) actionController.execute(currentContext, getOAuthConsumerByConsumerKeyAction); BaseConsumerDetails details = new BaseConsumerDetails(); details.setConsumerKey(inConsumerKey); details.setConsumerName(inConsumerKey); details.setSignatureSecret(new SharedConsumerSecret(consumer.consumerSecret)); details.setAuthorities(grantedAuthorities); // NOTE: This line supports OAuth 2-legged only! details.setRequiredToObtainAuthenticatedToken(false); return details; } catch (Exception ex) { log.error("Error occurred retrieving consumer with provided key.", ex); throw new OAuthException("Unable to retrieve consumer with provided information."); } }