public static final int AUTHTOKEN_RETIRED = 0;
public UddiEntityPublisher getEntityPublisher(EntityManager em, String authInfo) throws DispositionReportFaultMessage {
if (authInfo == null || authInfo.length() == 0)
throw new AuthTokenRequiredException(new ErrorMessage("errors.auth.AuthRequired"));
org.apache.juddi.model.AuthToken modelAuthToken = em.find(org.apache.juddi.model.AuthToken.class, authInfo);
if (modelAuthToken == null)
throw new AuthTokenRequiredException(new ErrorMessage("errors.auth.AuthInvalid"));
if (modelAuthToken.getTokenState() == AUTHTOKEN_RETIRED)
throw new AuthTokenRequiredException(new ErrorMessage("errors.auth.AuthInvalid"));
Authenticator authenticator = AuthenticatorFactory.getAuthenticator();
UddiEntityPublisher entityPublisher = authenticator.identify(authInfo, modelAuthToken.getAuthorizedName());
// Must make sure the returned publisher has all the necessary fields filled
if (entityPublisher == null)
throw new AuthTokenRequiredException(new ErrorMessage("errors.auth.AuthInvalid"));
if (entityPublisher.getAuthorizedName() == null)
throw new AuthTokenRequiredException(new ErrorMessage("errors.auth.AuthInvalid"));
// Auth token is being used. Adjust appropriate values so that it's internal 'expiration clock' is reset.
modelAuthToken.setLastUsed(new Date());
modelAuthToken.setNumberOfUses(modelAuthToken.getNumberOfUses() + 1);