Commit d5b147cf by Antti Tönkyrä

Merge branch 'master' into 'master'

Authkoodin generointi ja piirto + restapi ja yksi bugikorjaus

Authkoodin generointi ja piirtäminen kortille sekä restapi käyttäjän hakemiseksi koodilla. Korjattu myös templaten asettaminen CardTemplateDataEditViewin initView():ssä silloin kun cardObjectDataId tai cardTextDataId on annettu parametrinä.
2 parents 7666f893 58bc1f54
......@@ -252,6 +252,8 @@ public class CardPrintBean implements CardPrintBeanLocal {
text.setText(user.getBirthday().toString());
} else if(textDataType == CardTextDataType.STATIC) {
text.setText(textData.getText());
} else if(textDataType == CardTextDataType.AUTHCODE) {
text.setText(userBean.getAuthCode(user));
}
CardTextAlignment alignment = textData.getTextAlignment();
......@@ -502,6 +504,9 @@ public class CardPrintBean implements CardPrintBeanLocal {
} else if(textData.getTextDataType() == CardTextDataType.STATIC) {
logger.info("Drawing static text '" + textData.getText() + "' to card.");
g.drawString(textData.getText(), x, y);
} else if(textData.getTextDataType() == CardTextDataType.AUTHCODE) {
logger.info("Drawing auth code text '" + textData.getText() + "' to card.");
g.drawString(userBean.getAuthCode(user), x, y);
}
} else if(objectData != null) {
......
......@@ -8,6 +8,8 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Calendar;
......@@ -28,6 +30,7 @@ import javax.imageio.ImageIO;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -933,4 +936,92 @@ public class UserBean implements UserBeanLocal {
}
@Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT)
public String getAuthCode(EventUser user) {
logger.info("getAuthCode()");
String code = "";
String hex = Integer.toHexString(user.getId());
logger.info("Hex code {} for id {}", hex, user.getId());
//padding hex string to 5 characters by adding Xs to the beginning
if(hex.length() < 5) {
logger.info("Padding hex ({}) with X.", hex.length());
for(int i = 0; i < 5; i++) {
if(hex.length() < 5) {
hex = "X" + hex;
}
else break;
}
} else
logger.info("Hex string too long ({}), no padding needed", hex.length());
String hash = "";
logger.info("Generating md5 hash from hex {}", hex);
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] array = md.digest(hex.getBytes());
hash = new String(Hex.encodeHex(array));
logger.info("Hash {}", hash);
}catch(NoSuchAlgorithmException ex) {
logger.info("Catched exeption {}", ex.getMessage());
}
if(hash != "" && hash.length() > 2) {
//Generating code by concatenating hex string and first 3 characters from hash
code = code.concat(hex);
code = code.concat(hash.substring(0, 3));
logger.info("Code for user is {}", code);
}else
logger.info("No code generated: hash.length() {}", hash.length());
return code.toUpperCase();
}
@Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT)
public EventUser getUser(String authcode) {
logger.info("getUser({})", authcode);
EventUser user = null;
if(authcode.length() == 8) {
logger.info("authcode length is 8");
// First 5 characters are the hex
String paddedHex = authcode.substring(0, 5);
logger.info("Padded hex {}", paddedHex);
// Removing the padding characters
String hex = paddedHex.replace("X", "");
logger.info("Hex {}", hex);
int id = 0;
try {
id = Integer.decode("0x"+ hex.toLowerCase());
}catch(NumberFormatException ex) {
logger.info("NumberFormatException was thrown");
}
logger.info("Id {}", id);
if(id != 0) {
user = eventUserFacade.find(id);
}
if(user != null) {
// Testing if the user is correct
logger.info("User {} found with id {}", user, id);
String testCode = getAuthCode(user);
logger.info("Testcode {}", testCode);
if(testCode == null || testCode.equals("") || !authcode.equals(testCode)) {
user = null;
logger.info("User set to null, test code not the same as user that was found.");
}
} else
logger.info("User not found with id {}", id);
}else
logger.info("authcode length not 8!, length {}", authcode.length());
return user;
}
}
\ No newline at end of file
......@@ -131,4 +131,7 @@ public interface UserBeanLocal {
*/
BigDecimal transferAccountSaldoFromPreviousEvent(List<User> dstEventuser, LanEvent source);
EventUser getUser(String authcode);
String getAuthCode(EventUser user);
}
......@@ -9,7 +9,8 @@ public enum CardTextDataType {
WHOLENAME,
STATIC,
AGE,
ROLE;
ROLE,
AUTHCODE;
public String toStringLower() {
return this.toString().toLowerCase();
......
......@@ -244,6 +244,7 @@ cardTextData.type.LASTNAME = Lastname
cardTextData.type.STATIC = Static
cardTextData.type.AGE = Age
cardTextData.type.ROLE = Role
cardTextData.type.AUTHCODE = MoyaAuth code
cart.item = Item
......@@ -796,6 +797,9 @@ print = Print
printedCard.template = Template
printedCard.cardState = Card state
printedCard.cardState.PENDING_VALIDATION = Pending validation
printedCard.cardState.VALIDATED = Validated
printedCard.cardState.REJECTED = Rejected
product.barcode = Barcode
product.billed = Billed
......
......@@ -226,6 +226,7 @@ cardTextData.y = Y koordinaatti
cardTextData.size = Tekstin koko (px)
cardTextData.zindex = Z index
cardTextData.fontname = Fontin nimi
cardTextData.fontcolor = Fontin vri
cardTextData.fontstyle = Fontin tyyli
cardTextData.fontstyle.PLAIN = Ei tyylittely
cardTextData.fontstyle.BOLD = Bold
......@@ -245,7 +246,8 @@ cardTextData.type.LASTNAME = Sukunimi
cardTextData.type.STATIC = Staattinen
cardTextData.type.AGE = Ik
cardTextData.type.ROLE = Rooli
cardTextData.fontcolor = Fontin vri
cardTextData.type.AUTHCODE = MoyaAuth koodi
cart.item = Tuote
cart.item_quantity = M\u00E4\u00E4r\u00E4
......@@ -779,6 +781,9 @@ print = Tulosta
printedCard.template = Kortin template
printedCard.cardState = Kortin tila
printedCard.cardState.PENDING_VALIDATION = Odottaa hyvksynt
printedCard.cardState.VALIDATED = Hyvksytty
printedCard.cardState.REJECTED = Hyltty
product.barcode = Viivakoodi
product.billed = Laskutettu
......@@ -857,7 +862,7 @@ readerview.cards = Kortit ( tulostuslkm )
registerleaflet.title = Rekisteriseloste
rejectcard.mailSubject = {0} -tapahtuman profiilin kuva hyltty
rejectcard.mailBody = {0} -tapahtuman profiiliisi sy\u00F6tetty kuva on hyl\u00E4tty soveltumattomana. Sy\u00F6t\u00E4 uusi kuva v\u00E4litt\u00F6m\u00E4sti. Kuvan saat asetettua profiili-sivulta. Hyv\u00E4ksytt\u00E4v\u00E4ss\u00E4 kuvassa kasvosi n\u00E4kyvt selke\u00E4sti ja tunnistettavasti. \n\n
rejectcard.mailBody = {0} -tapahtuman profiiliisi sytetty kuva on hyltty soveltumattomana. Syt uusi kuva vlittmsti. Kuvan saat asetettua profiili-sivulta. Hyvksyttvss kuvassa kasvosi tulee nky selkesti ja kokonaan. Tarkista uuden kuvan lhettmisen jlkeen, ett se on rajautunut oikein ja on oikeassa asennossa.
rejectcard.toAddr = Shkpostiosoite
rejectcard.toName = Nimi
rejectcard.body = Viestin sislt
......
......@@ -3,7 +3,9 @@ package fi.codecrew.moya.rest;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
......@@ -12,6 +14,7 @@ import javax.ws.rs.core.MediaType;
import fi.codecrew.moya.beans.CardTemplateBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.rest.pojo.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.PrintedCardRestPojo;
import fi.codecrew.moya.rest.pojo.SimpleEventuserRoot;
import fi.codecrew.moya.util.UserSearchQuery;
......@@ -45,4 +48,15 @@ public class UserRestView {
return new PrintedCardRestPojo(cardbean.checkPrintedCard(user));
}
@GET
@Path("/eventuser/{cardauthcode}")
public EventUserRestPojo getEventUser(@PathParam("cardauthcode") String code) {
EventUser user = userbean.getUser(code);
if(user != null)
return new EventUserRestPojo(user);
else
return new EventUserRestPojo();
}
}
......@@ -18,36 +18,54 @@ public class EventUserRestPojo {
@XmlElement(name = "nick")
public String getUsername()
{
if(user == null)
return "";
else
return user.getUser().getNick();
}
@XmlElement(name = "login")
public String getLogin()
{
if(user == null)
return "";
else
return user.getUser().getLogin();
}
@XmlElement(name = "eventuserId")
public Integer getEventuserId()
{
if(user == null)
return 0;
else
return user.getId();
}
@XmlElement(name = "userId")
public Integer getuserId()
{
if(user == null)
return 0;
else
return user.getUser().getId();
}
@XmlElement(name = "firstname")
public String getFirstname()
{
if(user == null)
return "";
else
return user.getUser().getFirstnames();
}
@XmlElement(name = "lastname")
public String getLastname()
{
if(user == null)
return "";
else
return user.getUser().getLastname();
}
......
......@@ -71,16 +71,21 @@ public class CardTemplateDataEditView extends GenericCDIView {
logger.info("CardTextData {}", cardTextData);
}
if(templateId != 0) {
setCardTemplate(cfbean.find(templateId));
logger.info("CardTemplate {}", cardTemplate);
if(cardTextData != null)
cardTextData.setCardTemplate(cardTemplate);
else if(cardObjectData != null)
cardObjectData.setCardTemplate(cardTemplate);
} else if(cardTextData != null) {
setCardTemplate(cardTextData.getCardTemplate());
} else if(cardObjectData != null) {
setCardTemplate(cardObjectData.getCardTemplate());
}
super.beginConversation();
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!