Exemple #1
0
  /**
   * Method to check current status of the service and logged in user.
   *
   * <p>okay: true | false authenticated: true | false epersonEMAIL: [email protected] epersonNAME:
   * John Doe
   *
   * @param headers Request header which contains the header named "rest-dspace-token" containing
   *     the token as value.
   * @return status the Status object with information about REST API
   * @throws UnsupportedEncodingException The Character Encoding is not supported.
   */
  @GET
  @Path("/status")
  @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public Status status(@Context HttpHeaders headers) throws UnsupportedEncodingException {
    org.dspace.core.Context context = null;

    try {
      context = Resource.createContext();
      EPerson ePerson = context.getCurrentUser();

      if (ePerson != null) {
        // DB EPerson needed since token won't have full info, need context
        EPerson dbEPerson = epersonService.findByEmail(context, ePerson.getEmail());

        Status status = new Status(dbEPerson.getEmail(), dbEPerson.getFullName());
        return status;
      }
    } catch (ContextException e) {
      Resource.processException("Status context error: " + e.getMessage(), context);
    } catch (SQLException e) {
      Resource.processException("Status eperson db lookup error: " + e.getMessage(), context);
    } finally {
      context.abort();
    }

    // fallback status, unauth
    return new Status();
  }
Exemple #2
0
 @GET
 @Path("/login-shibboleth")
 @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
 public Response shibbolethLoginEndPoint() {
   org.dspace.core.Context context = null;
   try {
     context = Resource.createContext();
     AuthenticationService authenticationService =
         AuthenticateServiceFactory.getInstance().getAuthenticationService();
     Iterator<AuthenticationMethod> authenticationMethodIterator =
         authenticationService.authenticationMethodIterator();
     while (authenticationMethodIterator.hasNext()) {
       AuthenticationMethod authenticationMethod = authenticationMethodIterator.next();
       if (authenticationMethod instanceof ShibAuthentication) {
         // TODO: Perhaps look for a better way of handling this ?
         org.dspace.services.model.Request currentRequest =
             new DSpace().getRequestService().getCurrentRequest();
         String loginPageURL =
             authenticationMethod.loginPageURL(
                 context,
                 currentRequest.getHttpServletRequest(),
                 currentRequest.getHttpServletResponse());
         if (StringUtils.isNotBlank(loginPageURL)) {
           currentRequest.getHttpServletResponse().sendRedirect(loginPageURL);
         }
       }
     }
     context.abort();
   } catch (ContextException | SQLException | IOException e) {
     Resource.processException("Shibboleth endpoint error:  " + e.getMessage(), context);
   } finally {
     if (context != null && context.isValid()) {
       context.abort();
     }
   }
   return Response.ok().build();
 }