Tidied up a bit, added javadoc comments to new classes
parent
c23b176567
commit
ba5572b28a
|
@ -16,6 +16,7 @@ import org.springframework.security.oauth2.provider.code.AuthorizationRequestHol
|
|||
|
||||
/**
|
||||
* Entity class for authorization codes
|
||||
*
|
||||
* @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) {
|
||||
this.code = code;
|
||||
|
|
|
@ -5,12 +5,28 @@ import org.springframework.security.oauth2.common.exceptions.InvalidGrantExcepti
|
|||
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 {
|
||||
|
||||
/**
|
||||
* Save an AuthorizationCodeEntity to the repository
|
||||
*
|
||||
* @param authorizationCode the AuthorizationCodeEntity to save
|
||||
* @return the saved AuthorizationCodeEntity
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ import org.springframework.stereotype.Repository;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* JPA AuthorizationCodeRepository implementation.
|
||||
*
|
||||
* @author aanganes
|
||||
*
|
||||
*/
|
||||
|
@ -54,7 +56,8 @@ public class JpaAuthorizationCodeRepository implements AuthorizationCodeReposito
|
|||
}
|
||||
|
||||
AuthorizationRequestHolder authRequest = result.getAuthorizationRequestHolder();
|
||||
//authRequest.getAuthenticationRequest();
|
||||
|
||||
manager.remove(result);
|
||||
|
||||
return authRequest;
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ import org.springframework.security.oauth2.provider.code.AuthorizationRequestHol
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Database-backed, random-value authorization code service implementation.
|
||||
*
|
||||
* @author aanganes
|
||||
*
|
||||
*/
|
||||
|
@ -24,8 +26,13 @@ public class DefaultOAuth2AuthorizationCodeService implements AuthorizationCodeS
|
|||
|
||||
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
|
||||
public String createAuthorizationCode(AuthorizationRequestHolder authentication) {
|
||||
|
@ -37,8 +44,15 @@ public class DefaultOAuth2AuthorizationCodeService implements AuthorizationCodeS
|
|||
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
|
||||
public AuthorizationRequestHolder consumeAuthorizationCode(String code) throws InvalidGrantException {
|
||||
|
@ -47,10 +61,16 @@ public class DefaultOAuth2AuthorizationCodeService implements AuthorizationCodeS
|
|||
return auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the repository
|
||||
*/
|
||||
public AuthorizationCodeRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param repository the repository to set
|
||||
*/
|
||||
public void setRepository(AuthorizationCodeRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue