Example usage for org.springframework.security.oauth.provider BaseConsumerDetails getAuthorities

List of usage examples for org.springframework.security.oauth.provider BaseConsumerDetails getAuthorities

Introduction

In this page you can find the example usage for org.springframework.security.oauth.provider BaseConsumerDetails getAuthorities.

Prototype

public List<GrantedAuthority> getAuthorities() 

Source Link

Document

The base authorities for this consumer.

Usage

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 2  s. c o  m
        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 .  ja  v a2s.  c o  m*/
        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;
}