Newer
Older
package ca.nrc.cadc.auth;
Brian Major
committed
import java.net.URI;
import java.net.URL;
import javax.security.auth.Subject;
import org.apache.log4j.Logger;
import ca.nrc.cadc.profiler.Profiler;
import ca.nrc.cadc.reg.Standards;
import ca.nrc.cadc.reg.client.LocalAuthority;
Brian Major
committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import ca.nrc.cadc.reg.client.RegistryClient;
import ca.nrc.cadc.vosi.avail.CheckResource;
import ca.nrc.cadc.vosi.avail.CheckWebService;
/**
* Implementation of default Authenticator for AuthenticationUtil in cadcUtil.
* This class augments the subject with additional identities using the access
* control library.
*
* @author pdowler
*/
public class AuthenticatorImpl implements Authenticator
{
private static final Logger log = Logger.getLogger(AuthenticatorImpl.class);
public AuthenticatorImpl()
{
}
/**
* @param subject
* @return the possibly modified subject
*/
public Subject getSubject(Subject subject)
{
AuthMethod am = AuthenticationUtil.getAuthMethod(subject);
if (am == null || AuthMethod.ANON.equals(am))
{
return subject;
}
if (subject != null && subject.getPrincipals().size() > 0)
{
Profiler prof = new Profiler(AuthenticatorImpl.class);
ACIdentityManager identityManager = new ACIdentityManager();
identityManager.augmentSubject(subject);
prof.checkpoint("AuthenticatorImpl.augmentSubject()");
if (subject.getPrincipals(NumericPrincipal.class).isEmpty()) // no matching internal account
Brian Major
committed
{
// if the caller had an invalid or forged CADC_SSO cookie, we could get
// in here and then not match any known identity: drop to anon
log.debug("NumericPrincipal not found - dropping to anon: " + subject);
subject = AuthenticationUtil.getAnonSubject();
Brian Major
committed
}
}
return subject;
}
public static CheckResource getAvailabilityCheck()
{
RegistryClient regClient = new RegistryClient();
LocalAuthority localAuth = new LocalAuthority();
URI serviceURI = localAuth.getServiceURI(Standards.UMS_USERS_01.toASCIIString());
URL availURL = regClient.getServiceURL(serviceURI, Standards.VOSI_AVAILABILITY, AuthMethod.ANON);
return new CheckWebService(availURL.toExternalForm());