public Subject run()
{
if (recoverUserName != null && recoverPassword != null)
{
// User name and password use-case
Subject subject = new Subject();
// Principals
Principal p = new SimplePrincipal(recoverUserName);
subject.getPrincipals().add(p);
// PrivateCredentials
PasswordCredential pc = new PasswordCredential(recoverUserName, recoverPassword.toCharArray());
pc.setManagedConnectionFactory(mcf);
subject.getPrivateCredentials().add(pc);
// PublicCredentials
// None
if (log.isDebugEnabled())
log.debug("Recovery Subject=" + subject);
return subject;
}
else
{
// Security-domain use-case
try
{
// Create a security context on the association
SecurityContext securityContext = SecurityContextFactory.createSecurityContext(recoverSecurityDomain);
SecurityContextAssociation.setSecurityContext(securityContext);
// Unauthenticated
Subject unauthenticated = new Subject();
// Leave the subject empty as we don't have any information to do the
// authentication with - and we only need it to be able to get the
// real subject from the SubjectFactory
// Set the authenticated subject
securityContext.getSubjectInfo().setAuthenticatedSubject(unauthenticated);
// Select the domain
String domain = recoverSecurityDomain;
if (domain == null)
domain = securityDomain;
if (domain != null)
{
// Use the unauthenticated subject to get the real recovery subject instance
Subject subject = subjectFactory.createSubject(domain);
if (log.isDebugEnabled())
log.debug("Recovery Subject=" + subject);
return subject;