Refactor part 1

pull/210/head
Amanda Anganes 2012-09-18 14:24:34 -04:00
parent 0b6aebfefe
commit c40efda6b5
17 changed files with 50 additions and 49 deletions

View File

@ -49,7 +49,7 @@ import org.mitre.jwt.signer.JwsAlgorithm;
import org.mitre.jwt.signer.JwtSigner; import org.mitre.jwt.signer.JwtSigner;
import org.mitre.jwt.signer.impl.RsaSigner; import org.mitre.jwt.signer.impl.RsaSigner;
import org.mitre.jwt.signer.service.JwtSigningAndValidationService; import org.mitre.jwt.signer.service.JwtSigningAndValidationService;
import org.mitre.jwt.signer.service.impl.JwtSigningAndValidationServiceDefault; import org.mitre.jwt.signer.service.impl.DefaultJwtSigningAndValidationService;
import org.mitre.key.fetch.KeyFetcher; import org.mitre.key.fetch.KeyFetcher;
import org.mitre.openid.connect.config.OIDCServerConfiguration; import org.mitre.openid.connect.config.OIDCServerConfiguration;
import org.mitre.openid.connect.model.IdToken; import org.mitre.openid.connect.model.IdToken;
@ -640,7 +640,7 @@ public class AbstractOIDCAuthenticationFilter extends
signers.put(serverConfig.getIssuer() + JwsAlgorithm.RS512.getJwaName(), signer512); signers.put(serverConfig.getIssuer() + JwsAlgorithm.RS512.getJwaName(), signer512);
} }
JwtSigningAndValidationService signingAndValidationService = new JwtSigningAndValidationServiceDefault(signers); JwtSigningAndValidationService signingAndValidationService = new DefaultJwtSigningAndValidationService(signers);
validationServices.put(serverConfig, signingAndValidationService); validationServices.put(serverConfig, signingAndValidationService);

View File

@ -15,7 +15,7 @@ import org.bouncycastle.math.ec.ECCurve;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
public class EC extends AbstractJwk{ public class EllipticCurveJwk extends AbstractJwk {
public static final String CURVE = "crv"; public static final String CURVE = "crv";
public static final String X = "x"; public static final String X = "x";
@ -51,7 +51,7 @@ public class EC extends AbstractJwk{
this.y = y; this.y = y;
} }
public EC(JsonObject object) { public EllipticCurveJwk(JsonObject object) {
super(object); super(object);
} }

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
******************************************************************************/ ******************************************************************************/
package org.mitre.jwt.signer.service.impl; package org.mitre.jwt.encryption.impl;
import java.io.InputStream; import java.io.InputStream;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;

View File

@ -26,9 +26,9 @@ import java.security.interfaces.RSAPrivateKey;
import java.util.List; import java.util.List;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.mitre.jwt.encryption.impl.KeyStore;
import org.mitre.jwt.signer.AbstractJwtSigner; import org.mitre.jwt.signer.AbstractJwtSigner;
import org.mitre.jwt.signer.JwsAlgorithm; import org.mitre.jwt.signer.JwsAlgorithm;
import org.mitre.jwt.signer.service.impl.KeyStore;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;

View File

@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
public class JwtSigningAndValidationServiceDefault implements JwtSigningAndValidationService, InitializingBean { public class DefaultJwtSigningAndValidationService implements JwtSigningAndValidationService, InitializingBean {
@Autowired @Autowired
private ConfigurationPropertiesBean configBean; private ConfigurationPropertiesBean configBean;
@ -36,21 +36,21 @@ public class JwtSigningAndValidationServiceDefault implements JwtSigningAndValid
// map of identifier to signer // map of identifier to signer
private Map<String, ? extends JwtSigner> signers = new HashMap<String, JwtSigner>(); private Map<String, ? extends JwtSigner> signers = new HashMap<String, JwtSigner>();
private static Logger logger = LoggerFactory.getLogger(JwtSigningAndValidationServiceDefault.class); private static Logger logger = LoggerFactory.getLogger(DefaultJwtSigningAndValidationService.class);
/** /**
* default constructor * default constructor
*/ */
public JwtSigningAndValidationServiceDefault() { public DefaultJwtSigningAndValidationService() {
} }
/** /**
* Create JwtSigningAndValidationServiceDefault * Create DefaultJwtSigningAndValidationService
* *
* @param signer * @param signer
* List of JwtSigners to associate with this service * List of JwtSigners to associate with this service
*/ */
public JwtSigningAndValidationServiceDefault(Map<String, ? extends JwtSigner> signer) { public DefaultJwtSigningAndValidationService(Map<String, ? extends JwtSigner> signer) {
setSigners(signer); setSigners(signer);
} }
@ -67,7 +67,7 @@ public class JwtSigningAndValidationServiceDefault implements JwtSigningAndValid
logger.info(this.toString()); logger.info(this.toString());
} }
logger.info("JwtSigningAndValidationServiceDefault is open for business"); logger.info("DefaultJwtSigningAndValidationService is open for business");
} }
@ -104,7 +104,7 @@ public class JwtSigningAndValidationServiceDefault implements JwtSigningAndValid
*/ */
@Override @Override
public String toString() { public String toString() {
return "JwtSigningAndValidationServiceDefault [signers=" + signers + "]"; return "DefaultJwtSigningAndValidationService [signers=" + signers + "]";
} }
/** /**

View File

@ -17,9 +17,9 @@ import org.springframework.security.oauth2.provider.OAuth2Authentication;
@Entity @Entity
@Table(name="authentication_holder") @Table(name="authentication_holder")
@NamedQueries ({ @NamedQueries ({
@NamedQuery(name = "AuthenticationHolder.getByAuthentication", query = "select a from AuthenticationHolder a where a.authentication = :authentication") @NamedQuery(name = "AuthenticationHolderEntity.getByAuthentication", query = "select a from AuthenticationHolderEntity a where a.authentication = :authentication")
}) })
public class AuthenticationHolder { public class AuthenticationHolderEntity {
private Long id; private Long id;
@ -27,7 +27,7 @@ public class AuthenticationHolder {
private OAuth2Authentication authentication; private OAuth2Authentication authentication;
public AuthenticationHolder() { public AuthenticationHolderEntity() {
} }

View File

@ -69,7 +69,7 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
private ClientDetailsEntity client; private ClientDetailsEntity client;
private AuthenticationHolder authenticationHolder; // the authentication that made this access private AuthenticationHolderEntity authenticationHolder; // the authentication that made this access
private Jwt jwtValue; // JWT-encoded access token value private Jwt jwtValue; // JWT-encoded access token value
@ -122,14 +122,14 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
*/ */
@ManyToOne @ManyToOne
@JoinColumn(name = "auth_holder_id") @JoinColumn(name = "auth_holder_id")
public AuthenticationHolder getAuthenticationHolder() { public AuthenticationHolderEntity getAuthenticationHolder() {
return authenticationHolder; return authenticationHolder;
} }
/** /**
* @param authentication the authentication to set * @param authentication the authentication to set
*/ */
public void setAuthenticationHolder(AuthenticationHolder authenticationHolder) { public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) {
this.authenticationHolder = authenticationHolder; this.authenticationHolder = authenticationHolder;
} }

View File

@ -57,7 +57,7 @@ public class OAuth2RefreshTokenEntity implements OAuth2RefreshToken {
private Long id; private Long id;
private AuthenticationHolder authenticationHolder; private AuthenticationHolderEntity authenticationHolder;
private ClientDetailsEntity client; private ClientDetailsEntity client;
@ -98,14 +98,14 @@ public class OAuth2RefreshTokenEntity implements OAuth2RefreshToken {
*/ */
@ManyToOne @ManyToOne
@JoinColumn(name = "auth_holder_id") @JoinColumn(name = "auth_holder_id")
public AuthenticationHolder getAuthenticationHolder() { public AuthenticationHolderEntity getAuthenticationHolder() {
return authenticationHolder; return authenticationHolder;
} }
/** /**
* @param authentication the authentication to set * @param authentication the authentication to set
*/ */
public void setAuthenticationHolder(AuthenticationHolder authenticationHolder) { public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) {
this.authenticationHolder = authenticationHolder; this.authenticationHolder = authenticationHolder;
} }

View File

@ -1,18 +1,18 @@
package org.mitre.oauth2.repository; package org.mitre.oauth2.repository;
import org.mitre.oauth2.model.AuthenticationHolder; import org.mitre.oauth2.model.AuthenticationHolderEntity;
import org.springframework.security.oauth2.provider.OAuth2Authentication; import org.springframework.security.oauth2.provider.OAuth2Authentication;
public interface AuthenticationHolderRepository { public interface AuthenticationHolderRepository {
public AuthenticationHolder getById(Long id); public AuthenticationHolderEntity getById(Long id);
public AuthenticationHolder getByAuthentication(OAuth2Authentication a); public AuthenticationHolderEntity getByAuthentication(OAuth2Authentication a);
public void removeById(Long id); public void removeById(Long id);
public void remove(AuthenticationHolder a); public void remove(AuthenticationHolderEntity a);
public AuthenticationHolder save(AuthenticationHolder a); public AuthenticationHolderEntity save(AuthenticationHolderEntity a);
} }

View File

@ -4,7 +4,7 @@ import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import org.mitre.oauth2.model.AuthenticationHolder; import org.mitre.oauth2.model.AuthenticationHolderEntity;
import org.mitre.oauth2.repository.AuthenticationHolderRepository; import org.mitre.oauth2.repository.AuthenticationHolderRepository;
import org.mitre.util.jpa.JpaUtil; import org.mitre.util.jpa.JpaUtil;
import org.springframework.security.oauth2.provider.OAuth2Authentication; import org.springframework.security.oauth2.provider.OAuth2Authentication;
@ -19,13 +19,13 @@ public class JpaAuthenticationHolderRepository implements AuthenticationHolderRe
private EntityManager manager; private EntityManager manager;
@Override @Override
public AuthenticationHolder getById(Long id) { public AuthenticationHolderEntity getById(Long id) {
return manager.find(AuthenticationHolder.class, id); return manager.find(AuthenticationHolderEntity.class, id);
} }
@Override @Override
public AuthenticationHolder getByAuthentication(OAuth2Authentication a) { public AuthenticationHolderEntity getByAuthentication(OAuth2Authentication a) {
TypedQuery<AuthenticationHolder> query = manager.createNamedQuery("AuthenticationHolder.getByAuthentication", AuthenticationHolder.class); TypedQuery<AuthenticationHolderEntity> query = manager.createNamedQuery("AuthenticationHolderEntity.getByAuthentication", AuthenticationHolderEntity.class);
query.setParameter("authentication", a); query.setParameter("authentication", a);
return JpaUtil.getSingleResult(query.getResultList()); return JpaUtil.getSingleResult(query.getResultList());
} }
@ -33,28 +33,28 @@ public class JpaAuthenticationHolderRepository implements AuthenticationHolderRe
@Override @Override
@Transactional @Transactional
public void removeById(Long id) { public void removeById(Long id) {
AuthenticationHolder found = getById(id); AuthenticationHolderEntity found = getById(id);
if (found != null) { if (found != null) {
manager.remove(found); manager.remove(found);
} else { } else {
throw new IllegalArgumentException("AuthenticationHolder not found: " + id); throw new IllegalArgumentException("AuthenticationHolderEntity not found: " + id);
} }
} }
@Override @Override
@Transactional @Transactional
public void remove(AuthenticationHolder a) { public void remove(AuthenticationHolderEntity a) {
AuthenticationHolder found = getById(a.getId()); AuthenticationHolderEntity found = getById(a.getId());
if (found != null) { if (found != null) {
manager.remove(found); manager.remove(found);
} else { } else {
throw new IllegalArgumentException("AuthenticationHolder not found: " + a); throw new IllegalArgumentException("AuthenticationHolderEntity not found: " + a);
} }
} }
@Override @Override
@Transactional @Transactional
public AuthenticationHolder save(AuthenticationHolder a) { public AuthenticationHolderEntity save(AuthenticationHolderEntity a) {
return JpaUtil.saveOrUpdate(a.getId(), manager, a); return JpaUtil.saveOrUpdate(a.getId(), manager, a);
} }

View File

@ -22,7 +22,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.mitre.oauth2.model.AuthenticationHolder; import org.mitre.oauth2.model.AuthenticationHolderEntity;
import org.mitre.oauth2.model.ClientDetailsEntity; import org.mitre.oauth2.model.ClientDetailsEntity;
import org.mitre.oauth2.model.OAuth2AccessTokenEntity; import org.mitre.oauth2.model.OAuth2AccessTokenEntity;
import org.mitre.oauth2.model.OAuth2RefreshTokenEntity; import org.mitre.oauth2.model.OAuth2RefreshTokenEntity;
@ -98,7 +98,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
} }
// attach the authorization so that we can look it up later // attach the authorization so that we can look it up later
AuthenticationHolder authHolder = new AuthenticationHolder(); AuthenticationHolderEntity authHolder = new AuthenticationHolderEntity();
authHolder.setAuthentication(authentication); authHolder.setAuthentication(authentication);
authHolder = authenticationHolderRepository.save(authHolder); authHolder = authenticationHolderRepository.save(authHolder);
@ -150,7 +150,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
ClientDetailsEntity client = refreshToken.getClient(); ClientDetailsEntity client = refreshToken.getClient();
AuthenticationHolder authHolder = refreshToken.getAuthenticationHolder(); AuthenticationHolderEntity authHolder = refreshToken.getAuthenticationHolder();
//Make sure this client allows access token refreshing //Make sure this client allows access token refreshing
if (!client.isAllowRefresh()) { if (!client.isAllowRefresh()) {

View File

@ -40,9 +40,9 @@ import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
public class TokenIntrospection extends AbstractView { public class TokenIntrospectionView extends AbstractView {
private static Logger logger = LoggerFactory.getLogger(TokenIntrospection.class); private static Logger logger = LoggerFactory.getLogger(TokenIntrospectionView.class);
@Override @Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
@ -118,7 +118,7 @@ public class TokenIntrospection extends AbstractView {
} catch (IOException e) { } catch (IOException e) {
logger.error("IOException occurred in TokenIntrospection.java: ", e); logger.error("IOException occurred in TokenIntrospectionView.java: ", e);
} }

View File

@ -8,7 +8,7 @@
<class>org.mitre.oauth2.model.ClientDetailsEntity</class> <class>org.mitre.oauth2.model.ClientDetailsEntity</class>
<class>org.mitre.oauth2.model.OAuth2AccessTokenEntity</class> <class>org.mitre.oauth2.model.OAuth2AccessTokenEntity</class>
<class>org.mitre.oauth2.model.OAuth2RefreshTokenEntity</class> <class>org.mitre.oauth2.model.OAuth2RefreshTokenEntity</class>
<class>org.mitre.oauth2.model.AuthenticationHolder</class> <class>org.mitre.oauth2.model.AuthenticationHolderEntity</class>
<class>org.mitre.oauth2.model.AuthorizationCodeEntity</class> <class>org.mitre.oauth2.model.AuthorizationCodeEntity</class>
<class>org.mitre.openid.connect.model.Address</class> <class>org.mitre.openid.connect.model.Address</class>
<class>org.mitre.openid.connect.model.ApprovedSite</class> <class>org.mitre.openid.connect.model.ApprovedSite</class>

View File

@ -3,13 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="defaultKeystore" class="org.mitre.jwt.signer.service.impl.KeyStore"> <bean id="defaultKeystore" class="org.mitre.jwt.encryption.impl.KeyStore">
<constructor-arg name="location" value="classpath:keystore.jks" /> <constructor-arg name="location" value="classpath:keystore.jks" />
<constructor-arg name="password" value="changeit" /> <constructor-arg name="password" value="changeit" />
</bean> </bean>
<bean id="defaultsignerService" <bean id="defaultsignerService"
class="org.mitre.jwt.signer.service.impl.JwtSigningAndValidationServiceDefault"> class="org.mitre.jwt.signer.service.impl.DefaultJwtSigningAndValidationService">
<property name="signers"> <property name="signers">
<map> <map>
<entry key="rsa1"> <entry key="rsa1">

View File

@ -33,13 +33,13 @@ import org.bouncycastle.jce.X509Principal;
import org.bouncycastle.x509.X509V3CertificateGenerator; import org.bouncycastle.x509.X509V3CertificateGenerator;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mitre.jwt.encryption.impl.KeyStore;
import org.mitre.jwt.model.Jwt; import org.mitre.jwt.model.Jwt;
import org.mitre.jwt.signer.JwsAlgorithm; import org.mitre.jwt.signer.JwsAlgorithm;
import org.mitre.jwt.signer.JwtSigner; import org.mitre.jwt.signer.JwtSigner;
import org.mitre.jwt.signer.impl.HmacSigner; import org.mitre.jwt.signer.impl.HmacSigner;
import org.mitre.jwt.signer.impl.PlaintextSigner; import org.mitre.jwt.signer.impl.PlaintextSigner;
import org.mitre.jwt.signer.impl.RsaSigner; import org.mitre.jwt.signer.impl.RsaSigner;
import org.mitre.jwt.signer.service.impl.KeyStore;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

View File

@ -37,6 +37,7 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.x509.X509V3CertificateGenerator; import org.bouncycastle.x509.X509V3CertificateGenerator;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mitre.jwt.encryption.impl.KeyStore;
import org.mitre.jwt.signer.impl.RsaSigner; import org.mitre.jwt.signer.impl.RsaSigner;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;

View File

@ -38,7 +38,7 @@
</bean> </bean>
<bean id="testKeystore" class="org.mitre.jwt.signer.service.impl.KeyStore"> <bean id="testKeystore" class="org.mitre.jwt.encryption.impl.KeyStore">
<constructor-arg name="location" value="file:src/test/resources/keystore.jks" /> <constructor-arg name="location" value="file:src/test/resources/keystore.jks" />
<constructor-arg name="password" value="changeit" /> <constructor-arg name="password" value="changeit" />
</bean> </bean>