/*
- * Copyright [2006] [University Corporation for Advanced Internet Development, Inc.]
+ * Copyright 2006 University Corporation for Advanced Internet Development, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import edu.internet2.middleware.shibboleth.idp.authn.AuthenticationEngine;
import edu.internet2.middleware.shibboleth.idp.authn.LoginHandler;
+import edu.internet2.middleware.shibboleth.idp.authn.UsernamePrincipal;
-/**
- * Extracts the REMOTE_USER and places it in a request attribute to be used by the authentication engine.
- */
+/** Extracts the REMOTE_USER and places it in a request attribute to be used by the authentication engine. */
public class RemoteUserAuthServlet extends HttpServlet {
/** Serial version UID. */
- private static final long serialVersionUID = 1745454095756633626L;
+ private static final long serialVersionUID = -6153665874235557534L;
/** Class logger. */
private final Logger log = LoggerFactory.getLogger(RemoteUserAuthServlet.class);
String principalName = httpRequest.getRemoteUser();
log.debug("Remote user identified as {} returning control back to authentication engine", principalName);
- httpRequest.setAttribute(LoginHandler.PRINCIPAL_NAME_KEY, httpRequest.getRemoteUser());
+ httpRequest.setAttribute(LoginHandler.PRINCIPAL_KEY, new UsernamePrincipal(principalName));
AuthenticationEngine.returnToAuthenticationEngine(httpRequest, httpResponse);
}
}
\ No newline at end of file
Subject loginSubject = jaasLoginCtx.getSubject();
Set<Principal> principals = loginSubject.getPrincipals();
- if (principals.isEmpty()) {
- principals.add(new UsernamePrincipal(username));
- }
+ principals.add(new UsernamePrincipal(username));
Set<Object> publicCredentials = loginSubject.getPublicCredentials();
package edu.internet2.middleware.shibboleth.idp.session.impl;
+import java.security.Principal;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import javax.security.auth.Subject;
+
import edu.internet2.middleware.shibboleth.common.session.impl.AbstractSession;
+import edu.internet2.middleware.shibboleth.idp.authn.UsernamePrincipal;
import edu.internet2.middleware.shibboleth.idp.session.AuthenticationMethodInformation;
import edu.internet2.middleware.shibboleth.idp.session.ServiceInformation;
import edu.internet2.middleware.shibboleth.idp.session.Session;
public synchronized ServiceInformation getServiceInformation(String entityId) {
return servicesInformation.get(entityId);
}
+
+ /**
+ * This method will return the first, in an unordered list of principal names registered with the {@link Subject} of
+ * the session. If one or more {@link UsernamePrincipal} principals is registered with the subject the returned
+ * value will be the string form of one of those.
+ *
+ * {@inheritDoc}
+ */
+ public synchronized String getPrincipalName() {
+ Subject subject = getSubject();
+
+ Set<? extends Principal> principals = subject.getPrincipals(UsernamePrincipal.class);
+ if (principals == null || principals.isEmpty()) {
+ principals = subject.getPrincipals();
+ }
+
+ if (principals == null || principals.isEmpty()) {
+ return null;
+ }
+
+ return principals.iterator().next().getName();
+ }
}
\ No newline at end of file