Search in sources :

Example 1 with UsersWrapper

use of nl.uva.cs.lobcder.rest.wrappers.UsersWrapper in project lobcder by skoulouzis.

the class JDBCatalogue method getUsers.

public List<UsersWrapper> getUsers(Connection connection) throws SQLException {
    List<UsersWrapper> users = new ArrayList<>();
    try (PreparedStatement preparedStatement = connection.prepareStatement("select * from auth_usernames_table")) {
        ResultSet rs = preparedStatement.executeQuery();
        while (rs.next()) {
            UsersWrapper uw = new UsersWrapper();
            long id = rs.getLong(1);
            uw.setId(id);
            String token = rs.getString(2);
            // token = "****";
            uw.setToken(token);
            uw.setUname(rs.getString(3));
            List<String> roles = new ArrayList<>();
            try (PreparedStatement preparedStatement2 = connection.prepareStatement("SELECT roleName FROM auth_roles_tables WHERE unameRef = " + id)) {
                ResultSet rs2 = preparedStatement2.executeQuery();
                while (rs2.next()) {
                    roles.add(rs2.getString(1));
                }
            }
            uw.setRoles(roles);
            users.add(uw);
        }
    }
    return users;
}
Also used : UsersWrapper(nl.uva.cs.lobcder.rest.wrappers.UsersWrapper)

Example 2 with UsersWrapper

use of nl.uva.cs.lobcder.rest.wrappers.UsersWrapper in project lobcder by skoulouzis.

the class UsersService method getXml.

@Path("query/")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public UsersWrapperList getXml() throws FileNotFoundException, VlException, URISyntaxException, IOException, MalformedURLException, Exception {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.isAdmin()) {
        try (Connection cn = getCatalogue().getConnection()) {
            List<UsersWrapper> res = queryUsers(cn);
            UsersWrapperList uwl = new UsersWrapperList();
            uwl.setUsers(res);
            return uwl;
        } catch (SQLException ex) {
            log.log(Level.SEVERE, null, ex);
            throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
        }
    }
    return null;
}
Also used : MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) WebApplicationException(javax.ws.rs.WebApplicationException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) UsersWrapperList(nl.uva.cs.lobcder.rest.wrappers.UsersWrapperList) UsersWrapper(nl.uva.cs.lobcder.rest.wrappers.UsersWrapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

UsersWrapper (nl.uva.cs.lobcder.rest.wrappers.UsersWrapper)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)1 UsersWrapperList (nl.uva.cs.lobcder.rest.wrappers.UsersWrapperList)1