@Test public void shouldHandleEmptyStrings() { Token token = new Token("id", TokenType.OAUTH); token.setAttribute(CoreTokenField.STRING_ONE, ""); TokenAttributeConversion conversion = generateTokenAttributeConversion(); Entry result = conversion.getEntry(token); Attribute attribute = result.getAttribute(CoreTokenField.STRING_ONE.toString()); String string = attribute.firstValue().toString(); assertFalse(string.isEmpty()); }
public Entry getEntry(Token token) { Entry entry = new LinkedHashMapEntry(generateTokenDN(token)); addObjectClass(entry); for (CoreTokenField field : token.getAttributeNames()) { String key = field.toString(); if (CoreTokenField.TOKEN_TYPE.equals(field)) { TokenType type = token.getValue(field); entry.addAttribute(key, type.name()); continue; } if (CoreTokenFieldTypes.isCalendar(field)) { Calendar calendar = token.getValue(field); String dateString = conversion.toLDAPDate(calendar); entry.addAttribute(key, dateString); } else if (CoreTokenFieldTypes.isByteArray(field)) { byte[] array = token.getValue(field); entry.addAttribute(key, ByteString.valueOf(array)); } else if (CoreTokenFieldTypes.isInteger(field)) { Integer value = token.getValue(field); entry.addAttribute(key, ByteString.valueOf(value)); } else if (CoreTokenFieldTypes.isString(field)) { String value = token.getValue(field); if (value.isEmpty()) { value = EMPTY; } entry.addAttribute(key, ByteString.valueOf(value)); } else { throw new IllegalStateException(); } } return entry; }
TokenAttributeConversion { public Entry getEntry(Token token) { Entry entry = new LinkedHashMapEntry(generateTokenDN(token)); addObjectClass(entry); for (CoreTokenField field : token.getAttributeNames()) { String key = field.toString(); if (CoreTokenField.TOKEN_TYPE.equals(field)) { TokenType type = token.getValue(field); entry.addAttribute(key, type.name()); continue; } if (CoreTokenFieldTypes.isCalendar(field)) { Calendar calendar = token.getValue(field); String dateString = conversion.toLDAPDate(calendar); entry.addAttribute(key, dateString); } else if (CoreTokenFieldTypes.isByteArray(field)) { byte[] array = token.getValue(field); entry.addAttribute(key, ByteString.valueOf(array)); } else if (CoreTokenFieldTypes.isInteger(field)) { Integer value = token.getValue(field); entry.addAttribute(key, ByteString.valueOf(value)); } else if (CoreTokenFieldTypes.isString(field)) { String value = token.getValue(field); if (value.isEmpty()) { value = EMPTY; } entry.addAttribute(key, ByteString.valueOf(value)); } else { throw new IllegalStateException(); } } return entry; } }
TokenAttributeConversion { public Entry getEntry(Token token) { Entry entry = new LinkedHashMapEntry(generateTokenDN(token)); addObjectClass(entry); for (CoreTokenField field : token.getAttributeNames()) { String key = field.toString(); if (CoreTokenField.TOKEN_TYPE.equals(field)) { TokenType type = token.getValue(field); entry.addAttribute(key, type.name()); continue; } if (CoreTokenFieldTypes.isCalendar(field)) { Calendar calendar = token.getValue(field); String dateString = conversion.toLDAPDate(calendar); entry.addAttribute(key, dateString); } else if (CoreTokenFieldTypes.isByteArray(field)) { byte[] array = token.getValue(field); entry.addAttribute(key, ByteString.valueOf(array)); } else if (CoreTokenFieldTypes.isInteger(field)) { Integer value = token.getValue(field); entry.addAttribute(key, ByteString.valueOf(value)); } else if (CoreTokenFieldTypes.isString(field)) { String value = token.getValue(field); if (value.isEmpty()) { value = EMPTY; } entry.addAttribute(key, ByteString.valueOf(value)); } else { throw new IllegalStateException(); } } return entry; } @Inject  TokenAttributeConversion(LDAPConfig constants, LDAPDataConversion conversion); }
TokenAttributeConversion { public Entry getEntry(Token token) { Entry entry = new LinkedHashMapEntry(generateTokenDN(token)); addObjectClass(entry); for (CoreTokenField field : token.getAttributeNames()) { String key = field.toString(); if (CoreTokenField.TOKEN_TYPE.equals(field)) { TokenType type = token.getValue(field); entry.addAttribute(key, type.name()); continue; } if (CoreTokenFieldTypes.isCalendar(field)) { Calendar calendar = token.getValue(field); String dateString = conversion.toLDAPDate(calendar); entry.addAttribute(key, dateString); } else if (CoreTokenFieldTypes.isByteArray(field)) { byte[] array = token.getValue(field); entry.addAttribute(key, ByteString.valueOf(array)); } else if (CoreTokenFieldTypes.isInteger(field)) { Integer value = token.getValue(field); entry.addAttribute(key, ByteString.valueOf(value)); } else if (CoreTokenFieldTypes.isString(field)) { String value = token.getValue(field); if (value.isEmpty()) { value = EMPTY; } entry.addAttribute(key, ByteString.valueOf(value)); } else { throw new IllegalStateException(); } } return entry; } @Inject  TokenAttributeConversion(LDAPConfig constants, LDAPDataConversion conversion); Entry getEntry(Token token); Map<CoreTokenField, Object> mapFromEntry(Entry entry); Token tokenFromEntry(Entry entry); static Entry addObjectClass(Entry entry); static Entry stripObjectClass(Entry entry); DN generateTokenDN(Token token); DN generateTokenDN(String tokenId); }
TokenAttributeConversion { public Entry getEntry(Token token) { Entry entry = new LinkedHashMapEntry(generateTokenDN(token)); addObjectClass(entry); for (CoreTokenField field : token.getAttributeNames()) { String key = field.toString(); if (CoreTokenField.TOKEN_TYPE.equals(field)) { TokenType type = token.getValue(field); entry.addAttribute(key, type.name()); continue; } if (CoreTokenFieldTypes.isCalendar(field)) { Calendar calendar = token.getValue(field); String dateString = conversion.toLDAPDate(calendar); entry.addAttribute(key, dateString); } else if (CoreTokenFieldTypes.isByteArray(field)) { byte[] array = token.getValue(field); entry.addAttribute(key, ByteString.valueOf(array)); } else if (CoreTokenFieldTypes.isInteger(field)) { Integer value = token.getValue(field); entry.addAttribute(key, ByteString.valueOf(value)); } else if (CoreTokenFieldTypes.isString(field)) { String value = token.getValue(field); if (value.isEmpty()) { value = EMPTY; } entry.addAttribute(key, ByteString.valueOf(value)); } else { throw new IllegalStateException(); } } return entry; } @Inject  TokenAttributeConversion(LDAPConfig constants, LDAPDataConversion conversion); Entry getEntry(Token token); Map<CoreTokenField, Object> mapFromEntry(Entry entry); Token tokenFromEntry(Entry entry); static Entry addObjectClass(Entry entry); static Entry stripObjectClass(Entry entry); DN generateTokenDN(Token token); DN generateTokenDN(String tokenId);  }