forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Needed to add @AuthRequired. CEDAR based authentication is moved to ArpCedarApiKeyAuthMechanism via CompoundAuthMechanism, which seems to be the new authentication approach.
- Loading branch information
Showing
4 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/edu/harvard/iq/dataverse/api/auth/ArpCedarApiKeyAuthMechanism.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package edu.harvard.iq.dataverse.api.auth; | ||
|
||
import edu.harvard.iq.dataverse.arp.ArpCedarAuthenticationServiceBean; | ||
import edu.harvard.iq.dataverse.authorization.users.User; | ||
|
||
import javax.ejb.EJB; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.core.Context; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* AuthMechanism to allow using apiKey header o key query param with a CEDAR provided token | ||
* as associated with a Dataverse user via AuthenticatedUserArp. | ||
* | ||
* Note: while this is not an annotated EJB, this will be injected as an EJB into CompoundAuthMechanism | ||
* and so we can use @EJB and @Context inside it. | ||
*/ | ||
public class ArpCedarApiKeyAuthMechanism implements AuthMechanism | ||
{ | ||
private static final Logger logger = Logger.getLogger(ArpCedarApiKeyAuthMechanism.class.getCanonicalName()); | ||
|
||
@EJB | ||
protected ArpCedarAuthenticationServiceBean cedarAuthSvc; | ||
|
||
@Context | ||
protected HttpServletRequest httpRequest; | ||
|
||
@Override | ||
public User findUserFromRequest(ContainerRequestContext crc) throws WrappedAuthErrorResponse | ||
{ | ||
return cedarAuthSvc.lookupUser(getRequestApiKey(crc)); | ||
} | ||
|
||
private String getRequestApiKey(ContainerRequestContext containerRequestContext) { | ||
String headerParamApiKey = containerRequestContext.getHeaderString(ApiKeyAuthMechanism.DATAVERSE_API_KEY_REQUEST_HEADER_NAME); | ||
String queryParamApiKey = containerRequestContext.getUriInfo().getQueryParameters().getFirst(ApiKeyAuthMechanism.DATAVERSE_API_KEY_REQUEST_PARAM_NAME); | ||
|
||
return headerParamApiKey != null ? headerParamApiKey : queryParamApiKey; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters