Commit 10c72b2d by Antti Tönkyrä

code-based authentication for netauth

1 parent 5b977bee
......@@ -19,6 +19,7 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.NetworkAssociation;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.model.Role;
/**
......@@ -44,6 +45,9 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
private EventBean eventBean;
@EJB
private CardTemplateBean cardBean;
@EJB
private PermissionBean permissionBean;
public NetworkAssociationBean() {}
......@@ -83,6 +87,21 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
if(authUser == null)
throw new Exception("INVALID_USER_OR_PASSWORD");
return tryAssociateInternal(authUser, ip, mac, code, codeRequired);
}
@Override
@RolesAllowed(NetworkAssociationPermission.S_CAN_ADMINISTER_ASSOCIATIONS)
public NetworkAssociation tryAssociate(String usercode, String ip, String mac, String code, Boolean codeRequired) throws Exception {
EventUser authUser = userBean.getUser(usercode);
if(authUser == null)
throw new Exception("INVALID_USERCODE");
return tryAssociateInternal(authUser, ip, mac, code, codeRequired);
}
private NetworkAssociation tryAssociateInternal(EventUser authUser, String ip, String mac, String code, boolean codeRequired) throws Exception {
NetworkAssociation association;
HashSet<IAppPermission> userPerms = buildPermsFor(authUser);
......@@ -261,5 +280,5 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
if(na.size() > 0) return na.get(0);
else return null;
}
}
}
......@@ -25,4 +25,7 @@ public interface NetworkAssociationBeanLocal {
NetworkAssociation getActiveAssociationByIP(String ipAddress);
NetworkAssociation tryAssociate(String usercode, String ip, String mac,
String code, Boolean codeRequired) throws Exception;
}
......@@ -60,6 +60,37 @@ public class NetworkAssociationRestView {
return resp;
}
@POST
@Path("/codeauth")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot codeAuth(
@FormParam("usercode") String usercode,
@FormParam("ip") String ip,
@FormParam("mac") String mac,
@FormParam("code") String code,
@FormParam("coderequired") Boolean codeRequired
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
NetworkAssociation na = networkAssociationBean.tryAssociate(
usercode, ip, mac, code, codeRequired);
if(na.getStatus().equals(NetworkAssociationStatus.ACTIVE))
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
else
resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} catch(Exception e) {
resp.getResult().setResultCode(0);
if(e.getMessage() != null && e.getMessage() != "") {
resp.getResult().setMessage(e.getMessage());
} else {
resp.getResult().setMessage("UNKNOWN_ERROR");
}
}
return resp;
}
@GET
@Path("/get_association_infos")
@Produces({ MediaType.APPLICATION_JSON })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!