Commit 4bf0e50b by Tuomas Riihimäki

wtf

1 parent ce3eb353
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.v1;
/*
@RequestScoped
@Path("/v1/auth")
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON, "; charset=UTF-8"})
@Api(value = "/v1/auth", description = "Authentication function")
public class AuthRestView {
@EJB
private UserBeanLocal userbean;
@EJB
private CardTemplateBeanLocal cardbean;
@Context
private HttpServletRequest servletRequest;
@EJB
private PermissionBeanLocal permbean;
private static final Logger logger = LoggerFactory.getLogger(AuthRestView.class);
@EJB
private PlaceGroupBeanLocal placegroupbean;
@EJB
private ReaderBeanLocal readerbean;
@EJB
private TicketBeanLocal ticketbean;
@EJB
private PlaceBeanLocal placebean;
/**
* Tries to log in with credentials in form params {username} and {password}.
* If user is already logged, we log the existing user out and try login with new credentials
*
* @param username
* @param password
* @return {@link UserPojo} User rest object and http 200 if succeessful, http 403 if login failed
///
@POST
@Path("/login")
@Produces({MediaType.APPLICATION_JSON})
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Operation(description = "Authenticate", responses = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = UserPojo.class))) })
public Response auth(
@FormParam("username") String username,
@FormParam("password") String password) {
boolean success = false;
try {
Principal principal = servletRequest.getUserPrincipal();
// If users exists, but is different than the user we are trying to log in with, logout, and relogin
// with the new user.
if (principal != null && principal.getName() != null && !principal.getName().equals(username)) {
servletRequest.logout();
principal = null;
}
// If there is no active login at the moment
if (principal == null) {
servletRequest.getSession(true);
servletRequest.login(username, password);
}
success = true;
} catch (ServletException e) {
// Catch error, do nothing else.l
}
Response.ResponseBuilder ret = Response.ok();
if (success) {
//ret.entity(pojoFactory.createUserPojo(permbean.getCurrentUser()));
} else {
ret.status(Response.Status.FORBIDDEN);
}
return ret.build();
}
}
*/
\ No newline at end of file
package fi.codecrew.moya.rest.v3;
import fi.codecrew.moya.beans.RoleBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.entitysearch.UserSearchQuery;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.rest.v2.PojoFactoryV2;
import fi.codecrew.moya.rest.v2.pojo.UserPojo;
import fi.codecrew.moya.utilities.SearchResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@RequestScoped
@Path("/v3/role")
@Produces({MediaType.APPLICATION_JSON + "; charset=UTF-8"})
@Consumes({MediaType.APPLICATION_JSON})
public class RoleRestViewV3 {
@EJB
private UserBeanLocal userbean;
@EJB
private RoleBeanLocal rolebean;
@GET
@Path("/{roleid}/users")
@Operation(description = "Get PrintedCard for EventUser",
responses = {@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = UserPojo.class)))})
public Response getRolesUsers(@PathParam("roleid") Integer roleid) {
Role r = rolebean.find(roleid);
if (r == null) {
return Response.status(Response.Status.NOT_FOUND).entity("Nor role found for id " + roleid).build();
}
UserSearchQuery q = new UserSearchQuery();
q.setFilterRoles(Arrays.asList(r));
SearchResult<EventUser> ret = userbean.getThisEventsUsers(q);
return Response.ok(
new GenericEntity<List<UserPojo>>(
ret.getResults().stream().map(eu -> PojoFactoryV2.createUserPojo(eu)).collect(Collectors.toList()
)) {
}).build();
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!