Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2006-2011 the original author or authors.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package org.springframework.security.oauth2.provider.authentication;
An org.springframework.security.authentication.AuthenticationManager for OAuth2 protected resources.

Author(s):
Dave Syer
	private String resourceId;
	public void setResourceId(String resourceId) {
		this. = resourceId;
	}

Parameters:
tokenServices the tokenServices to set
	public void setTokenServices(ResourceServerTokenServices tokenServices) {
		this. = tokenServices;
	}
	public void afterPropertiesSet() {
		Assert.state( != null"TokenServices are required");
	}

Expects the incoming authentication request to have a principal value that is an access token value (e.g. from an authorization header) .Loads an authentication from the org.springframework.security.oauth2.provider.token.ResourceServerTokenServices and checks that the resource id is contained in the org.springframework.security.oauth2.provider.AuthorizationRequest (if one is specified). Also copies authentication details over from the input to the output (e.g. typically so that the access token value and request details can be reported later).

		String token = (Stringauthentication.getPrincipal();
		if (auth == null) {
			throw new InvalidTokenException("Invalid token: " + token);
		}
		if ( != null && resourceIds != null && !resourceIds.isEmpty() && !resourceIds.contains()) {
			throw new OAuth2AccessDeniedException("Invalid token does not contain resource id (" +  + ")");
		}
		auth.setDetails(authentication.getDetails());
		return auth;
	}
New to GrepCode? Check out our FAQ X