Package org.springframework.security.oauth2.provider

Examples of org.springframework.security.oauth2.provider.ClientDetailsService


  @Override
  public AuthorizationRequest updateAfterApproval(AuthorizationRequest authorizationRequest, Authentication userAuthentication) {

    String userId = userAuthentication.getName();
    String clientId = authorizationRequest.getClientId();
    ClientDetails client = clientDetailsService.loadClientByClientId(clientId);

    // This must be re-parsed here because SECOAUTH forces us to call things in a strange order
    if (Boolean.parseBoolean(authorizationRequest.getApprovalParameters().get("user_oauth_approval"))
        && authorizationRequest.getExtensions().get("csrf") != null
        && authorizationRequest.getExtensions().get("csrf").equals(authorizationRequest.getApprovalParameters().get("csrf"))) {

      authorizationRequest.setApproved(true);

      // process scopes from user input
      Set<String> allowedScopes = Sets.newHashSet();
      Map<String,String> approvalParams = authorizationRequest.getApprovalParameters();

      Set<String> keys = approvalParams.keySet();

      for (String key : keys) {
        if (key.startsWith("scope_")) {
          //This is a scope parameter from the approval page. The value sent back should
          //be the scope string. Check to make sure it is contained in the client's
          //registered allowed scopes.

          String scope = approvalParams.get(key);
          Set<String> approveSet = Sets.newHashSet(scope);

          //Make sure this scope is allowed for the given client
          if (systemScopes.scopesMatch(client.getScope(), approveSet)) {

            // If it's structured, assign the user-specified parameter
            SystemScope systemScope = systemScopes.getByValue(scope);
            if (systemScope != null && systemScope.isStructured()){
              String paramValue = approvalParams.get("scopeparam_" + scope);
View Full Code Here


  @Test
  public void testDifferentRefreshTokenMaintainsState() throws Exception {
    // create access token
    getTokenServices().setAccessTokenValiditySeconds(1);
    getTokenServices().setClientDetailsService(new ClientDetailsService() {
      public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
        BaseClientDetails client = new BaseClientDetails();
        client.setAccessTokenValiditySeconds(1);
        client.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "refresh_token"));
        return client;
View Full Code Here

  @Test
  public void testNoRefreshTokenIfNotAuthorized() throws Exception {
    // create access token
    getTokenServices().setAccessTokenValiditySeconds(1);
    getTokenServices().setClientDetailsService(new ClientDetailsService() {
      public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
        BaseClientDetails client = new BaseClientDetails();
        client.setAccessTokenValiditySeconds(1);
        client.setAuthorizedGrantTypes(Arrays.asList("authorization_code"));
        return client;
View Full Code Here

  }

  @Test
  public void testClientSpecificRefreshTokenExpiry() throws Exception {
    getTokenServices().setRefreshTokenValiditySeconds(1000);
    getTokenServices().setClientDetailsService(new ClientDetailsService() {
      public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
        BaseClientDetails client = new BaseClientDetails();
        client.setRefreshTokenValiditySeconds(100);
        client.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "refresh_token"));
        return client;
View Full Code Here

  }

  @Test(expected = InvalidTokenException.class)
  public void testClientInvalidated() throws Exception {
    final AtomicBoolean deleted = new AtomicBoolean();
    getTokenServices().setClientDetailsService(new ClientDetailsService() {
      public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
        if (deleted.get()) {
          throw new ClientRegistrationException("No such client: " + clientId);
        }
        BaseClientDetails client = new BaseClientDetails();
View Full Code Here

  }

  @Test
  public void testClientSpecificTokenExpiry() throws Exception {
    getTokenServices().setAccessTokenValiditySeconds(1000);
    getTokenServices().setClientDetailsService(new ClientDetailsService() {
      public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
        BaseClientDetails client = new BaseClientDetails();
        client.setAccessTokenValiditySeconds(100);
        return client;
      }
View Full Code Here

  @Before
  public void init() throws Exception {
    client = new BaseClientDetails();
    client.setRegisteredRedirectUri(Collections.singleton("http://anywhere.com"));
    client.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "implicit"));
    endpoint.setClientDetailsService(new ClientDetailsService() {
      public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
        return client;
      }
    });
    endpoint.setTokenGranter(new TokenGranter() {
View Full Code Here

    return requestValidator;
  }

  private TokenGranter tokenGranter() {
    if (tokenGranter == null) {
      ClientDetailsService clientDetails = clientDetailsService();
      AuthorizationServerTokenServices tokenServices = tokenServices();
      AuthorizationCodeServices authorizationCodeServices = authorizationCodeServices();
      OAuth2RequestFactory requestFactory = requestFactory();

      List<TokenGranter> tokenGranters = new ArrayList<TokenGranter>();
View Full Code Here

        return consumerTokenServices;
    }

    private TokenGranter tokenGranter(HttpSecurity http) throws Exception {
        if(tokenGranter == null) {
            ClientDetailsService clientDetails = clientDetails();
            AuthorizationServerTokenServices tokenServices = tokenServices(http);
            AuthorizationCodeServices authorizationCodeServices = authorizationCodeServices(http);
            AuthenticationManager authenticationManager = authenticationManager(http);

            List<TokenGranter> tokenGranters = new ArrayList<TokenGranter>();
View Full Code Here

        DBObject userAuthorization = (DBObject)source.get("userAuthentication");
        Object principal = getPrincipalObject(userAuthorization.get("principal"));
        Authentication userAuthentication = new UsernamePasswordAuthenticationToken(principal,
                userAuthorization.get("credentials"), getAuthorities((List) userAuthorization.get("authorities")));

        return new OAuth2Authentication(oAuth2Request,  userAuthentication );
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.oauth2.provider.ClientDetailsService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.