Changeset 5975


Ignore:
Timestamp:
02/12/15 15:40:42 (9 years ago)
Author:
Twan Goosen
Message:

Authentication resource: 'redirect' param
Created two test forms in index.jsp

Location:
ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/src/main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/AuthenticationRestService.java

    r5974 r5975  
    66import clarin.cmdi.componentregistry.impl.database.ValidationException;
    77import clarin.cmdi.componentregistry.model.AuthenticationInfo;
     8import com.google.common.base.Strings;
    89import com.wordnik.swagger.annotations.Api;
    910import com.wordnik.swagger.annotations.ApiOperation;
     
    1213import java.net.URI;
    1314import java.security.Principal;
     15import javax.ws.rs.DefaultValue;
    1416import javax.ws.rs.GET;
    1517import javax.ws.rs.POST;
    1618import javax.ws.rs.Path;
    1719import javax.ws.rs.Produces;
     20import javax.ws.rs.QueryParam;
    1821import javax.ws.rs.core.Context;
    1922import javax.ws.rs.core.MediaType;
     
    2831
    2932/**
     33 * Authentication resource to be used by the client to retrieve the current
     34 * authentication status and/or to force an authentication request if the user
     35 * is not authenticated.
     36 *
     37 * <p>
     38 * A 'GET' on this resource will return a JSON or XML structure with the
     39 * following information:</p>
     40 * <ul>
     41 * <li>authentication (true/false)</li>
     42 * <li>username (string)</li>
     43 * <li>displayName</li>
     44 * (string)
     45 * </ul>
     46 *
     47 * <p>
     48 * A 'POST' to this resource will trigger an authentication request (by means of
     49 * a 401) response code if the user is not yet authenticated. In case of a
     50 * successful authentication, it will respond with a redirect (303) to this same
     51 * resource.</p>
     52 *
     53 * <p>
     54 * A query parameter 'redirect' is accepted on the GET. If it is present, the
     55 * service will respond with a redirect to the provided URI. This way, the
     56 * client can make sure that the user is lead back to the front end in the
     57 * desired state. Passing the 'redirect' query parameter in the POST response
     58 * will cause it to be preserved in the redirect to the GET. To execute a
     59 * 'login' action, a front end application will therefore typically send a POST
     60 * to {@code <SERVICE_BASE_URI>/authentication?redirect=<FRONT_END_URI>}.</p>
    3061 *
    3162 * @author Twan Goosen <twan.goosen@mpi.nl>
     
    4677    @GET
    4778    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    48     @ApiOperation(value = "Information on the current authentication state")
    49     public AuthenticationInfo getAuthenticationInformation() throws JSONException, AuthenticationRequiredException {
     79    @ApiOperation(value = "Information on the current authentication state. Pass 'redirect' query parameter to make this method redirect to the URI specified as its value.")
     80    @ApiResponses(value = {
     81        @ApiResponse(code = 200, message = "If no query parameters are passed, with the authentications status in its body"),
     82        @ApiResponse(code = 303, message = "A redirect to the URI provided as the value of the 'redirect' parameter")
     83    })
     84    public Response getAuthenticationInformation(@QueryParam("redirect") @DefaultValue("") String redirectUri) throws JSONException, AuthenticationRequiredException {
    5085        final Principal userPrincipal = security.getUserPrincipal();
    5186
     87        final AuthenticationInfo authInfo;
    5288        if (userPrincipal == null || ComponentRegistryFactory.ANONYMOUS_USER.equals(userPrincipal.getName())) {
    53             return new AuthenticationInfo(false);
     89            authInfo = new AuthenticationInfo(false);
    5490        } else {
    55             return new AuthenticationInfo(new UserCredentials(userPrincipal));
     91            authInfo = new AuthenticationInfo(new UserCredentials(userPrincipal));
     92        }
     93
     94        if (Strings.isNullOrEmpty(redirectUri)) {
     95            return Response.ok(authInfo).build();
     96        } else {
     97            return Response.seeOther(URI.create(redirectUri)).entity(authInfo).build();
    5698        }
    5799    }
     
    60102    @ApiOperation(value = "Triggers the service to require the client to authenticate by means of the configured authentication mechanism. Notice that this might require user interaction!")
    61103    @ApiResponses(value = {
    62         @ApiResponse(code = 302, message = "A redirect, either to a Shibboleth authentication page/discovery service or other identification mechanism, and ultimately once authenticated, to the application front end"),
     104        @ApiResponse(code = 303, message = "A redirect, either to a Shibboleth authentication page/discovery service or other identification mechanism, and ultimately to the same URI as requested (which should be picked up as a GET)"),
    63105        @ApiResponse(code = 401, message = "If unauthenticated, a request to authenticate may be returned (not in case of Shibboleth authentication)")
    64106    })
     
    66108        logger.debug("Client has triggered authentication request");
    67109
    68         //done - redirect to front end
    69         final URI frontEndUri = uriInfo.getBaseUri().resolve("..");
    70         return Response.seeOther(frontEndUri).build();
     110        //done - redirect to GET
     111        return Response.seeOther(uriInfo.getRequestUri()).build();
    71112    }
    72113}
  • ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/src/main/webapp/WEB-INF/web.xml

    r5917 r5975  
    120120        </auth-constraint>
    121121    </security-constraint>
    122     <security-constraint>
    123         <display-name>ComponentRegistry SWF GET</display-name>
    124         <web-resource-collection>
    125             <web-resource-name>ComponentRegistry access</web-resource-name>
    126             <description />
    127             <url-pattern>/*</url-pattern>
    128             <http-method>GET</http-method>
    129         </web-resource-collection>
    130         <auth-constraint>
    131             <role-name>tomcat</role-name>
    132         </auth-constraint>
    133     </security-constraint>
    134122    <login-config>
    135123        <auth-method>BASIC</auth-method>
  • ComponentRegistry/branches/ComponentRegistry-2.0/ComponentRegistry/src/main/webapp/index.jsp

    r5603 r5975  
    11<?xml version="1.0" encoding="UTF-8" ?>
    22<%@ page language="java" contentType="text/html; charset=UTF-8"
    3         pageEncoding="UTF-8"%>
     3         pageEncoding="UTF-8"%>
    44<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    55
    66<html
    7         xmlns="http://www.w3.org/1999/xhtml" lang="en">
    8 <head>
    9 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     7    xmlns="http://www.w3.org/1999/xhtml" lang="en">
     8    <head>
     9        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    1010
    11 <!--  BEGIN Browser History required section -->
    12 <link rel="stylesheet" type="text/css" href="history/history.css" />
    13 <!--  END Browser History required section -->
     11        <!--  BEGIN Browser History required section -->
     12        <link rel="stylesheet" type="text/css" href="history/history.css" />
     13        <!--  END Browser History required section -->
    1414
    15 <title>${title}</title>
    16 <script src="AC_OETags.js" language="javascript"></script>
     15        <title>${title}</title>
     16    </head>
    1717
    18 <!--  BEGIN Browser History required section -->
    19 <script src="history/history.js" language="javascript"></script>
    20 <!--  END Browser History required section -->
    21 
    22 <style>
    23 body {
    24         margin: 0px;
    25         overflow: hidden
    26 }
    27 </style>
    28 <script type="text/javascript" src="./js/extMouseWheel.js"></script>
    29 <script language="JavaScript" type="text/javascript">
    30 <!--
    31 // -----------------------------------------------------------------------------
    32 // Globals
    33 // Major version of Flash required
    34 var requiredMajorVersion = ${version_major};
    35 // Minor version of Flash required
    36 var requiredMinorVersion = ${version_minor};
    37 // Minor version of Flash required
    38 var requiredRevision = ${version_revision};
    39 // -----------------------------------------------------------------------------
    40 // -->
    41 </script>
    42 </head>
    43 
    44 <body scroll="no">
    45 <div id="flashContainerDiv"
    46         style="position: absolute; width: 100%; height: 100%"><script
    47         language="JavaScript" type="text/javascript">
    48 <!--
    49 // Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
    50 var hasProductInstall = DetectFlashVer(6, 0, 65);
    51 
    52 // Version check based upon the values defined in globals
    53 var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    54 
    55 if ( hasProductInstall && !hasRequestedVersion ) {
    56         // DO NOT MODIFY THE FOLLOWING FOUR LINES
    57         // Location visited after installation is complete if installation is required
    58         var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
    59         var MMredirectURL = window.location;
    60     document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    61     var MMdoctitle = document.title;
    62 
    63         AC_FL_RunContent(
    64                 "src", "playerProductInstall",
    65                 "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
    66                 "width", "${width}",
    67                 "height", "${height}",
    68                 "align", "middle",
    69                 "id", "${application}",
    70                 "quality", "high",
    71                 "bgcolor", "${bgcolor}",
    72                 "name", "${application}",
    73                 "allowScriptAccess","sameDomain",
    74                 "type", "application/x-shockwave-flash",
    75                 "pluginspage", "http://www.adobe.com/go/getflashplayer"
    76         );
    77 } else if (hasRequestedVersion) {
    78         // if we've detected an acceptable version
    79         // embed the Flash Content SWF when all tests are passed
    80         AC_FL_RunContent(
    81                         "src", "${ComponentRegistrySwfName}",
    82                         "width", "${width}",
    83                         "height", "${height}",
    84                         "align", "middle",
    85                         "id", "${application}",
    86                         "quality", "high",
    87                         "bgcolor", "${bgcolor}",
    88                         "name", "${application}",
    89                         "allowScriptAccess","sameDomain",
    90                         "type", "application/x-shockwave-flash",
    91                         "pluginspage", "http://www.adobe.com/go/getflashplayer",
    92                         "FlashVars", "serviceRootUrl=<%= application.getInitParameter("eu.clarin.cmdi.componentregistry.serviceRootUrl") %>&userName=${pageContext.request.remoteUser}&itemId=${param.itemId}&view=${param.view}&browserview=${param.browserview}&registrySpace=${param.registrySpace}&groupId=${param.groupId}&debug=${flexDebug}"
    93                            
    94         );
    95   } else {  // flash is too old or we can't detect the plugin
    96     var alternateContent = 'This content requires the Adobe Flash Player. '
    97         + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
    98     document.write(alternateContent);  // insert non-flash content
    99   }
    100 // -->
    101 </script>
    102 <noscript><object
    103         classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    104         id="${application}" width="${width}" height="${height}"
    105         codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
    106         <param name="movie" value="${ComponentRegistrySwfName}.swf" />
    107         <param name="quality" value="high" />
    108         <param name="bgcolor" value="${bgcolor}" />
    109         <param name="allowScriptAccess" value="sameDomain" />
    110         <embed src="${ComponentRegistrySwfName}.swf" quality="high" bgcolor="${bgcolor}"
    111                 width="${width}" height="${height}" name="${application}"
    112                 align="middle" play="true" loop="false" quality="high"
    113                 allowScriptAccess="sameDomain" type="application/x-shockwave-flash"
    114                 pluginspage="http://www.adobe.com/go/getflashplayer"
    115                 FlashVars="serviceRootUrl=<%= application.getInitParameter("eu.clarin.cmdi.componentregistry.serviceRootUrl") %>&userName=${pageContext.request.remoteUser}&item=${param.item}&view=${param.view}&browserview=${param.browserview}&space=${param.space}&debug=${flexDebug}">
    116         </embed>
    117 </object>
    118 </noscript>
    119 </div>
    120 </body>
     18    <body>
     19        <form action="rest/authentication" method="GET">
     20            <input type="submit" value="Authentication status"/>
     21        </form>
     22        <form action="rest/authentication?redirect=${pageContext.request.requestURL}" method="POST">
     23            <input type="submit" value="Log in"/>
     24        </form>
     25    </body>
    12126</html>
Note: See TracChangeset for help on using the changeset viewer.