Example usage for org.springframework.security.oauth.common OAuthException OAuthException

List of usage examples for org.springframework.security.oauth.common OAuthException OAuthException

Introduction

In this page you can find the example usage for org.springframework.security.oauth.common OAuthException OAuthException.

Prototype

public OAuthException(String message) 

Source Link

Usage

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;/*from   w  ww . j ava2 s. c  om*/
    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 {
        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:ltistarter.oauth.MyConsumerDetailsService.java

@Override
public ConsumerDetails loadConsumerByConsumerKey(String consumerKey) throws OAuthException {
    BaseConsumerDetails cd;//from  ww w  .  j a  va2s. c o  m
    // 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);
        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:nl.surfnet.coin.api.service.JanusClientDetailsService.java

/**
 * {@inheritDoc}/*w w w.  jav a2  s.  c o  m*/
 */
@Override
@Cacheable(value = { "janus-meta-data" })
public ConsumerDetails loadConsumerByConsumerKey(String consumerKey) throws OAuthException {
    EntityMetadata metadata = getJanusMetadataByConsumerKey(consumerKey,
            new OAuthException(OAuth2Exception.INVALID_CLIENT));
    validateMetadata(consumerKey, metadata);
    final OpenConextConsumerDetails consumerDetails = new OpenConextConsumerDetails();
    consumerDetails.setConsumerKey(consumerKey);
    consumerDetails.setAuthorities(Arrays.<GrantedAuthority>asList(new SimpleGrantedAuthority("ROLE_USER")));
    ClientMetaData clientMetaData = new JanusClientMetadata(metadata);
    consumerDetails.setClientMetaData(clientMetaData);
    ClientMetaDataHolder.setClientMetaData(clientMetaData);

    consumerDetails.setSignatureSecret(new SharedConsumerSecretImpl(metadata.getOauthConsumerSecret()));

    // set to required by default
    consumerDetails.setRequiredToObtainAuthenticatedToken(true);
    if (metadata.isTwoLeggedOauthAllowed()) {
        // two legged allowed
        consumerDetails.setRequiredToObtainAuthenticatedToken(false);
    }

    return consumerDetails;
}

From source file:org.eurekastreams.server.service.security.oauth.ConsumerDetailsServiceImpl.java

/**
 * {@inheritDoc}/*from www .jav  a 2 s.c o m*/
 */
@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.");
    }
}