Changeset 5014


Ignore:
Timestamp:
04/17/14 17:52:56 (10 years ago)
Author:
olhsha@mpi.nl
Message:

creating user records via froms, shibb and non-shibb

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend
Files:
3 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/pom.xml

    r4985 r5014  
    2626            <version>2.5</version>
    2727            <scope>provided</scope>
    28         </dependency>       
     28        </dependency>
     29<!--        <dependency>
     30            <groupId>com.sun.jersey</groupId>
     31            <artifactId>jersey-server-linking</artifactId>
     32            <version>1.9.1</version>
     33        </dependency>       -->
    2934        <dependency>
    3035            <groupId>com.sun.jersey</groupId>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/PrincipalResource.java

    r4995 r5014  
    3232import javax.ws.rs.Consumes;
    3333import javax.ws.rs.DELETE;
     34import javax.ws.rs.FormParam;
    3435import javax.ws.rs.GET;
    3536import javax.ws.rs.POST;
     
    5455public class PrincipalResource extends ResourceResource {
    5556
     57    int shaStrength = 512;
     58
    5659    public void setHttpRequest(HttpServletRequest request) {
    5760        this.httpServletRequest = request;
     
    9699    @GET
    97100    @Produces(MediaType.TEXT_XML)
    98     @Path("/info")
     101    @Path("info")
    99102    @Transactional(readOnly = true)
    100103    public JAXBElement<Principal> getPrincipalByInfo(@QueryParam("email") String email) throws IOException {
     
    141144    @Path("create/{remoteId}/{password}")
    142145    public String createSpringAuthenticationRecord(@PathParam("remoteId") String remoteId, @PathParam("password") String password) throws IOException {
    143         int result = dbIntegrityService.addSpringUser(remoteId, password, 512, remoteId);
    144         return result+ " record(s) has been added. Must be 2: 1 record for the principal, another for the authorities table.";
     146        Number remotePrincipalID = this.getPrincipalID();
     147        if (remotePrincipalID == null) {
     148            return "Logged in principal is null or anonymous.";
     149        }
     150
     151        if (dbIntegrityService.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) {
     152            int result = dbIntegrityService.addSpringUser(remoteId, password, shaStrength, remoteId);
     153            return result + " record(s) has been added. Must be 2: 1 record for the principal, another for the authorities table.";
     154        } else {
     155            verboseOutput.ADMIN_RIGHTS_EXPECTED();
     156            httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
     157            return "Nothing is added.";
     158        }
     159
    145160    }
    146161
     
    175190            return new ObjectFactory().createPrincipal(new Principal());
    176191        }
     192
     193    }
     194
     195    @POST
     196    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     197    @Produces(MediaType.APPLICATION_XML)
     198    @Path("register/nonshibboleth")
     199    public JAXBElement<Principal> registerNonShibbolizedPrincipal(@FormParam("name") String name,
     200            @FormParam("remoteId") String remoteId, @FormParam("password") String passowrd, @FormParam("email") String email)
     201            throws IOException {
     202        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     203        Principal newPrincipal = new Principal();
     204        newPrincipal.setDisplayName(name);
     205        newPrincipal.setEMail(email);
     206        try {
     207            try {
     208                final int updatedSpringTables = dbIntegrityService.addSpringUser(remoteId, passowrd, shaStrength, remoteId);
     209                final Number principalID = dbIntegrityService.addPrincipal(newPrincipal, remoteId);
     210                final Principal addedPrincipal = dbIntegrityService.getPrincipal(principalID);
     211                return new ObjectFactory().createPrincipal(addedPrincipal);
     212            } catch (NotInDataBaseException e1) {
     213                loggerServer.debug(e1.toString());
     214                httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString());
     215                return new ObjectFactory().createPrincipal(new Principal());
     216            }
     217        } catch (PrincipalExists e) {
     218            loggerServer.debug(e.toString());
     219            httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
     220            return new ObjectFactory().createPrincipal(new Principal());
     221        }
     222
     223    }
     224
     225    @POST
     226    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     227    @Produces(MediaType.APPLICATION_XML)
     228    @Path("register/shibboleth")
     229    public JAXBElement<Principal> registerShibbolizedPrincipal(@FormParam("name") String name,
     230            @FormParam("remoteId") String remoteId, @FormParam("email") String email)
     231            throws IOException {
     232        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     233        Principal newPrincipal = new Principal();
     234        newPrincipal.setDisplayName(name);
     235        newPrincipal.setEMail(email);
     236        try {
     237            try {
     238                final Number principalID = dbIntegrityService.addPrincipal(newPrincipal, remoteId);
     239                final Principal addedPrincipal = dbIntegrityService.getPrincipal(principalID);
     240                return new ObjectFactory().createPrincipal(addedPrincipal);
     241            } catch (NotInDataBaseException e1) {
     242                loggerServer.debug(e1.toString());
     243                httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString());
     244                return new ObjectFactory().createPrincipal(new Principal());
     245            }
     246        } catch (PrincipalExists e) {
     247            loggerServer.debug(e.toString());
     248            httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
     249            return new ObjectFactory().createPrincipal(new Principal());
     250        }
     251    }
     252
     253    @POST
     254    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     255    @Produces(MediaType.TEXT_PLAIN)
     256    @Path("register/shibbolethasnonshibboleth")
     257    public String registerShibbolizedPrincipalAsNonShibb(@FormParam("remoteId") String remoteId, @FormParam("password") String password)
     258            throws IOException {
     259        int result = dbIntegrityService.addSpringUser(remoteId, password, shaStrength, remoteId);
     260        return result + " record(s) has been added. Must be 2: 1 record for the principal, another for the authorities table.";
    177261
    178262    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/error.jsp

    r4997 r5014  
    2525    <body>
    2626     Authentication error. Check username and password. <br>
    27      <a href="index.jsp"> To DWAN's test jsp page.</a><br>
    28      <a href="loginform.jsp"> To DWAN's login jsp page.</a>
     27     <a href="api/.."> To DWAN's test jsp page.</a><br>
     28     <a href="api/authentication/login"> To DWAN's login.</a>
    2929    </body>
    3030</html>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/index.jsp

    r4997 r5014  
    2424        <p><a href="https://trac.clarin.eu/wiki/DASISH/SpecificationDocument#RESTAPI">https://trac.clarin.eu/wiki/DASISH/SpecificationDocument#RESTAPI</a></p>
    2525     
    26 <!--        <br>
    27         <a href="createprincipal.jsp"> create principal record</a> <br>
    28         <br> -->
     26        <br>
     27        <a href="registerNonShibbolethPrincipal.html"> Register a non-shibboleth user</a> <br>
     28        <br>
     29        <a href="registerShibbolethPrincipal.html"> Register a shibboleth user</a> <br>
     30        <br>
     31        <a href="registerShibbolethAlsoAsNonShibboleth.html"> Register an existing  shibboleth user as a non-shibboleth as well.</a> <br>
     32        <br>
     33        <br>
    2934        <a href="api/authentication/login"> login  </a> <br>
    3035         <br>
     
    3338       
    3439        <b>Test URI-s</b><br>
     40        <br>
    3541        <b>All output xml-s are valid w.r.t. the schema</b><br>
    3642        GET <a href="api/authentication/principal">api/authentication/principal</a> <br>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/loginform.jsp

    r4997 r5014  
    3333                    <table>
    3434                        <tr>
    35                             <td>User:</td>
     35                            <td>Login:</td>
    3636                            <td><input type='text' name='username' value=''></td>
    3737                        </tr>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/logout.jsp

    r4997 r5014  
    2525    <body>
    2626     You are logged out.<br>
    27      <a href="index.jsp"> To DWAN's test jsp page.</a>
     27     <a href="api/.."> To DWAN's main test page.</a>
    2828    </body>
    2929</html>
Note: See TracChangeset for help on using the changeset viewer.