Tidied up a bit, added javadoc comments to new classes

pull/210/head
Amanda Anganes 2012-08-23 11:05:10 -04:00
parent c23b176567
commit ba5572b28a
4 changed files with 49 additions and 8 deletions

View File

@ -16,6 +16,7 @@ import org.springframework.security.oauth2.provider.code.AuthorizationRequestHol
/** /**
* Entity class for authorization codes * Entity class for authorization codes
*
* @author aanganes * @author aanganes
* *
*/ */
@ -40,9 +41,10 @@ public class AuthorizationCodeEntity {
} }
/** /**
* Create a new AuthorizationCodeEntity with the given code. * Create a new AuthorizationCodeEntity with the given code and AuthorizationRequestHolder.
* *
* @param code the authorization code * @param code the authorization code
* @param authRequest the AuthoriztionRequestHolder associated with the original code request
*/ */
public AuthorizationCodeEntity(String code, AuthorizationRequestHolder authRequest) { public AuthorizationCodeEntity(String code, AuthorizationRequestHolder authRequest) {
this.code = code; this.code = code;

View File

@ -5,12 +5,28 @@ import org.springframework.security.oauth2.common.exceptions.InvalidGrantExcepti
import org.springframework.security.oauth2.provider.code.AuthorizationRequestHolder; import org.springframework.security.oauth2.provider.code.AuthorizationRequestHolder;
/** /**
* @author amanda * Interface for saving and consuming OAuth2 authorization codes as AuthorizationCodeEntitys.
*
* @author aanganes
* *
*/ */
public interface AuthorizationCodeRepository { public interface AuthorizationCodeRepository {
/**
* Save an AuthorizationCodeEntity to the repository
*
* @param authorizationCode the AuthorizationCodeEntity to save
* @return the saved AuthorizationCodeEntity
*/
public AuthorizationCodeEntity save(AuthorizationCodeEntity authorizationCode); public AuthorizationCodeEntity save(AuthorizationCodeEntity authorizationCode);
/**
* Consume an authorization code.
*
* @param code the authorization code value
* @return the authentication associated with the code
* @throws InvalidGrantException if no AuthorizationCodeEntity is found with the given value
*/
public AuthorizationRequestHolder consume(String code) throws InvalidGrantException; public AuthorizationRequestHolder consume(String code) throws InvalidGrantException;
} }

View File

@ -16,6 +16,8 @@ import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
* JPA AuthorizationCodeRepository implementation.
*
* @author aanganes * @author aanganes
* *
*/ */
@ -54,7 +56,8 @@ public class JpaAuthorizationCodeRepository implements AuthorizationCodeReposito
} }
AuthorizationRequestHolder authRequest = result.getAuthorizationRequestHolder(); AuthorizationRequestHolder authRequest = result.getAuthorizationRequestHolder();
//authRequest.getAuthenticationRequest();
manager.remove(result);
return authRequest; return authRequest;

View File

@ -13,6 +13,8 @@ import org.springframework.security.oauth2.provider.code.AuthorizationRequestHol
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* Database-backed, random-value authorization code service implementation.
*
* @author aanganes * @author aanganes
* *
*/ */
@ -24,8 +26,13 @@ public class DefaultOAuth2AuthorizationCodeService implements AuthorizationCodeS
private RandomValueStringGenerator generator = new RandomValueStringGenerator(); private RandomValueStringGenerator generator = new RandomValueStringGenerator();
/* (non-Javadoc) /**
* @see org.springframework.security.oauth2.provider.code.AuthorizationCodeServices#createAuthorizationCode(org.springframework.security.oauth2.provider.code.AuthorizationRequestHolder) * Generate a random authorization code and create an AuthorizationCodeEntity,
* which will be stored in the repository.
*
* @param authentication the authentication of the current user, to be retrieved when the
* code is consumed
* @return the authorization code
*/ */
@Override @Override
public String createAuthorizationCode(AuthorizationRequestHolder authentication) { public String createAuthorizationCode(AuthorizationRequestHolder authentication) {
@ -37,8 +44,15 @@ public class DefaultOAuth2AuthorizationCodeService implements AuthorizationCodeS
return code; return code;
} }
/* (non-Javadoc) /**
* @see org.springframework.security.oauth2.provider.code.AuthorizationCodeServices#consumeAuthorizationCode(java.lang.String) * Consume a given authorization code.
* Match the provided string to an AuthorizationCodeEntity. If one is found, return
* the authentication associated with the code. If one is not found, throw an
* InvalidGrantException.
*
* @param code the authorization code
* @return the authentication that made the original request
* @throws InvalidGrantException, if an AuthorizationCodeEntity is not found with the given value
*/ */
@Override @Override
public AuthorizationRequestHolder consumeAuthorizationCode(String code) throws InvalidGrantException { public AuthorizationRequestHolder consumeAuthorizationCode(String code) throws InvalidGrantException {
@ -47,10 +61,16 @@ public class DefaultOAuth2AuthorizationCodeService implements AuthorizationCodeS
return auth; return auth;
} }
/**
* @return the repository
*/
public AuthorizationCodeRepository getRepository() { public AuthorizationCodeRepository getRepository() {
return repository; return repository;
} }
/**
* @param repository the repository to set
*/
public void setRepository(AuthorizationCodeRepository repository) { public void setRepository(AuthorizationCodeRepository repository) {
this.repository = repository; this.repository = repository;
} }