/** * @param s * @return */ public static byte[] ascii( String s ) { if ( s == null ) { return new byte[0]; } return bytes( s, ASCII_ENCODING ); }
/** * @param uuid * @return */ public static byte[] uuidToBytesNullOk( UUID uuid ) { if ( uuid != null ) { return bytes( uuid ); } return new byte[16]; }
/** * @param s * @return */ public static byte[] bytes( String s ) { return bytes( s, UTF8_ENCODING ); }
public static ByteBuffer bytebuffer( UUID uuid ) { if ( uuid == null ) { return null; } return ByteBuffer.wrap( bytes( uuid ) ); }
public static String toBase64( UUID id ) { if ( id == null ) { return null; } return encodeBase64URLSafeString( bytes( id ) ); }
public static String base64( String str ) { return Base64.encodeBase64URLSafeString( bytes( str ) ); } }
public static ByteBuffer bytebuffer( String s, String encoding ) { return ByteBuffer.wrap( bytes( s, encoding ) ); }
public static ByteBuffer bytebuffer( String s ) { return ByteBuffer.wrap( bytes( s ) ); }
public static ByteBuffer bytebuffer( Boolean b ) { return ByteBuffer.wrap( bytes( b ) ); }
public static ByteBuffer bytebuffer( Object obj ) { if ( obj instanceof ByteBuffer ) { return ( ( ByteBuffer ) obj ).duplicate(); } return ByteBuffer.wrap( bytes( obj ) ); }
@JsonIgnore public byte[] getCorrelationIDAsBytes() { return bytes( properties.get( MESSAGE_CORRELATION_ID ) ); }
/** * @param obj * @return */ public static byte[] bytes( Object obj ) { if ( obj == null ) { return new byte[0]; } else if ( obj instanceof byte[] ) { return ( byte[] ) obj; } else if ( obj instanceof Long ) { return bytes( ( Long ) obj ); } else if ( obj instanceof String ) { return bytes( ( String ) obj ); } else if ( obj instanceof UUID ) { return bytes( ( UUID ) obj ); } else if ( obj instanceof Boolean ) { return bytes( ( Boolean ) obj ); } else if ( obj instanceof Date ) { return bytes( ( ( Date ) obj ).getTime() ); } else { return bytes( obj.toString() ); } }
private ByteBuffer principalKey( AuthPrincipalInfo principalInfo ) { // 66 bytes, 2 UUIDS + 2 chars for prefix ByteBuffer buff = ByteBuffer.allocate( 32 * 2 + 2 ); buff.put( bytes( principalInfo.getApplicationId() ) ); buff.put( bytes( principalInfo.getUuid() ) ); buff.put( bytes( principalInfo.getType().getPrefix() ) ); buff.rewind(); return buff; }
public static String base64( UUID uuid ) { return base64.encodeToString( bytes( uuid ) ); }
/** * Build a string path for this lock. Since it's specifically for updating a property, the property needs appended * to the path. If the property is null, it's getting deleted, so a lock on it isn't neccessary. In that case, a * no op lock is returned */ public static Lock getUniqueUpdateLock( LockManager manager, UUID applicationId, Object value, String... path ) throws UGLockException { //we have no value, therefore there's nothing to lock if ( value == null ) { return NO_OP_LOCK; } return manager.createLock( applicationId, buildPath( Hex.encodeHexString( bytes( value ) ), path ) ); } }
/** Returns a UUID that is -1 of the passed uuid, sorted by time uuid only */ public static UUID decrement( UUID uuid ) { if ( !isTimeBased( uuid ) ) { throw new IllegalArgumentException( "The uuid must be a time type" ); } //timestamp is in the 60 bit timestamp long timestamp = uuid.timestamp(); timestamp--; if ( timestamp < 0 ) { throw new IllegalArgumentException( "You must specify a time uuid with a timestamp > 0" ); } //get our bytes, then set the smaller timestamp into it byte[] uuidBytes = bytes( uuid ); setTime( uuidBytes, timestamp ); return uuid( uuidBytes ); }
private String getTokenForUUID( TokenInfo tokenInfo, TokenCategory tokenCategory, UUID uuid ) { int l = 36; if ( tokenCategory.getExpires() ) { l += 8; } ByteBuffer bytes = ByteBuffer.allocate( l ); bytes.put( bytes( uuid ) ); long expires = Long.MAX_VALUE; if ( tokenCategory.getExpires() ) { expires = ( tokenInfo.getDuration() > 0 ) ? UUIDUtils.getTimestampInMillis( uuid ) + ( tokenInfo.getDuration() ) : UUIDUtils.getTimestampInMillis( uuid ) + getExpirationForTokenType( tokenCategory ); bytes.putLong( expires ); } bytes.put( sha( tokenCategory.getPrefix() + uuid + tokenSecretSalt + expires ) ); return tokenCategory.getBase64Prefix() + encodeBase64URLSafeString( bytes.array() ); }
cursor = encodeBase64URLSafeString( bytes( nextResult ) );
protected UserInfo createAdminUserInternal( UUID organizationId, String username, String name, String email, String password, boolean activated, boolean disabled, Map<String, Object> userProperties ) throws Exception { logger.debug( "createAdminUserInternal - username: {}, email: {}, name: {}", username, email, name ); if ( isBlank( password ) ) { password = encodeBase64URLSafeString( bytes( UUID.randomUUID() ) ); } if ( username == null ) { username = email; } if ( name == null ) { name = email; } EntityManager em = emf.getEntityManager( smf.getManagementAppId() ); User user = new User(); user.setUsername( username ); user.setName( name ); user.setEmail( email ); user.setActivated( activated ); user.setConfirmed( !newAdminUsersRequireConfirmation() ); // only user.setDisabled( disabled ); if ( userProperties != null ) { // double check no 'password' property just to be safe userProperties.remove( "password" ); user.setProperties( userProperties ); } user = em.create( user ); return createAdminFrom( organizationId, user, password ); }
@Test public void testBytes() { byte[] bytes = ConversionUtils.bytes( true ); assertNotNull( "bytes() on boolean true returned null", bytes ); assertTrue( "bytes() on boolean true returned wrong size byte array:" + bytes.length, bytes.length == 1 ); assertTrue( "bytes() on boolean true returned wrong value:" + bytes[0], bytes[0] == 1 ); bytes = ConversionUtils.bytes( false ); assertNotNull( "bytes() on boolean false returned null", bytes ); assertTrue( "bytes() on boolean false returned wrong size byte array:" + bytes.length, bytes.length == 1 ); assertTrue( "bytes() on boolean false returned wrong value:" + bytes[0], bytes[0] == 0 ); bytes = ConversionUtils.bytes( new UUID( 0, 0 ) ); assertNotNull( "bytes() on uuid(0, 0) returned null", bytes ); assertTrue( "bytes() on uuid(0, 0) returned wrong size byte array:" + bytes.length, bytes.length == 16 ); for ( byte b : bytes ) { assertTrue( "bytes() on uuid(0, 0) returned wrong value:" + b, b == 0 ); } } }